Question: I Need some help with a computer science question in C++ A company has six salespeople. Every month, they go on road trips to sell
I Need some help with a computer science question in C++
A company has six salespeople. Every month, they go on road trips to sell the companys product. At the end of each month, the total sales for a salesperson in that month, together with that salespersons ID and the month, is recorded in a file. At the end of each year, the manager of the company wants to see an annual sales report. Due to the amount of data involved, hes like to be able to view the report by ID or by total sales.
Write a program to load id data from salesID.txt, sales data from salesData.txt (unknown # of records. The records are not in any order of sales id or month), calculate the total sales of each person in a year, and display a report. Shell code is provided in HW8_SalesReport_shell.cpp. You need understand the shell code and then add:
ADD CODE #1: declaration of two functions sortByID and showReport. Also include:
Function prologue comment
/*IN*/, /*OUT*/, /*INOUT*/ comments to each function parameter.
Pre- and Post- condition comments for each function.
ADD CODE #2: complete function loadData
ADD CODE #3: implementation of two functions sortByID and showReport
Youre not supposed to modify the given code otherwise (at least 20% penalty).
The output of your program (data, format ) must match those screenshots:

*************************************************
SalesData.txt
12345 1 893
32214 1 343
23422 3 903
57373 2 893
35864 5 329
54654 9 392
12345 2 999
32214 4 892
23422 4 895
23422 2 492
57373 6 892
35864 10 1223
54654 11 3420
12345 12 322
35864 5 892
54654 3 893
12345 8 494
32214 8 9023
23422 6 223
23422 4 783
57373 8 8834
35864 3 2882
****************************************
salesID.txt
32214
23422
57373
35864
54654
12345
********************************************************************************
// HW8_SalesReport_shell.cpp (shell code. need ADD CODE #1 ~ #3)
#include
#include
#include
#include
//----------------------------------------------
// global declarations
//----------------------------------------------
const int MAX = 10; // max # of sales person
struct salesPersonRec
{
std::string ID; // salesperson's ID
double totalSales; // salesperson's yearly sales amount
};
//----------------------------------------------
// function declarations
//----------------------------------------------
// read id data into array and set totalSales of each record to 0
bool loadID(salesPersonRec list[]/*OUT*/, int listSize/*IN*/);
// Pre: listSize specified
// Post: listSize # of ids read in from file and saved in the ID column in the first listSize records of list. totalSales of those records set to 0
// read in sales data and calculate total sales per person
bool loadData(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/);
// Pre: listSize specified, list contains valid ids and totalSales set to 0 for the first listSize records
// Post: sales data read from file
// totalSales of the first listSize records are set to accumulated sales of the salesperson with the given id
// display menu on screen
void showMenu();
// Pre: none
// Post: menu choices printed on screen
// display id and yearly sales amout of all salespersons by id order
void showReportByID(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/);
// Pre: listSize specified, list contains at least listSize number of records
// Post: the first listSize records in list are reordered so they are now in ascending order of the id column
// id and totalSales column of the first listSize records in list are printed on screen
// display id and yearly sales amout of all salespersons by total sales order
void showReportBySales(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/);
// Pre: listSize specified, list contains at least listSize number of records
// Post: the first listSize records in list are reordered so they are now in ascending order of the total sales column
// id and totalSales column of the first listSize records in list are printed on screen
// sort sales person records by total sales amount
void sortBySales(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/);
// Pre: listSize specified, list contains at least listSize number of records
// Post: the first listSize records in list are reordered so they are now in ascending order of the totalSales column
// ADD CODE #1: two function declarations
// END ADD CODE #1
//----------------------------------------------
int main()
{
salesPersonRec salesPersonList[MAX]; // array to hold the salesperson's data
int numOfSalesPerson = 6;
if (!loadID(salesPersonList, numOfSalesPerson)) // load id data
return 1;
if (!loadData(salesPersonList, numOfSalesPerson)) // load sales data
return 1;
// user interaction via menu
int option = 0; // user option
do
{
// display menu
showMenu();
// user option
std::cin >> option;
switch (option)
{
case 1: // sort and display report by id
showReportByID(salesPersonList, numOfSalesPerson);
break;
case 2: // sort and display report by sales
showReportBySales(salesPersonList, numOfSalesPerson);
break;
case 0: // exit
std::cout
break;
default: // invalid input
std::cout
break;
}
} while (option != 0);
} // end main
//----------------------------------------------
// Function Implementation
//----------------------------------------------
// read id data into array and set totalSales of each record to 0
bool loadID(salesPersonRec list[]/*OUT*/, int listSize/*IN*/)
{
std::ifstream inFile; // input file
std::string idfilename = "salesID.txt";
// open id file
inFile.open(idfilename);
if (inFile.fail())
{
std::cerr
return false; // and end now
}
// read in id data
for (int index = 0; index
{
if (!(inFile >> list[index].ID)) // get salesperson's ID
return false; // reading failed
list[index].totalSales = 0.0;
}
inFile.close(); // close file
return true;
} //end loadID
//----------------------------------------------
// read in sales data and calculate total sales of each person
bool loadData(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/)
{
std::ifstream inFile; // input file
std::string datafilename = "salesData.txt";
// open sales data
inFile.open(datafilename);
if (inFile.fail())
{
std::cerr
return false; // and end now
}
// read in data and process
std::string id;
int month;
double amount;
// ADD CODE #2:
// read sales data from file,
// calculate and update totalSales of each record
// END ADD CODE #2
inFile.close(); // close data file
return true;
} //end loadData
//----------------------------------------------
// display menu on screen
void showMenu()
{
const std::string menuOptions[] = { "Options:",
"1. Display sales report by sales id.",
"2. Display sales report by annual sales amount.",
"0. Exit",
"Choose (0 ~ 2): "
};
int menuLen = sizeof(menuOptions) / sizeof(std::string);
std::cout
for (int i = 0; i
std::cout
std::cout
} // end getUserOption
//----------------------------------------------
void showReportByID(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/)
{
sortByID(list, listSize);
showReport(list, listSize);
} // end showReportByID
//----------------------------------------------
void showReportBySales(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/)
{
sortBySales(list, listSize);
showReport(list, listSize);
} // end showReportBySales
//----------------------------------------------
void sortBySales(salesPersonRec list[]/*INOUT*/, int listSize/*IN*/)
{
// insertion sort
for (int i = 1; i
{
// find spot to insert [i]
salesPersonRec hold = list[i];
double amount = list[i].totalSales;
int indexToInsert = i - 1;
while (indexToInsert >= 0 && amount
{
// shift
list[indexToInsert + 1] = list[indexToInsert];
indexToInsert--;
}
// insert
list[indexToInsert + 1] = hold;
}
} // end sortBySales
//----------------------------------------------
// ADD CODE #3: implementation of two functions
// END ADD CODE #3
***********************************************************
Options: 1. Display sales report by sales id 2. Display sales report by annual sales amount 0. Exit Choose 0 ~ 2): 1 Annual Sales Report Total Sales 12345 23422 32214 35864 54654 57373 2708.00 3296.00 10258.00 5326.00 4705.00 10619.00 Options: Display sales report by sales id. 2. Display sales report by annual sales amount. 0. Exit Choose : 2 Annual Sales Report Total Sales 12345 23422 54654 35864 32214 57373 2708.00 3296.00 4705.00 5326.00 10258.00 10619.00
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
