Question: C++ //Lab Wednesday.cpp - Modify the menue so that it contains five options. //ADD Record, Display Record, Display Total Sales, Display Average sales, //and Exit.

C++

//Lab Wednesday.cpp - Modify the menue so that it contains five options. //ADD Record, Display Record, Display Total Sales, Display Average sales, //and Exit. When the user selests the Display Records option, the program should call //a function to display the contents of the sales.txt file on the screen. When the user // selest the Display Average Sales option, the program should call a function to calculate // and display the average sales amount stored in the file. Test the options and uplaad to the // assignment link.saves records to a sequential access //file and also calculates and displays the total //of the sales amounts stored in the file //Displays the records and the average sales amount

#include  #include  #include  using namespace std; //function prototypes int getChoice(); void addRecords(); void displayRecords(); void displayTotal(); int main() { int choice = 0; do { //get user's menu choice choice = getChoice(); if (choice == 1) addRecords(); else if (choice == 2) displayRecords(); else if (choice == 3) displayTotal(); else if (choice == 4) displayAvg(); //end if } while (choice != 5); return 0; } //end of main function //*****function definitions***** int getChoice() { //displays menu and returns choice int menuChoice = 0; cout << endl << "Menu Options" << endl; cout << "1 Add Records" << endl; cout << "2 Display Records" << endl; cout << "3 Display Total Sales" << endl; cout << "4 Display Average Sales" << endl; cout << "5 Exit" << endl; cout << "Choice (1 through 5)? "; cin >> menuChoice; cin.ignore(100, ' '); cout << endl; return menuChoice; } //end of getChoice function void addRecords() { //saves records to a sequential access file string name = ""; int sales = 0; ofstream outFile; //open file for append outFile.open("sales.txt", ios::app); //if the open was successful, get the //salesperson's name and sales amount and //then write the information to the file; //otherwise, display an error message if (outFile.is_open()) { cout << "Salesperson's name (X to stop): "; getline(cin, name); while (name != "X" && name != "x") { cout << "Sales: "; cin >> sales; cin.ignore(100, ' '); outFile << name << '#' << sales << endl; cout << "Salesperson's name " << "(X to stop): "; getline(cin, name); } //end while outFile.close(); } else cout << "sales.txt file could not be opened" << endl; //end if } //end of addRecords function void displayRecords() { //displays the contents of the sales.txt file string name = ""; int sales = 0; ifstream inFile; //open file for input inFile.open("sales.txt"); //if the open was successful, read a //record and then display the record //otherwise, display an error message if (inFile.is_open()) { getline(inFile, name, '#'); inFile >> sales; inFile.ignore(); while (!inFile.eof()) { cout << name << " $" << sales << endl; getline(inFile, name, '#'); inFile >> sales; inFile.ignore(); } //end while inFile.close(); } else cout << "sales.txt file could not be opened." << endl; //end if } //end of displayRecords function void displayTotal() { //calculates and displays the total sales string name = ""; int sales = 0; int total = 0; ifstream inFile; //open file for input inFile.open("sales.txt"); //if the open was successful, read the //salesperson's name and sales amount, then add //the sales amount to the accumulator, and then //display the accumulator; otherwise, display //an error message if (inFile.is_open()) { getline(inFile, name, '#'); inFile >> sales; inFile.ignore(); while (!inFile.eof()) { total += sales; getline(inFile, name, '#'); inFile >> sales; inFile.ignore(); } //end while inFile.close(); cout << "Total sales $" << total << endl << endl; } else cout << "sales.txt file could not be opened" << endl; //end if } //end of displayTotal function void displayAvg()

//this is the sales.txt file

June Mayfield#23400 Eric Jefferson#26700

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!