In: Computer Science
Write a C++ program that prints the insurance fee to pay for a pet according to the following rules:(NOTE:You must use a switch statement to determine pet fee.)A dog that has been neutered costs $50.A dog that has not been neutered costs $80.A cat that has been spayedcosts $40.A cat that has not been spayedcosts $60.A bird or reptile costs nothing.Any other animal generates an error message.The program should prompt the user for the appropriate information: a character code for the pet type, and a yes/no response for the neutered status. Use a code letter to determine the kind of animal (i.e. D or d represents a dog, C or c represents a cat, B or b represents a bird, R or r represents a reptile, and anything else represents some other kind of animal). Use a code letter to determine the neutered/spayedstatus(i.e. Y or y represents yes, N or n represents no). The user should be allowed to enter the input in either upper or lower case.It prints out the type of animal (full name of animal) and the insurance fee. Any error in input data should generate an error message “Invalid data –no fee calculated”.
C++ CODE:-
#include
using namespace std;
void Cal_fee_dog(char status)
{
int p=50;
int q=80;
cout<<"The type of animal is: DOG\n";
if(status=='y' || status=='Y')
{
cout<<"The Insurance Fee to
pay is:$"<< p ;
cout<<"\n";
}
else if(status=='n'||status=='N')
{
cout<<"The Insurance Fee to
pay is:$"<< q ;
cout<<"\n";
}
}
void Cal_fee_cat(char status)
{
int p=40;
int q=60;
cout<<"The type of animal is: CAT\n";
if(status=='y' || status=='Y')
{
cout<<"The Insurance Fee to
pay is:$"<< p ;
cout<<"\n";
}
else if(status=='n'||status=='N')
{
cout<<"The Insurance Fee to
pay is:$"<< q ;
cout<<"\n";
}
}
void Identify_bird()
{
cout<<"The type of animal is: BIRD\n";
cout<<"No Insurance Fee\n";
}
void Identify_reptile()
{
cout<<"The type of animal is: REPTILE\n";
cout<<"No Insurance Fee\n";
}
void Identify_animal()
{
cout<<"Invalid data-no fee calculated";
cout<<"\n";
}
int main()
{
char ch,status;
cout<<"Enter the character code for pet
type:\n";
cin>> ch;
cout<<"Enter the response for neutered
status:\n";
cin>> status;
/* cout<<"You entered:-"<
cout<<"You entered:-"<
switch(ch)
{
case 'd':
Cal_fee_dog(status);
break;
case 'D':
Cal_fee_dog(status);
break;
case 'c':
Cal_fee_cat(status);
break;
case 'C':
Cal_fee_cat(status);
break;
case 'b':
Identify_bird();
break;
case 'B':
Identify_bird();
break;
case 'r':
Identify_reptile();
break;
case 'R':
Identify_reptile();
break;
default:
Identify_animal();
}
return 0;
}
SCREENSHOT of OUTPUT:-