Declare a single structure data type suitable for a car structure of the type il
ID: 3767738 • Letter: D
Question
Declare a single structure data type suitable for a car structure of the type illustrated below:
Car Number
Miles Driven
Gallons Used
25
1950
65
36
3260
130
44
1789
68
52
2367
110
68
2135
153
Write a program using the data type you declared to interactively accepts the above data into an array of five structures. Once the data have been entered, the program should create a report listing each car number and miles per gallon achieved by the car. At the end of the report include the average miles per gallon achieved by the complete fleet of cars. In C++, Please! comments welcomed
Car Number
Miles Driven
Gallons Used
25
1950
65
36
3260
130
44
1789
68
52
2367
110
68
2135
153
Explanation / Answer
//This program is tested by me.You can do record of 100 entries in this program.If you want to store more than 100 //entries ,just change the array size in the structure declaration part
//preprocessor directives
#include<iostream>
#include<conio.h>
using namespace std;
struct carDetails
{
int car_no[100];
int milesDriven[100];
int gallonsUsed[100];
};
int main()
{
// object c referencing to a structure carDetails
carDetails c;
int n,i;
//enter the total number of records
cout<<"Enter the total number of records to be entered ";
cin>>n;
//Input the values for the record
for(i=0;i<n;i++)
{
cout<<"Enter the car number";
cin>>c.car_no[i];
cout<<"enter the miles driven";
cin>>c.milesDriven[i];
cout<<"enter the gallons used";
cin>>c.gallonsUsed[i];
}
//output the record values in the screen
cout<<"carNumber"<<" "<<"milesDriven"<<" "<<"gallonsUsed"<<endl;
for(i=0;i<n;i++)
{
cout<<c.car_no[i]<<" "<<" ";
cout<<c.milesDriven[i]<<" "<<" ";
cout<<c.gallonsUsed[i]<<" "<<" ";
cout<<" ";
}
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.