The information that he needs includes the type, seating capacity, price, miles per gallon, and color of each car. Define a struct named lotCar that will contain all of these members.
The program will allow user to input includes the type, seating capacity, price, miles per gallon, and color of each car. The input must be validated before writing the record to file:
- Valid car types are c-coupe, m-minivan and s-SUV and q-quit.
- The miles per gallon and price depend on the type of vehicle the user selects.
- Coupe - 25 mpg with cost of $15,000, 5 seat passengers
- Minivan - 20 mpg with a cost of $18,000, 5 seat passengers
- SUV - 18 mpg with a cost of 22,000, 7 seat passengers
Validate the type of car using Boolean function which will loop until a valid character has been entered. Return false when user enter 'q' and return true when user enter a valid car type. Another Boolean function to input the seating capacity the user selects. Allow users to continue working with the program but make a different choice if the seating capacity does not match the car they select.
Sample screen display:
Enter type of car : Šoupe, (m)inivan, (s)UV or (q)uit: c
Enter the seating capacity: 5
Enter miles per gallon: 25
Enter your color choice: green
Output file lotCar should resemble like this:
Coupe 5 25 green
So please help me, I am stuck with this coding for the problem:
CODE
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//define structure
struct lotCar
{
char type;
int seat_capacity;
int miles;
string color;
};
//function to input lotcar record
lotCar GetData()
{
lotCar tempRec;
cout << "Enter type of car: Šoupe, (m)inivan, (s)UV or (q)uit: ";
cin >> tempRec.type;
cout << "Enter the seating capacity that you want :";
cin >> tempRec.seat_capacity;
cout << "Enter miles per gallon : ";
cin >> tempRec.miles;
cout << "Enter your color choice : ";
cin >> tempRec.color;
return tempRec;
}
//function to display lotcar record
void ShowData (lotCar temp)
{
char ans;
switch (temp.type)
{
case 'C': case 'c':
cout << "______________\n";
cout << "\n type of car : coupe";
cout << "\n seating capacity :5";
cout << "\n miles per gallon :25";
cout << "\n color :"<<temp.color;
cout << "\n price : $15,000";
cout << "\n_______________\n";
break;
case 'M': case 'm':
cout << "______________\n";
cout << "\n type of car : minivan";
cout << "\n seating capacity :5";
cout << "\n miles per gallon :20";
cout << "\n color :"<<temp.color;
cout << "\n price : $18,000";
cout << "\n_______________\n";
break;
case 'S': case 's': case '7':
cout << "______________\n";
cout << "\n type of car : SUV";
cout << "\n seating capacity :7";
cout << "\n miles per gallon :18";
cout << "\n color :"<<temp.color;
cout << "\n price : $22,000";
cout << "\n_______________\n";
default: //if character input do not match any cases above,do this:
cout<<"Wrong selection\n\n"; //display-wrong menu selection
}
{ cout<<"\n\n do you want to quit?";//ask user whether to continue
cin>>ans; //input menu choice again
}
if (ans=='y' || ans=='Y' );
cout <<"thanks\n";
else if
(ans=='n' || ans=='N' );
cout<< temp.type;
};
//main program
int main()
{
ofstream f_out("lotCar.txt",ios::app);
lotCar your_record;
your_record = GetData();
ShowData (your_record);
f_out<< "\t" << your_record.type<< "\t" <<your_record.seat_capacity<< "\t" <<your_record.miles<< "\t" <<your_record.color<<endl<<endl;
f_out.close();
return 0;
}
* so please help me thank you
*Mod Edit: added code tags: