C++ Control STRuctures I & II SELECTION/Repetition STATEMENTS
Options available for Purchasing Cell Phone:
OPTION | CATEGORY |
1 | Samsung Galaxy S8 ($30/month) |
2 | Samsung Galaxy S8 Plus ($35/month) |
3 | LG G6 ($20/moth) |
4 | Apple iPhone 7 ($25.99/month) |
5 | Apple iPhone 7 Plus ($49.99/month) |
-1 | Continue to Phone Plan Selection |
Write a program for Mobile Plus Communications (MPC) Mobile Communications Company that asks customers to select from the list of smart phones in the table above. The Menu will be presented to customers upon entering the MPC.com website. For now, this program will only run on a desktop computer. After all the phones are selected, the customer must then select a Plan from the following Phone Plan Option List:
Phone Plans available after selecting phones from the menu above:
OPTION | SELECTION |
Plan A | 4 phone Lines or More – $50/Line per month, otherwise a flat fee of $300/month |
Plan B | Less than 4 Lines – $70/Line per month, otherwise $50/Line per month |
Plan C | Plan with Tablet Line (Any number of Lines) $60/Line per month |
If the customer enters any option that is not in the tables above, the program should display “Invalid Option Selected”. You must use the switch statement in your program to solve this problem.
The program should calculate the total cost of the purchase based on the user’s selections and then provide the following output summary.
Number of Phones Purchased for each type of phone
Plan Selected
Number of phone lines activated
Total Cost
The following is a sample output
********************************
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/moth)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit): 1
Enter the number of phones for this selection: 3
*********************************
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/moth)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit): 2
Enter the number of phones for this selection: 3
Expert Answer
#include <iostream>
using namespace std;
int main()
{
int lines = 0, s8 = 0, s8plus = 0, lg =0, iph7 =0, iph7plus =0;
double cost = 0;
char plan;
int choice, n;
bool repeat = true;
while(repeat)
{
cout<<“1. Samsung Galaxy S8 ($30/month)”<<endl;
cout<<“2. Samsung Galaxy S8 Plus ($35/month)”<<endl;
cout<<“3. LG G6 ($20/month)”<<endl;
cout<<“4. Apple iPhone 7 ($25.99/month)”<<endl;
cout<<“5. Apple iPhone 7 Plus ($49.99/month)”<<endl;
cout<<“9. Exit”<<endl;
cout<<“Enter your phone selection (1-5: 9 to exit):”;
cin >> choice;
if(choice != 9) //if not exit
{
cout << “Enter the number of phones for this selection: “;
cin >> n;
lines += n; //increase the line count
}
//depending on choice , add the cost for n phones and increase count of that phone type
switch(choice)
{
case 1:
s8+=n;
cost += n * 30;
break;
case 2:
s8plus+=n;
cost += n * 35;
break;
case 3:
lg+=n;
cost += n * 20;
break;
case 4:
iph7+=n;
cost += n * 25.99;
break;
case 5:
iph7plus+=n;
cost += n * 49.99;
break;
case 9:
repeat = false;
break;
default:
cout<<“Invalid option selected ! “<<endl;
}
cout<<endl;
}
while(true)
{
cout<<“Choose plan (A, B or C): “;
cin >> plan;
if(plan >=’A’ && plan<=’C’)
break;
else
cout<<“Invalid plan selected !”<<endl;
}
switch(plan)
{
case ‘A’:
if(lines >= 4)
cost += lines * 50; //50 per line if 4 or more lines
else
cost += 300; //flat 300
break;
case ‘B’:
if(lines < 4)
cost += lines * 70; //70/line if less than 4
else
cost += lines * 50;
break;
case ‘C’:
cost += lines * 60;
break;
}
cout<<“nNumber of Phones selected -“<<endl;
cout<<“1. Samsung Galaxy S8 = “<< s8 <<endl;
cout<<“2. Samsung Galaxy S8 Plus = “<< s8plus << endl;
cout<<“3. LG G6 = “<< lg << endl;
cout<<“4. Apple iPhone 7 = “<< iph7 <<endl;
cout<<“5. Apple iPhone 7 Plus = “<< iph7plus << endl<<endl;
cout<<“Plan selected: Plan “<<plan<<endl<<endl;
cout<<“Number of phone lines activated: ” << lines <<endl;
cout<<“Total cost: $”<<cost<<endl<<endl;
}
output
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):1
Enter the number of phones for this selection: 3
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):2
Enter the number of phones for this selection: 3
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):3
Enter the number of phones for this selection: 1
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):4
Enter the number of phones for this selection: 2
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):5
Enter the number of phones for this selection: 1
1. Samsung Galaxy S8 ($30/month)
2. Samsung Galaxy S8 Plus ($35/month)
3. LG G6 ($20/month)
4. Apple iPhone 7 ($25.99/month)
5. Apple iPhone 7 Plus ($49.99/month)
9. Exit
Enter your phone selection (1-5: 9 to exit):9
Choose plan (A, B or C): B
Number of Phones selected –
1. Samsung Galaxy S8 = 3
2. Samsung Galaxy S8 Plus = 3
3. LG G6 = 1
4. Apple iPhone 7 = 2
5. Apple iPhone 7 Plus = 1
Plan selected: Plan B
Number of phone lines activated: 10
Total cost: $816.97