Assume you're writing this menu-driven program for a shipping company. There are two types of shipments: normal and expedited. a. As shown in Program 4-18, please declare constants for the types of shipments. Please write the names of constants in ALL CAPS. b. Show the menu in a clear form, and prompt the user for the type of shipment; the rest of the program depends on the type of shipment chosen. c. 1. For normal shipments, ask for the weight of the package (double) and the distance (int). Then use the table on the right: Rate per 100 miles 2.03 Weight 1 Ib. or less more than 1 lb., less than 4 Ib. at least 4 Ib., less than 10 Ib. 10 lb. or more The smallest distance offered is 15 miles, and the greatest is 900 miles 3.95 6.57 8.26 2. For expedited shipments, ask for the weight of the package (double) and the distance (int). Then use the table on the right: Weight 1 lb. or less more than 1 lb., less than 4 Ib. at least 4 Ib., less than 10 Ib. 10 lb. or more Rate per 100 miles 3.10 The smallest distance offered is 10 miles, and the greatest is 500 miles 4.28 7.13 9.75 3. Please verify the user input each time the user enters a value. If the input is incorrect, set a flag to indicate that condition. You'll need the flag when you display output. d. Output. Here are some scenarios. Ex1: The shipment type is normal, the weight is 6.3 pounds, and the distance is 700 miles. The output should look like: Shipment type : Normal : 6.300 : 700 : $45.99 Weight Distance Cost Ex2: The shipment type is expedited, the weight is 3.42 pounds, and the distance is 475 miles. The output should look like: Shipment type : Expedited : 3.420 : 475 : $20.33 Weight Distance Cost Ex3: The input is invalid for at least one of the prompts. The only output should be: There was invalid input. Please try again.
Addition of Two Numbers
Adding two numbers in programming is essentially the same as adding two numbers in general arithmetic. A significant difference is that in programming, you need to pay attention to the data type of the variable that will hold the sum of two numbers.
C++
C++ is a general-purpose hybrid language, which supports both OOPs and procedural language designed and developed by Bjarne Stroustrup. It began in 1979 as “C with Classes” at Bell Labs and first appeared in the year 1985 as C++. It is the superset of C programming language, because it uses most of the C code syntax. Due to its hybrid functionality, it used to develop embedded systems, operating systems, web browser, GUI and video games.
Please, I need to answer this question using the C++
Program 4-18
// This program displays a menu and asks the user to make a
// selection. An if/else if statement determines which item
// the user has chosen.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int choice; // To hold a menu choice
int months; // To hold the number of months
double charges; // To hold the monthly charges
// Constants for membership rates
const double ADULT = 40.0,
SENIOR = 30.0,
CHILD = 20.0;
// Constants for menu choices
const int ADULT_CHOICE = 1,
CHILD_CHOICE = 2,
SENIOR_CHOICE = 3,
QUIT_CHOICE = 4;
// Display the menu and get a choice.
cout << "\t\tHealth Club Membership Menu\n\n"
<< "1. Standard Adult Membership\n"
<< "2. Child Membership\n"
<< "3. Senior Citizen Membership\n"
<< "4. Quit the Program\n\n"
<< "Enter your choice: ";
cin >> choice;
// Set the numeric output formatting.
cout << fixed << showpoint << setprecision(2);
// Respond to the user's menu selection.
if (choice == ADULT_CHOICE)
{
cout << "For how many months? ";
cin >> months;
charges = months * ADULT;
cout << "The total charges are $" << charges << endl;
}
else if (choice == CHILD_CHOICE)
{
cout << "For how many months? ";
cin >> months;
charges = months * CHILD;
cout << "The total charges are $" << charges << endl;
}
else if (choice == SENIOR_CHOICE)
{
cout << "For how many months? ";
cin >> months;
charges = months * SENIOR;
cout << "The total charges are $" << charges << endl;
}
else if (choice == QUIT_CHOICE)
{
cout << "Program ending.\n";
}
else
{
cout << "The valid choices are 1 through 4. Run the\n"
<< "program again and select one of those.\n";
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps