Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Modify the menue so that it contains five options. //ADD Record, Display Record, Display Total Sales, Display Average sales, //and Exit. When the user

C++

Modify the menue so that it contains five options. //ADD Record, Display Record, Display Total Sales, Display Average sales, //and Exit. When the user selects 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

#include  #include  #include  using namespace std; sales.txt 
June Mayfield#23400 Eric Jefferson#26700
 //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()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions