C++ struct variable

Description

C++ struct variable

#include <iostream>
using namespace std;
struct Product                   //declare a structure
{
   int modelnumber;           //ID number of widget
   int partnumber;            //ID number of widget part
   float cost;                //cost of part
};
int main()//from  w w  w  . j ava  2 s . co m
{
   Product part1;                //define a structure variable
   part1.modelnumber = 6244;  //give values to structure members
   part1.partnumber = 373;
   part1.cost = 217.55F;

   cout << "Model "  << part1.modelnumber;
   cout << ", part "   << part1.partnumber;
   cout << ", costs $" << part1.cost << endl;
   return 0;
}



PreviousNext

Related