Uses parts inventory to demonstrate structures - C++ Data Type

C++ examples for Data Type:struct

Description

Uses parts inventory to demonstrate structures

Demo Code

#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 ww  .ja  v a  2  s  .  c  o  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;
}

Result


Related Tutorials