Question

CIS 1111 Programming Files

Description:

In this assignment, you will write a program in C++ that uses files and nested loops to create a file for real estate agents home sales and then read the sales from the file and calculates the average sale for each agent. Each agent sold 4 homes.  Use a nested loop to write each agent’s sales to a file. Then read the data from the file in order to display the agent’s average sale and the average for all sales. Determine which agent had the highest total sales and display their name and total sales

Enter 4 sales for each agent. Column 1 is the agent’s name and Column 2-5 are their sales in 1000’s.

Agent

House 1

House 2

House 3

House 4

Martha

90

125

60

125

Leela

55

25

75

100

Jorge

130

60

70

100

 

Requirements:

1.      Use a nested loop structure to input the data and write the data to a text file.

a.      The outer loop will be a while loop (unknown number of agents), the inner loop will be a for loop (4 sales).

b.      Have the user enter the agent’s name.

c.      Have the user enter 4 sales and validate whether the sale prices are in range (0-200).

d.      Since you do not know how many agents will be entered, add a way to quit the loop.

e.      Add a new line (endl) after each agent name. Add spaces after each sales added to the text file except after the last sale add a new line.

f.       You may not count the number of agents processed.

 

 

2.      Use a nested loop structure to read the data from the text file and calculate the agent’s average sale.

a.      The outer look will be a while loop; the inner loop will be a for loop (4 sales)

b.      To calculate each agent’s average sale, use an accumulator (total agent variable) initialized to 0 before the for loop, then calculate the agent’s average after the loop.

c.      To calculate the total average sale, you will need an accumulator for the company.  Add each agent’s total into the total agency variable following the for loop, then calculate the agency average after the while loop.

d.      Only display 2 decimals for the averages.

3.      Use cout to output the values of the variables to the console. Your cout statement MUST use the variables to display the values

4.      Output must be labelled and easy to read as shown in the sample output below.

5.      Program must be documented with the following:

a.      // Name

b.      // Date

c.      // Program Name

image.png

image.png

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code for Crete agentSales.txt file

#include
#include
#include
using namespace std;

int main()
{
   ofstream out("agentSales.txt");
   string name;
   int sales;
   cout << "Enter the name of the Agent: ";
   cin >> name;
   while (true)
   {
       out << name;
       for (int i = 0; i < 4; i++)
       {
           while (true)
           {
               cout << "Enter the sale price of Home1: ";
               cin >> sales;
               if (sales >= 0 && sales < 200)
                   break;
               cout << "Enter the sale price in range 0 - 200\n";
           }
           out << " " << sales;
       }
       cout << "Enter the name of the agent or \"stop\" to stop: ";
       cin >> name;;
       if (name == "stop")
           break;
       out << endl;
   }
   system("pause");
   return 0;
}

output- x I D: Chegg\C++\Write agent sale in file and then read anc calc avg\Debug\Write agent sale in file and then read anc calc

agentSales.txt- 0 agentSales - Notepad File Edit Format View Help Martha 90 125 60 125 Leela 55 25 75 100 Jorge 130 60 70 100 Ln 1, Col 1 1

code for reading the file and then find the average

code

#include
#include
#include
#include
using namespace std;

int main()
{
   ifstream in;
   in.open("agentSales.txt");
   double avg,sale;
   double sum;
   string name;
   if (!in)
   {
       cout << "Can not find the file. Exiting...." << endl;
       return 0;
   }
   cout << fixed << setprecision(2);
   cout << "Agent\t\tAverage Sales" << endl;
   while (!in.eof())
   {
       in >> name;
       sum = 0;
       for (int i = 0; i < 4; i++)
       {
           in >> sale;
           sum += sale;
       }
       avg = sum / 4;
       cout << name << "\t\t$" << avg << endl;
   }
   system("pause");
   return 0;
}

output

- x I D: Chegg\C++\Write agent sale in file and then read anc calc avg\Debug\Write agent sale in file and then read anc calc

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
CIS 1111 Programming Files
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
  • In this assignment, you will write a program in C++ which uses files and nested loops...

    In this assignment, you will write a program in C++ which uses files and nested loops to create a file from the quiz grades entered by the user, then reads the grades from the file and calculates each student’s average grade and the average quiz grade for the class. Each student takes 6 quizzes (unknown number of students). Use a nested loop to write each student’s quiz grades to a file. Then read the data from the file in order...

  • C++ Programming- CIS 1111 The CPlusPlus & LandMinusMinus Company needs you to write a program which...

    C++ Programming- CIS 1111 The CPlusPlus & LandMinusMinus Company needs you to write a program which will produce a report, in both number and chart form, which will display Net Sales for their three company divisions, for any given month of the year entered by the user. The corporate tax rate for the company is 30% (define as constant); the three division names are East-Coast, Mid-West, and West-Coast. Requirements Have the user enter a month name, and then process each...

  • Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read...

    Programming Assignment 1 Structures, arrays of structures, functions, header files, multiple code files Program description: Read and process a file containing customer purchase data for books. The books available for purchase will be read from a separate data file. Process the customer sales and produce a report of the sales and the remaining book inventory. You are to read a data file (customerList.txt, provided) containing customer book purchasing data. Create a structure to contain the information. The structure will contain...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

  • Use two files for this lab: your C program file, and a separate text file containing...

    Use two files for this lab: your C program file, and a separate text file containing the integer data values to process. Use a while loop to read one data value each time until all values in the file have been read, and you should design your program so that your while loop can handle a file of any size. You may assume that there are no more than 50 data values in the file. Save each value read from...

  • CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes...

    CIS 22A C++ Project Exam Statistics Here is what your program will do: first it welcomes the user and displays the purpose of the program. It then prompts the user to enter the name of an input file (such as scores.txt). Assume the file contains the scores of the final exams; each score is preceded by a 5 characters student id. Create the input file: copy and paste the following data into a new text file named scores.txt DH232 89...

  • Java Programming Reading from a Text File Write a Java program that will use an object...

    Java Programming Reading from a Text File Write a Java program that will use an object of the Scanner class to read employee payroll data from a text file The Text file payroll.dat has the following: 100 Washington Marx Jung Darwin George 40 200 300 400 Kar Car Charles 50 22.532 15 30 The order of the data and its types stored in the file are as follows: Data EmployeelD Last name FirstName HoursWorked double HourlyRate Data Tvpe String String...

  • C++ requirements The store number must be of type unsigned int. The sales value must be...

    C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...

  • convert pseducode to c++ Starting out with Programming Logic and Design (3) - Read-only Terates once...

    convert pseducode to c++ Starting out with Programming Logic and Design (3) - Read-only Terates once for each student. The nested inner loop, in lines 27 through 31, iterates once for each test score. Program 5-20 1 1 This program averages test scores. It asks the user for th 2 1/ number of students and the number of test scores per stude Declare Integer numStudents 4 Declare Integer numTest Scores 5 Declare Integer total 6 Declare Integer student 7 Declare...

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