#WSQ16<\/a> #TC1017<\/a> #CARS<\/a><\/p>\n Link to github: https:\/ This program needs to read a file which has a data base with various information relevant to cars. By reading the information, the program needs to print out the follow data:<\/p>\n The program opens the file and then uses a string variable in order to read stuff from the subline (substring aka substr).<\/p>\n Also, the program has a if inside a loop, which permits the file to be read several times until getting the average midrange price of a vehicle. <\/p>\n Here is how the code should look:<\/p>\n #include<\/a> <iostream><\/p>\n #include<\/a> <fstream><\/p>\n #include<\/a> <sstream><\/p>\n #include<\/a> <cstdlib><\/p>\n #include<\/a> <string><\/p>\n <\/p>\n using namespace std;<\/p>\n int cars(string carstext){<\/p>\n string range, city, highway;<\/p>\n int counter=0;<\/p>\n float range2=0.0, city2=0.0, highway2=0.0, sumcity=0.0, sumrange=0.0, sumhigh=0.0;<\/p>\n ifstream cars;<\/p>\n string line;<\/p>\n cars.open(carstext.c_str());<\/p>\n while(getline(cars, line)){<\/p>\n if((counter%2)==0){<\/p>\n range=line.substr(42, 47);<\/p>\n range2=atoi(range.c_str());<\/p>\n <\/p>\n city=line.substr(53, 54);<\/p>\n city2=atoi(city.c_str());<\/p>\n <\/p>\n highway=line.substr(56, 57);<\/p>\n highway2=atoi(highway.c_str());<\/p>\n <\/p>\n sumrange=sumrange + range2;<\/p>\n sumcity=sumcity + city2;<\/p>\n sumhigh=sumhigh + highway2;<\/p>\n <\/p>\n counter++;<\/p>\n }<\/p>\n }<\/p>\n cout<<“city mileage: “<<sumcity\/93<<endl;<\/p>\n cout<<“highway mileage: “<<sumhigh\/93<<endl;<\/p>\n cout<<“midrange vehicle price: “<<sumrange\/93<<endl;<\/p>\n }<\/p>\n int main(){<\/p>\n cout<<cars(“93cars.txt”);<\/p>\n <\/p>\n }<\/p>\n <\/p>\n <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":" #WSQ16 #TC1017 #CARSLink to github: https:\/\/github.com\/carlosgreen\/TC1017\/blob\/master\/cars.cppThis program needs to read a file which has a data base with various information relevant to cars. By reading the information, the program needs… Continue reading \n