Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

vvvvvvvv Instructions: For this part of the project, you will add a menu to your

ID: 3702107 • Letter: V

Question

vvvvvvvv

Instructions:

For this part of the project, you will add a menu to your program in Part 2 and add functionality to create and display mailing labels by reading input from a text file. The menu should be the first thing that is displayed when your program is run. Allow the user to continue making choices until they choose the option to quit. Redisplay the menu before prompting the user for a menu option. See the Sample Output for how your menu should look.

Invalid menu choices should be validated.   If the user enters an invalid menu option, your program should give them an error message that explains what they did wrong and redisplay the menu with a prompt to enter a different option number. This process should continue until the user enters a valid option number. In addition, your program should validate the user’s input for type of item to be mailed. If the user enters any number other than 1, 2 or 3, your program should give them an error message that explains what they did wrong and prompt them to enter a different number. This process should continue until the user enters valid data.

The multiple mailings option of your menu should read a text file named Mailings.txt and display to the console all the information that was displayed in Project 2 for each mailing in the file. When the user selects the multiple mailings option, the mailing labels should be created and displayed for every mailing in the file without the user needing to do anything else. The Mailings.txt file contains 5 mailings, but your program must be able to process an identically formatted file with any number of mailings.

If a user selects the multiple mailings option, your program should calculate and display the total cost of all the postage in the text file. After displaying all the mailing labels, display the total amount of postage owed. Format the total cost of the postage in dollars and cents. See Sample Output.

Summary:

Add a menu to offer the user a choice of mailing a single item, mailing multiple items or quitting the program. The menu should be the first thing displayed when your program begins executing. The menu format should match the one in the Sample Output.

Allow the user to continue making menu choices until they choose the option to quit. Always display the menu before prompting the user for a menu option.

Properly handle an invalid menu choice.

Validate the user’s input for type of mailing.

Add functionality to create and display mailing labels by reading input from the Mailings.txt text file. Make sure your program can process an identically formatted file containing any number of mailings without counting the records.

Calculate and display the total cost of all the postage in the text file. Make sure your program will correctly calculate the total cost no matter how many mailings are in the text file.

Notes:

Save your .cpp file with the required filename.

Click the assignment link to upload your file.

Sample Output

Welcome to the Mailing Label Printing System

1 – Single Mailing

2 – Multiple Mailings

3 -- Quit

Enter your choice: 1                      

Enter name : Larry Smith

Enter street address: 122 Main Street

Enter city: Charlotte

Enter state: NC

Enter zip code: 23499

Enter 1 for letter, 2 for envelope, 3 for parcel: 1

Enter weight in ounces: 2.1

**************************$0.93

Larry Smith

122 Main Street

Charlotte     NC 23499

|::|:|::||::|::||:|::|:|::::||:|

1 – Single Mailing

2 – Multiple Mailings

3 -- Quit

Enter your choice: 2

**************$2.94

Ann Perkins

217 Lowell Drive

Pawnee IN   47408

|:|::||:::|:|::|||:::|::|:|:::||

**************$1.42

Ron Swanson

3657 White Bridge Road

Eagleton IN   47320

|:|::||:::|::||:::|:|||::::|::||

**************$0.71

Andy Dwyer

789 Cherry Road

Wamapoke IN   48034

|:|::||::|:||:::::||::|::|:::|||

**************$0.49

Ben Wyatt

1513 Plymouth Street

Pawnee IN   47407

|:|::||:::|:|::|||:::|:::||::|:|

**************$2.54

Chris Traeger

8900 Rapport Street

Eagleton IN   47322

|:|::||:::|::||:::|:|::|:|::|:||

Total cost of all the postage is $8.10

1 – Single Mailing

2 – Multiple Mailings

3 -- Quit

Enter your choice: 3

Thank you. Closing program.

Explanation / Answer

ScreenShot

----------------------------------------------------------------------------------------------------------------------------------------------------

Program

//Header file
#include<iostream>
#include<string>
#include <iomanip>
#include <fstream>
#include<stdlib.h>
using namespace std;
//menu function
void menu() {
   cout << "1 – Single Mailing 2 – Multiple Mailings 3 --Quit" << endl;
}
//Main method
int main()
{
   //Declarations and initializations
  
   int ch, product;
   string name, cost, address, city, state, zip;
   double weight;
   int totalCost = 0, p = 1;
   ifstream inputFile;          //file object creation
   string line;//Open fie for reading
   inputFile.open("C:/Users/deept/Desktop/mailing.txt");
   //Loop to dispaly menu until quit
   while (p == 1) {
       menu();
       //Prompt user choice
       cout << "Enter your choice: ";
       cin >> ch;
       switch (ch) {
       case 1:
           //User to get entered details
           cout << "Enter name :";
           cin.ignore();
           getline(cin, name);
           cout << "Enter street address : ";
           getline(cin, address);
           cout << "Enter city : ";
           getline(cin, city);
           cout << "Enter state :";
           cin >> state;
           cout << "Enter zip code : ";
           cin >> zip;
           cout << "Enter 1 for letter, 2 for envelope, 3 for parcel : ";
           cin >> product;
           cout << "Enter weight in ounces : ";
           cin >> weight;
           if (product == 1) {
               cout << endl << "***************$0.93" << endl;
               cout << name << " " << address << " " << city << "      " << state << "   " << zip << endl;
               cout << "| :: | : | :: || :: | :: || : | :: | : | :::: || : |" << endl;
           }
           else if (product == 2) {
               cout << endl << "***************$1.02" << endl;
               cout << name << " " << address << " " << city << "      " << state << "   " << zip << endl;
               cout << "| :: | : | :: || :: | :: || : | :: | : | :::: || : |" << endl;
           }
           else if (product == 3) {
               cout << endl << "***************$1.75" << endl;
               cout << name << " " << address << " " << city << "      " << state << "   " << zip << endl;
               cout << "| :: | : | :: || :: | :: || : | :: | : | :::: || : |" << endl;
           }
           else {
               cout << "We have no mailing service of your choice!!" << endl;
           }
           break;
           //Choice 2 File reading
       case 2:

           if (!inputFile) {
               cout << "Unable to open file";
               exit(1); // terminate with error
           }

           if (inputFile)
           {
               while (inputFile >> line)
               {
                   getline(inputFile, cost);
                   cout << endl << "**************$" << cost << endl;
                   getline(inputFile, name);
                   getline(inputFile, address);
                   getline(inputFile, city);
                   getline(inputFile, state);
                   getline(inputFile, zip);
                   cout << name << endl << address << endl << city << " " << state << " " << zip << endl;
                   cout << "| :: | : | :: || :: | :: || : | :: | : | :::: || : |" << endl;
                   totalCost += stod(cost);
               }
           }
           cout << "Total cost of all the postage is " << totalCost;
           break;
           //quiting from the program
       case 3:
           p = 0;
           cout << "Thank you. Closing program." << endl;
           exit(0);
           break;
           //default condition
       default:
           cout << "your option is wrong please enter option 1-3:" << endl;
           break;
       }
   }
       return 0;
   }


-------------------------------------------------------------------------------------------------------------

Note:-

You have to provide the cost calculation details and how the mailing.txt file.

As per my understatnding ,you need a menu driven program with file reading,

Any clarification ,let me know.