In: Computer Science
CSCI 1470
Lab 5 Assignment #3
Topic: Selection
(switch statement))
Reading: Chapter 4
Point Value: 15 points
*Note: Include the following set of comments at the top of your source code for all assignments.
//Your Name
//Brief description of the purpose of the program (Example: Displays student information.)
Assignment: (Save this file as Lab5-3-YourLastName.cpp) A mobile phone service provider has three different subscription packages for its customers:
Package A: |
For $39.99 per month 450 minutes are provided. Additional minutes are $0.45 per minute. |
Package B: |
For $59.99 per month 900 minutes are provided. Additional minutes are $0.40 per minute. |
Package C: |
For $69.99 per month unlimited minutes provided. |
Write a program that calculates and displays a customer’s monthly bill. Prompt for the customer’s name, the month being billed, which package the customer purchased and how many minutes were used. Display the customer’s bill as shown below in the sample output.
Display a menu to allow the user to enter the desired subscription package. Use a switch statement to calculate the monthly charge based on the package chosen.
Sample Input/Output:
Please enter the customer's name: Sue Lee
Please enter the current billing month: July
How many minutes were used? 560
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 1
The Mobile Phone bill for July
Customer's Name: Sue Lee
Minutes Used: 560
Amount Due: $89.49
Another Sample Input/Output:
Please enter the customer's name: Lisa Miles
Please enter the current billing month: August
How many minutes were used? 700
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 7
The valid choices are 1 through 4. Run the
program again and select one of those.
Another Sample Input/Output:
Please enter the customer's name: John Jones
Please enter the current billing month: May
How many minutes were used? 800
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 3
The Mobile Phone bill for May
Customer's Name: John Jones
Minutes Used: 800
Amount Due: $69.99
Another Sample Input/Output:
Please enter the customer's name: Karen Hill
Please enter the current billing month: June
How many minutes were used? 500
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 4
Program ending.
Another Sample Input/Output:
Please enter the customer's name: Jill Mills
Please enter the current billing month: May
How many minutes were used? 350
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 1
The Mobile Phone bill for May
Customer's Name: Jill Mills
Minutes Used: 350
Amount Due: $39.99
Another Sample Input/Output:
Please enter the customer's name: Josh Hayes
Please enter the current billing month: March
How many minutes were used? 850
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 2
The Mobile Phone bill for March
Customer's Name: Josh Hayes
Minutes Used: 850
Amount Due: $59.99
Grading Criteria:
· If program does not run, then 0 points for lab grade.
· -1 point – if no name or description of code
· -1 point – if no named constants are used
· -2 points – for inaccurate output item (Amount Due)
· -1 point – for output items not displayed in sample report (Customer Name, Month, Minutes Used, Amount due)
· -2 points – If no input validation with error message for number of minutes
· -1 point – if money values are not displayed with 2 decimal position
· -2 points – If menu is not displayed for user
Please comment, if you need any corrections.Please give a Thumps
up if you like the answer.
Program
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const double PACK_A = 39.99; //constant to hold price
of pack A
const double PACK_B = 59.99; //constant to hold price
of pack B
const double PACK_C = 69.99; //constant to hold price
of pack C
int menu_choice;
float total;
int mins_used;
string cust_name,bill_month;
cout<<"Please enter the customer's name:
";
getline(cin, cust_name);
cout<<"Please enter the current billing month:
";
cin>>bill_month;
cout << "How many mins_used were used? ";
cin >> mins_used;
cout<<"Select a subscription
package:"<<endl<<"1. Package A"<<endl<<"2.
Package B"<<endl<<"3. Package C"<<endl<<"4.
Quit"<<endl;
cout << "Menu Option: ";
cin >> menu_choice;
if (menu_choice >= 1 && menu_choice <=
4)
{
switch(menu_choice){
case 1: //if user has chosen package A
total += PACK_A; //add A's price to total
if(mins_used>450)
total += (mins_used-450)*0.45; //add to total price of extra
mins_used if there are any
break; //break statement to prevent fall-through
case 2: //if user has chosen package B
total += PACK_B; //add B's price to total
if(mins_used>900)
total += (mins_used-900)*0.40; //add to total price of extra
mins_used if there are any
break; //break statement to prevent fall-through
case 3: //if user has chosen package C
total += PACK_C; //add C's price to total
break; //break statement to prevent fall-through
case 4:
cout<<"Program
ending."<<endl;
exit(0);
}
cout<<"The Mobile Phone bill for
"<<bill_month<<endl;
cout<<"Customer's Name:
"<<cust_name<<endl;
cout<<"Minutes Used:
"<<mins_used<<endl;
//set fixed precision for formatting
cout << setprecision(2) << fixed <<
showpoint;
//print total owed to company on screen
cout <<"Amount Due: $"<<total<<endl;
}
else{ //following block will execute if menu_choice>4
cout << "The valid choices are 1 through 4. Run the program
again and select one of those." << endl;
}
return 0;
}
Output
Please enter the customer's name: Josh Hayes
Please enter the current billing month: March
How many mins_used were used? 850
Select a subscription package:
1. Package A
2. Package B
3. Package C
4. Quit
Menu Option: 2
The Mobile Phone bill for March
Customer's Name: Josh Hayes
Minutes Used: 850
Amount Due: $59.99