Student Performance Objectives:

  • To review the the C++ switch
  • To review sentinel control
  • To design and implement a modular program with functional reuse
  • To introduce database processing using text file input and output
  • To implement a solution using parallel partially-filled arrays
  • To use the selection sort algorithm
  • To produce a report with output in columnar format using setw()

Problem Scenario:

Super-Cool, Inc. is a large retail clothing store. When a salesperson checks-out a customer at the cash-register, the amount is recorded and credited toward the employee. The CEO has requested a report program to compare the sales of the employees. For overall summary information print:

1.the number of salespersons,

2.the overall total $ amount of all merchandise sales,

3.the largest total sales amount by an employee.

The report will have two sections:

1.Section 1: ORDERED BY ID

2.Section 2: ORDERED BY TOTAL SALES AMOUNT

A detailed report layout has been approved the client (CEO). See below.

Assignment Requirements:

from Tony Gaddis, Starting out with C++ from Control Structures through Objects, Pearson Education: 2009. p. 302.

1.The program must include the required documentation (Identification Header, Problem Specification, Problem Analysis) and follow programming documentation guidelines (see A#2).

Before each function definition include the following documentation:

//********************************************************************
// FUNCTION NAME: XXXXXXXXXXXXXXXXXXXXXXX
// FUNCTION PURPOSE: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// INPUT PARAMETERS:
// 1. XXXXXXX – description of parameter
// 2. XXXXXXXXXX - description of parameter
//RETURN VALUE – description
//********************************************************************

2.The program must use text file input and file output using ifstream and ofstream. Recall if the files do not open, the program will end. Close all files.

3.The input ASCII text file is named SuperCool.data and can be copied from the class directory using the following command:

$cp ~cs1253_dou/SuperCool.data SuperCool.data

The program must read data from the input file and store into the parallel partially-filled arrays: ID, department code, and total sales. Data fields are separated by spaces. Data records are one record per line. There is an unknown number of records in the data file, but no more than 25.

After the input data is read from the file and stored into the arrays, the input file is closed and all processing thereafter in the program is by using the arrays. ONLY READ until end of file ONE TIME!

The data records in the file are arranged in ascending order by IDs in the following way:

Sales Person ID (integer) 3- digits,Department Code, Total Sales ($$$$) (real with 2 decimals)
301, 4, 237.99
325, 3, 9283.05
359, 2, 5483.82

4.Include the following statements in a logical place after you have opened your output file. The identifier fout is the name of the output stream:

fout.setf(ios::fixed);
fout.setf(ios::showpoint);
fout.precision(2);

If you prefer, use the I/O manipulators for fixed and setprecision(2)

5.To justify values within a field, code setw(?)where ? is the width of the data field where the value will be printed - right justified for numbers/ left justified for strings.

Place in your program with the other preprocessor directives: #include < iomanip>

Example usage where fout is the name of the output stream:

fout << setw(10) << OldX;
fout << setw(8) << NewX << endl;

0123456789012345678901234567890 <- column guide
-5.00 -0.19 <- printed output line from above

6.DO NOT print the department codes. Use a C++ switch statement to print the department description.

Department Code, DepartmentDescription
1, Shoes
2, Women
3, Men
4, Jewelry(msc)

7.For the report section 2, use the selection sort algorithm to order the parallel partially-filled arrays by increasing decreasing order of the Total Sales. See C++ code below.

8.The output file MUST be named Report.out. To verify your programs output, use the pico editor to view the file: $pico Report.out

Columns MUST line up neatly (justified within a field). The report format should follow this example.

###############################################
###############################################


Super-Cool, Inc.
Sales Comparison - ORDERED BY ID

SALES_ID DEPARTMENT TOTAL_SALES_$
301 Jewelry(msc) 237.99
325 Men 9283.05
359 Women 5483.82
:
----------- SUMMARY_OVERALL -----------
NUMBER_OF_SALESPERSON: X
TOTAL_SALES_$: XXXXXXXXXXX.XX
LARGEST_SALES_AMOUNT_$: XXXXXXXXXXX.XX


###############################################
###############################################


Super-Cool, Inc.
Sales Comparison - ORDERED BY TOTAL SALES

SALES_ID DEPARTMENT TOTAL_SALES_$
325 Men 9283.05
359 Women 5483.82
301 Jewelry(msc) 237.99
:
----------- SUMMARY_OVERALL -----------
NUMBER_OF_SALESPERSON: X
TOTAL_SALES_$: XXXXXXXXXXX.XX
LARGEST_SALES_AMOUNT_$: XXXXXXXXXXX.XX

###############################################
###############################################

9.The main function should be minimal for a good design. It is OK to open and close files in main. You may use more functions, but these individual separate functions are mandatory:

a.To read until end of file and store data into the parallel partially-filled arrays: ID, department code, and total sales. DO NOT CALCULATE SUM OF TOTAL SALES and LARGEST $ here!

b.To calculate the overall sum of all total sales of the employees.

c.To calculate the largest sales amount

d.To print a report section (Call this report two times!)

  • 1.SUBFUNCTION 1: To print the headings: title, sub-title, column heading
  • 2.SUBFUNCTION 2: To print the department description and NOT the department code (use the C++ switch)
  • 3.SUBFUNCTION 3: To print the summary information.

a.To sort the parallel partially-filled arrays (use the Selection Sort).

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.