ADVERTISEMENT

One of the works done by our Robotics and Machine Learning division,
SELF-LEVELING QUADCOPTER
Arduino based Quadcopter.
Self-leveling is acheived by the aligning the quadcopter using the readings from the gryo as well as the accelerometer.
A four channel RC transmitter is used to control the movement of the quadcopter when in flight. Kindly subscribe to our YouTube Channel and stay tuned.

Friday 29 April 2016

CSE1002:PP8:Car Mileage Calculation Problem

A workshop has a variety of cars. The details of the car such as car number, miles driven, and gallons of gas used in each car is stored in a file.
Car Number          Miles Driven         Gallons used
      54            250            19
      62            525            38
      71            123            6
      85            1,322            86
      97            235            14
Write a  C++ program that reads the data in the file created and displays the car number, miles driven, gallons used, and the miles per gallon for each car.

PSEUDOCODE:
START
READ s;
READ FILE with name s in f
while(!f.eof())
f>>car>>mile>>gal;
SET avg=mile/gal;
SET total+=mile;
SET totalg+=gal;
SET tavg+=avg;
PRINT car,mile,gal,avg
end while
PRINT total,totalg,tavg,tavg/n;
STOP
CODE:
#include<iostream>
#include<fstream>
#include<iomanip>
using namespace std;
main()
{int car,n=0;
char s[100];
cin>>s;
float mile,gal,total=0,totalg=0,avg,tavg=0;
fstream f;
f.open(s,ios::in);
while(!f.eof())
{
f>>car>>mile>>gal;
avg=mile/gal;
total+=mile;
totalg+=gal;
tavg+=avg;
cout<<fixed<<setprecision(2)<<car<<" "<<mile<<" "<<gal<<" "<<avg<<endl;
n++;
}
cout<<fixed<<setprecision(2)<<total<<endl<<totalg<<endl<<tavg<<endl<<tavg/n;
}

No comments:

Post a Comment