Answer to Question #19049 in C++ for mhamad

Question #19049
this program accept the following:
1. 5 type of car (a,b,c,d,f)
2.for each it accept the length of the car in centimeter
3.the length of the road in kilometer
4.the number of the lanes in the road
5.if the road is double-side or not

the program then calculates that how many of cars can fit on the road. the program assume 2 meters distance between each tow consecutive cars. the program also assume that there would be exactly 20% of each ace type on the road
1
Expert's answer
2012-11-20T08:10:46-0500
# include <iostream>

using namespace std;

int main(){
int car[5];
double road;
int num;
bool size;
char c;
for(int i=0;i<5;i++){
cout<<"Enter size of car "<<i<<endl;
cin>>car[i];}

cout<<"Enter km of road"<<endl;
cin>>road;
cout<<"Enter num of lanes "<<endl;
cin>>num;
cout<<"Road is double-sized? (y/n) "<<endl;
cin>>c;
if ((c=='y')||(c=='Y')) {size=1; num*=2;}
else size=0;

int am=static_cast <int> (num*road*1000/(((2+car[0])+(2+car[1])+(2+car[2])+(2+car[3])+(2+car[4]))));
& cout<<"MAX amount of each car is "<<am<<endl;

system("PAUSE");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS