Question
C++ Write a program that maintains the sales of a company. The program keeps records of quarterly sales of every division in the company. Each
C++
Write a program that maintains the sales of a company. The program keeps records of quarterly sales of every division in the company. Each record contains a given divisions information such as name and quarterly sales. The program also performs several functionalities such as: adding a new division record, updating a divisions sales, removing a division record, displaying a divisions sales as well as the overall companys yearly sale, displaying highest and lowest quarters for the company, and saving the divisions data in an output file.
You need to create a structure, Division, to hold individual division details and a vector of Division structs, called divisions, to hold the data for all the companys divisions. The Division struct contains the following fields:
struct Division
{
string name;
double quarterlySales [4];
}
The program should read and process a transaction file DivisionsTrans.txt. The transaction file DivisionsTrans.txt contains several commands such as display, add, search, delete, update, calculateTotalSales, highestLowestQuarter, save... Each command is written on a new line along with some other related information:
Display
This command displays the details of all divisions in a neat table format. Details include the name of the division, the quarterly sales and total sales for that division. For example:
Division Quarter1 Quarter2 Quarter3 Quarter4 TotalSales
-----------------------------------------------------------------------------
Imaging And Printing 22979.00 23854.00 16151.00 25764.00 88748.00
Desktops 13197.00 12844.00 13888.00 15478.00 55407.00
Notebooks 17540.00 16029.00 18830.00 22545.00 74944.00
Workstations 2218.00 2147.00 2148.00 1786.00 8299.00
Note: Decimal numbers should be printed with 2 digits of precision.
There are no spaces in the division names in the transaction file. Each new word in division name starts with capital letter. You need to print them separated by spaces as shown above.
Add DivisionName DivisionQuarter1Sales DivisionQuarter2Sales DivisionQuarter3Sales DivisionQuarter4Sales
This command adds a new Division record to the divisions vector. The program should read the Division details from the transaction file (DivisionName, DivisionQuarter1Sales, DivisionQuarter2Sales, DivisionQuarter3Sales, DivisionQuarter4Sales). The program should check for valid sales values (positive values) and duplicate Division entries (same DivisionName). If the Division does not exist in the vector and the inputs are valid, the program should add an entry for that Division and its details at the end of the vector. You can simply use the push_back function to add it to the end of the vector. The program should also display a message that the Division was successfully added to the vector. For example:
add ImagingAndPrinting 22979.00 23854.00 16151.00 25764.00
successfully added to divisions
If the Division already exists in the vector, it should not be added again. Similarly, if the input values are invalid, then the division will not be added. In both scenarios, the program should display an error message. For example:
add Corporate 22560.00 -23000.00 22800.00 29056.00
Invalid data, can not be added to divisions
Search DivisionName
This command searches and returns all Divisions whose names match DivisionName. DivisionName could be the exact name or a keyword found in the name. So any entries whose name fully or partially matches DivisionName should be displayed. For example, if DivisionName is Systems, the program should display the following Divisions from the list:
search Systems
Division Quarter1 Quarter2 Quarter3 Quarter4 TotalSales
-----------------------------------------------------------------------------
Personal Systems 34303.00 32071.00 35650.00 40741.00 142765.00
Enterprise Systems 27814.00 28183.00 20491.00 18651.00 95139.00
If no matching entry is found, the program should display a message that this Division does not exist. For example:
search Hardware
No such division exists
Delete DivisionName
This command deletes an existing Division entry specified by its DivisionName. The entry whose name matches DivisionName should be deleted. Note that deleting could be from any entry in the vector and not necessarily the last record. The program should also display a message that the Division was successfully deleted from the vector. For example:
delete Enterprise
successfully deleted
If no matching entry is found, the program should display a message that this Division does not exist. For example:
delete PDA
No such division exist, can not be deleted
Update DivisionName Quarter QuarterSales
This command updates the quarterly sales of a given Division. The command specifies DivisionName, Quarter, and QuarterSales, which correspond to the name of the Division that should be updated, the quarter whose sales must be changed, and the new quarterly sales value, respectively. The program searches for the Division whose name matches DivisionName. If a match is found, it updates the sales for the specific quarter Quarter to Quarter Sales. The program should also display a message that the Division was successfully updated. For example:
update Desktops 3 12888.00
successfully updated quarter 3 sales to 12888.00
Otherwise, the program should display a message that this Division was not found. For example:
update Auxiliary 2 12030.00
no such division exists, can not be updated
CalculateTotalSales
This command calculates and prints the total sales of all divisions in the company.
HighestLowestQuarter
This command determines and prints which quarters have the highest and lowest amount of sales for the company.
Save
This command saves the divisions vector data in an output file DivisionsOut.txt. Once done, the program should display a message that the vector is successfully written to file. For example:
Divisions data successfully saved
Note: Each command must be implemented in a separate function.
To test your code, you may load and process the following transaction file:
DivisionsTrans.txt add ImagingAndPrinting 22979.00 23854.00 16151.00 25764.00 add Desktops 13197.00 12844.00 13888.00 15478.00 add Notebooks 17540.00 16029.00 18830.00 22545.00 add Workstations 2218.00 2147.00 2148.00 1786.00 add AuxiliarySystems 33303.00 35072.00 29650.00 -36750.00 add PersonalSystems 34303.00 32071.00 35650.00 40741.00 add EnterpriseSystems 27814.00 28183.00 20491.00 18651.00 add Software 3933.00 3913.00 4060.00 3586.00 add Corporate 22560.00 -23000.00 22800.00 29056.00 add FinancialServices 3498.00 3629.00 3819.00 3047.00 add OtherServices 22398.00 23520.00 34922.00 34935.00 add Notebooks 27540.00 18029.00 20830.00 22595.00 display search Printing search Desktops search Corporate search Systems search Hardware delete Other delete Corporate delete PDA delete Enterprise update Desktops 3 12888.00 update Imaging 5 34000.00 update Auxiliary 2 12030.00 update Workstations 1 4322.00 display calculateTotalSales highestLowestQuarter save |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started