In: Computer Science
C++ Programm
Automobile Insurance Program:
Writes a program that prints the insurance fee to pay for a Vehicle according to the following rules:
A Honda that is All Wheel Drive costs $450.
A Honda that is two wheels drive costs $350.
A Toyota that is All Wheel Drive costs $300.
A Toyota that is Two Wheel Drive costs $250.
A Nissan that is All Wheel Drive costs $200.
A Nissan that is Two Wheel Drive costs $280
Any other type of vehicle generates an error message. The program should prompt the user for the appropriate information, using a code to determine the kind of Vehicle (i.e. H or h represents a Honda, T or t represents a Toyota, N or n represents Nissan. And y or n for the AWD).
After printing the insurance fee, the program should ask the user if (s) he wants to ensure another Vehicle using repetition structure.
Solution Source Code C++:
C++ Code:
#include
#include
using namespace std;
int main() {
char ch,ch1,ch2;
int cost;
cout<<"Enter Vehicle type:\n(H/h) for Honda\n(T/t) represents Toyota\n(N/n) for Nissan:\n ";
cin>>ch;
switch(ch){
case 'H':
case 'h':
cout<<"Is it AWD :(Y/N)";
cin>>ch1;
if(ch1=='Y'||ch1=='y')
cost=450;
else
cost=350;
break;
case 'T':
case 't':
cout<<"Is it AWD :(Y/N)";
cin>>ch1;
if(ch1=='Y'||ch1=='y')
cost=300;
else
cost=250;
break;
case 'N':
case 'n':
cout<<"Is it AWD :(Y/N)";
cin>>ch1;
if(ch1=='Y'||ch1=='y')
cost=200;
else
cost=280;
break;
default:
cout<<"Wrong choice";
}
cout<<"The insurance cost is
$"< cout<<"Do you wish to check for another vehicle(Y/N):
"; cin>>ch2; if(ch2=='Y'||ch2=='y') main(); else exit(0); }