Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program which performs the following: Ask user to enter from keyboar

ID: 3798239 • Letter: W

Question

Write a C++ program which performs the following: Ask user to enter from keyboard the sales info about 3 cars: Example: CRV-3 150000.00 20.0 MRV-1 180000.00 20.0 CIVIC 82000.00 10.0 The fields in the above columns are: Vehicle Name: string Vehicle Price: float/double Profit Rate (%) = float/double Displays the results for each car with the following info: Vehicle Name: string Total Price: float/double Note: The total price of each car is calculated as follows: Total Price = (Vehicle Price) + (Vehicle Price * Profit/100) Homework: Redo the above exercise to read the car sales info (a) from a file "car.txt". Then output the results (b) to a file "showroom.txt".

Explanation / Answer

vehicle.cpp :

#include<iostream.h>

#include<fstream.h>

#include<conio.h>

struct vehicle{

char VehicleName[20];

double VehiclePrice;

double ProfitRate;

double TotalPrice;

};

int main(){

clrscr();

char data[100];

vehicle v[3];

ifstream infile;

infile.open("car.txt");

ofstream outfile;

outfile.open("showroom.txt");

for(int i=0;i<3;i++){

infile>>v[i].VehicleName;

infile>>v[i].VehiclePrice;

infile>>v[i].ProfitRate;

v[i].TotalPrice = (v[i].VehiclePrice) + (v[i].VehiclePrice * v[i].ProfitRate/100);

outfile<<v[i].VehicleName<<" "<<v[i].TotalPrice<<endl;

/*cout<<v[i].VehicleName<<" "<<v[i].VehiclePrice<<" "<<v[i].ProfitRate<<" "<<v[i].TotalPrice<<endl;*/

}

infile.close();

outfile.close();

getch();

return 0;

}

car.txt :

CRV-3 150000.00 20.0

MRV-1 180000.00 20.0

CIVIC 82000.00 10.0

showroom.txt :

CRV-3 180000

MRV-1 216000

CIVIC 90200

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote