Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROJECT: Sales Data Analysis Complete the Sales Data Analysis project we discussed in class (W09 Th). A company has six salespeople. Every month, they go

PROJECT: Sales Data Analysis

Complete the Sales Data Analysis project we discussed in class (W09 Th).

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 HW7_SalesReport_shell.cpp. You need to understand the shell code and then add:

ADD CODE #1: function declarations (multiple)

ADD CODE #2: complete function loadData

ADD CODE #3: function implementations (multiple)

Youre not supposed to modify the given code otherwise (at least 20% penalty).

Your .cpp file should also contain:

Algorithms (pseudo code) for two functions: loadData and the function to sort records by total sales amount. Add them as block comments at the beginning of your source code file. If you choose to draw flowchart, include it in your HW document instead.

Pre- and Post- condition comments for each function.

/*IN*/, /*OUT*/, /*INOUT*/ comments to function parameters

Comment your program appropriately. Pay attention to the standard stuff like coding style, indention, heading, and curly braces.

HTML CODE:

// SalesReport.cpp (shell) // CS225 // generate sales report using monthly sales data // fixed # of sales people; unknown # of sales record // // ADD: function definitions and implmentation

#include #include // std::ifstream #include // std::string

//---------------------------------------------- // 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

// display menu on screen void showMenu(); // Pre: none // Post: menu choices printed on screen

// ADD

bool loadData(salesPersonRec list [] /*INOUT*/, int listSize/*IN*/); //Pre: listSize specified //Post: listSize # of sales read in from file and saved in the sales column in the second listSize records of list, // totalSales of those records set to 0

void showReportByID(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); //Pre: listSize specified //Post: gives the data to sortByID // gives the data to showReport

void showReportBySales(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); //Pre: listSize specified //Post: gives the data to sortBySales // gives the data to showReport

void sortBySales(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); //Pre: listSize specified // data sorted by showReportBySales //Post: sorts by sales // salesPersonRec list [] with sales

void sortByID(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); //Pre: listSize specified // data sorted by showReportByID //Post: sorts data by ID // salesPersonRec list [] with ID

void showReport(const salesPersonRec list[] /*IN*/, int listSize /*IN*/); //Pre: listSize specified // salesPersonRec list given // takes data from showReportByID // takes data from showReportBySales //Post: prints sales data // prints ID data

//----------------------------------------------

int main() { salesPersonRec salesPersonList[MAX]; // array to hold the salesperson's data int numOfSalesPerson = 6;

if (!loadID(salesPersonList, numOfSalesPerson)) // load id data return 1; // failed

if (!loadData(salesPersonList, numOfSalesPerson)) // load sales data return 1; // failed

// 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 << " Thank you for using our reporting system! "; break; default: // invalid input std::cout << "invalid choice. Please try again. "; break; } } while (option != 0);

return 0; } // end main

//---------------------------------------------- // Function definition //----------------------------------------------

// read id data into array and set totalSales of each record to 0 bool loadID(salesPersonRec list[]/*OUT*/, int listSize/*IN*/) { // open input file std::string idfilename = "salesID.txt";

std::ifstream inFile(idfilename); if (inFile.fail()) { std::cerr << "Error: can't open input file \"" << idfilename << "\". Abort. "; // report to cerr return false; // and end now }

// read in id data for (int index = 0; index < listSize; 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

//----------------------------------------------

// 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 << std::endl; for (int i = 0; i < menuLen - 1; i++) std::cout << menuOptions[i] << std::endl; std::cout << menuOptions[menuLen - 1]; // last item } // end showMenu

//----------------------------------------------

// ADD bool loadData(salesPersonRec list[] /*INOUT*/, int listSize/*IN*/) {

return success; }

void showReportByID(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/) { sortByID(list, listSize); showReport(list, listSize); }

void showReportbySales(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/) { sortBySales(list, listSize); showReport(list, listSize); }

void showReport(const salesPersonRec list[] /*IN*/, int listSize /*IN*/); { std::cout << " Will print report "; }

void sortByID(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); { std::cout << " Will be sorted by ID "; }

void sortBySales(salesPersonRec list[] /*INOUT*/, int listSize /*IN*/); { std::cout << " Will be sorted by sales "; }

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

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students also viewed these Databases questions