Question
Please add code for program.
movies.txt file. LAB 14-2 Plan and Create In this lab, you will plan and create an algorithm for Cheryl Liu, the owner of a candy shop named Sweets-4-You. The problem specification is shown in Figure 14-15. Problem specification Cheryl Liu is the owner of a candy shop named Sweets-4-You. She wants a program that displays the following menu: Menu Options 1 Add Records 2 Display Total Sales 3 Exit If Cheryl selects option 1, the program should call a function that prompts her to enter each salespersons name and sales amount. The function should save Cheryls entries in a sequential access file named sales.tct. If Cheryl selects option 2, the program should call a function that calculates and displays the total of the sales amounts stored in the sales.txt file. The program should end only when Cheryl selects option 3. igure 14-15 Problem specification for Lab 142
media%2F2b3%2F2b3c61f6-d943-4429-9e09-87
media%2F36e%2F36e4fe64-b9bc-412f-8fe0-4f
media%2F3a0%2F3a098d53-d935-4618-a0cf-1a
media%2F37f%2F37f96629-c7ec-4ce2-ba49-a5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN C++ IN VISUAL STUDIO

#include<iostream>

#include<fstream>

#include<string>

#include <iomanip>

using namespace std;

int getChoice();

void addRecord();

void displayTotal();

void displayRecords();

void displayAverage();

int main()

{

int choice=0;

do

{

choice=getChoice();

if(choice==1)

addRecord();

else if(choice==2)

displayRecords();

else if(choice==3)

displayTotal();

else if(choice==4)

displayAverage();

}while(choice!=5);

return 0;

}

int getChoice()

{

int menuChoice=0;

cout<<endl<<"Menu Option"<<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,2,3,4 or 5)? ";

cin>>menuChoice;

cin.ignore(100,'\n');

cout<<endl;

return menuChoice;

}

void addRecord()

{

string name="";

int sales=0;

ofstream outFile;

outFile.open("sales.txt",ios::app);

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,'\n');

outFile<<name<<'#'<<sales<<endl;

cout<<"Salesperson's name"<<"(X to stop): ";

getline(cin, name);

}

outFile.close();

}

else

cout<<"Sales.txt file could not be opened."<<endl;

}

void displayTotal()

{

string name ="";

int sales=0;

int total=0;

ifstream inFile;

inFile.open("sales.txt");

if(inFile.is_open())

{

getline(inFile,name,'#');

inFile>>sales;

inFile.ignore();

while(!inFile.eof())

{

total+=sales;

getline(inFile,name,'#');

inFile>>sales;

inFile.ignore();

}

inFile.close();

cout<<"Total sales $"<<total<<endl<<endl;

}

else

cout<<"Sales.txt file could no be opened"<<endl;

}

void displayRecords()

{

ifstream inFile;

string str;

inFile.open("sales.txt");

if(inFile.is_open())

{

while (std::getline(inFile, str))

{

size_t pos = str.find("#");//find the position of the # in the line

string str3 = str.substr (0,pos);//then taking substring upto the #

//and then print the name and the price (for taking price take the substring from the pos+1)

cout << "Salesperson's name: "<<str3 <<", Sales =$"<<str.substr(pos+1)<<endl;

// now we loop back and get the next line in 'str'

}

}

else

cout<<"Sales.txt file could no be opened"<<endl;

}

void displayAverage()

{

string name ="";

int sales=0;

int total=0;

int count_Records=0;//this variable keep track on the no of records in the file

ifstream inFile;

inFile.open("sales.txt");

//this is same as the finding the total

//but here we have the find the no of records in the file

if(inFile.is_open())

{

getline(inFile,name,'#');

inFile>>sales;

inFile.ignore();

count_Records++;//increment by 1

while(!inFile.eof())

{

count_Records++;//increment by 1

total+=sales;

getline(inFile,name,'#');

inFile>>sales;

inFile.ignore();

}

double avg=double(total)/double(count_Records);//calculate the avarage bye this formula

std::cout << std::fixed;

std::cout << std::setprecision(2);//this is for setting precision upto 2 points

cout<<"Avarage sales $"<<avg<<endl<<endl;

}

else

cout<<"Sales.txt file could no be opened"<<endl;

}

OUTPUT

SALES.TXT FILE

CODE SNAPS

IF YOU HAVE ANY QUERY REGARDING THIS CODE PLEASE ASK ME IN THE COMMENT I AM HERE FOR HELP. THANKS. PLEASE APPRICIATE MY WORK WITH THUMBS UP.

Add a comment
Know the answer?
Add Answer to:
Please add code for program. movies.txt file. LAB 14-2 Plan and Create In this lab, you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ program Write a C++ program to manage a hospital system, the system mainly uses file...

    C++ program Write a C++ program to manage a hospital system, the system mainly uses file handling to perform basic operations like how to add, edit, search, and delete record. Write the following functions: 1. hospital_menu: This function will display the following menu and prompt the user to enter her/his option. The system will keep showing the menu repeatedly until the user selects option 'e' from the menu. Arkansas Children Hospital a. Add new patient record b. Search record c....

  • unctions with No Parameters Summary In this lab, you complete a partially prewritten Python program that...

    unctions with No Parameters Summary In this lab, you complete a partially prewritten Python program that includes a function with no parameters. The program asks the user if they have preregistered for art show tickets. If the user has preregistered, the program should call a function named discount() that displays the message "You are preregistered and qualify for a 5% discount." If the user has not preregistered, the program should call a function named noDiscount() that displays the message "Sorry,...

  • Write a C# code for a Sales Calculator: Note: You cannot use the foreach loop in...

    Write a C# code for a Sales Calculator: Note: You cannot use the foreach loop in any part of this program! sales.txt file: 1189.55, 1207.00, 1348.27, 1456.88, 1198.34, 1128.55, 1172.37, 1498.55, 1163.29 The application should have controls described as follows: • A button that reads Get Sales. If the user clicks this button, the application should call a method named ProcesSalesFile. ProcessSalesFile Method: accepts no arguments and does not return anything The ProcessSalesFile Method will do the following: o Open...

  • Write a C# code for a Sales Calculator: Note: You cannot use the foreach loop in any part of this...

    Write a C# code for a Sales Calculator: Note: You cannot use the foreach loop in any part of this program! sales.txt file: 1189.55, 1207.00, 1348.27, 1456.88, 1198.34, 1128.55, 1172.37, 1498.55, 1163.29 The application should have controls described as follows: • A button that reads Get Sales. If the user clicks this button, the application should call a method named ProcesSalesFile. ProcessSalesFile Method: accepts no arguments and does not return anything The ProcessSalesFile Method will do the following: o Open...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • C Program Assignment: 2-Add comments to your program to full document it by describing the most...

    C Program Assignment: 2-Add comments to your program to full document it by describing the most important processes. 3-Your variables names should be very friendly. This means that the names should have meaning related to what they are storing. Example: Instead of naming the variable that stores the hours worked for an employee in a variable called ‘x’ you should name it HoursWorked. 5-Submit your .c program (note that I only need your source code and not all files that...

  • INSTRUCTION AND PROBLEMS Write a Python program for each of the problems in this lab. Please...

    INSTRUCTION AND PROBLEMS Write a Python program for each of the problems in this lab. Please use PyCharm to type and test your programs. Submit the Python files to Blackboard for credit. In this lab, you should submit 4 Python files, one for each problem PROBLEM I Energy consumption is measured in units of kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy bll. A power company charges customers $0.12 per kWh for...

  • Please write this program in C++, thanks Task 9.3 Write a complete C++ program to create a music player Your program sh...

    Please write this program in C++, thanks Task 9.3 Write a complete C++ program to create a music player Your program should read in several album names, each album has up to 5 tracks as well as a genre. First declare genre for the album as an enumeration with at least three entries. Then declare an album structure that has five elements to hold the album name, genre, number of tracks, name of those tracks and track location. You can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT