0% found this document useful (0 votes)
3 views1 page

Example 7.7 CPP

The document contains a C++ program that defines a structure for a widget part with attributes for model number, part number, and cost. It prompts the user to input values for four widget parts and then displays the entered information. The program uses an array of structures to manage the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Example 7.7 CPP

The document contains a C++ program that defines a structure for a widget part with attributes for model number, part number, and cost. It prompts the user to input values for four widget parts and then displays the entered information. The program uses an array of structures to manage the data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <iostream>

using namespace std;


const int SIZE =4; //number of parts in array
////////////////////////////////////////////////////////////////
struct part //specify a structure
{
int modelnumber; //ID number of widget
int partnumber; //ID number of widget part
float cost; //cost of part
};
////////////////////////////////////////////////////////////////
int main()
{
int n;
part apart[SIZE]; //define array of structures
for(n=0; n<SIZE; n++) //get values for all members
{
cout << endl;
cout << "Enter model number: ";
cin >> apart[n].modelnumber; //get model number
cout << "Enter part number: ";
cin >> apart[n].partnumber; //get part number
cout << "Enter cost: ";
cin >> apart[n].cost; //get cost
}
cout << endl;
for(n=0; n<SIZE; n++) //show values for all members
{
cout << "Model " << apart[n].modelnumber;
cout << " Part " << apart[n].partnumber;
cout << " Cost " << apart[n].cost << endl;
}
return 0;
}

You might also like