In: Computer Science
C++ programming: FUNCTIONS WITH DIFFERENT RETURN TYPES AND PARAMETERS
NuMetro has a special on movies for all members of the public but special discounts for students and pensioners. If pensioners or students buy a movie ticket they receive 10% if they buy a movie and popcorns, they receive 20% discount. Other customers only receive a discount when they buy a movie ticket and popcorn; there is no discount for just a movie ticket alone. Write a program named question5b.cpp that will consist of two functions. The program must prompt the user for type of customer (‘p’ for pensioner, ‘s’ for student, ‘o’ for other). It must then call the relevant function according to that entry. The first function must receive the customer type and calculates discount for pensioners and students. The second function calculates the discount for customers that are not pensioners or students.
cpp code:
#include <iostream>
using namespace std;
//function 1 for pensioner and student
int discountType1(char popCorn)
{
//if popcorn, discount 20
if(popCorn=='y')
return 20;
else
return 10; //else 10
}
//function 2 for others
int discountType2(char popCorn)
{
//if popcorn, discount 20
if(popCorn=='y')
return 20;
else
return 0; //else 0
}
int main()
{
char type,c;
//prompt for user type
cout << "Enter the of customer ('p' for pensioner, 's' for
student, 'o' for other): ";
cin>>type;
//popcorn
cout<<"\nWant pop corn ('y' /'n'): ";
cin>>c;
//call the function
if(type=='p' || type=='s')
cout<<"\nYou got discount of
"<<discountType1(c)<<" %\n";
else
cout<<"\nYou got discount of
"<<discountType2(c)<<" %\n";
return 0;
}
output:
//for any clarification , please do comments, if you found this solution useful,please give me thumbs up