Widget part as an object - C++ Class

C++ examples for Class:object

Description

Widget part as an object

Demo Code

#include <iostream>
using namespace std;
class part/*from w w w .  ja v a2s .  c  o m*/
{
   private:
   int modelnumber;   //ID number of widget
   int partnumber;    //ID number of widget part
   float cost;        //cost of part
   public:
   void setpart(int mn, int pn, float c)  //set data
   {
      modelnumber = mn;
      partnumber = pn;
      cost = c;
   }
   void showpart()
   {
      cout << "Model "    << modelnumber;
      cout << ", part "   << partnumber;
      cout << ", costs $" << cost << endl;
   }
};
int main()
{
   part part1;                         //define object
   //   of class part
   part1.setpart(6244, 373, 217.55F);  //call member function
   part1.showpart();                   //call member function
   return 0;
}

Result


Related Tutorials