Question

In: Computer Science

Hi, could you please expand on this code to include: Total earnings per division (East, West,...

Hi, could you please expand on this code to include: Total earnings per division (East, West, North and south); Highest and lowest per division (East, West, North and South) and total earning for the entire company. Thank you so very much! Lab12B.cpp ========= #include #include using namespace std; //program to prompt user for sales of any division in any quarter and save to binary file struct Division { char name; //values could be N, E , W or S int quarter; //values could be 1, 2, 3, 4 double sales; }; int main() { ifstream inFile("divisions.dat", ios::in | ios::binary); string ans = "y"; Division div; if(inFile.fail()) { cout << "Could not open divisions.dat for reading. Please use Lab12A to create the file" << endl; return 0; } cout << "Reading data from divisions.dat" << endl; inFile.read(reinterpret_cast(&div), sizeof(div)); while(!inFile.eof()) { cout << "Division name: " << div.name << endl; cout << "Quarter No.: " << div.quarter << endl; cout << "Sales amount: " << div.sales << endl << endl; inFile.read(reinterpret_cast(&div), sizeof(div)); } inFile.close(); }

Solutions

Expert Solution

Solution : Added code is in the bold text.

#include<iostream>
#define MAX 100000

using namespace std; //program to prompt user for sales of any division in any quarter and save to binary file
struct Division {
char name; //values could be N, E , W or S
int quarter; //values could be 1, 2, 3, 4
double sales;
};
int main()
{
//variable declaration
double totalEarnEAST=0;
double lowestEarnEAST=MAX;
double highestEarnEAST=0;
double totalEarnWEST=0;
double lowestEarnWEST=MAX;
double highestEarnWEST=0;
double totalEarnNORTH=0;
double lowestEarnNORTH=MAX;
double highestEarnNORTH=0;
double totalEarnSOUTH=0;
double lowestEarnSOUTH=MAX;
double highestEarnSOUTH=0;

ifstream inFile("divisions.dat", ios::in | ios::binary);
string ans = "y";
Division div;
if(inFile.fail())
{ cout << "Could not open divisions.dat for reading. Please use Lab12A to create the file" << endl;
return 0;
}
cout << "Reading data from divisions.dat" << endl;
inFile.read(reinterpret_cast(&div), sizeof(div));
while(!inFile.eof())
{
cout << "Division name: " << div.name << endl;
cout << "Quarter No.: " << div.quarter << endl;
cout << "Sales amount: " << div.sales << endl << endl;
//set the value total ,lowest , highest earning division wise.
switch(div.name)
{
case 'E':
totalEarnEAST+=div.sales;
if(highestEarnEAST<div.sales)
highestEarnEAST=div.sales;
if(lowestEarnEAST>div.sales)
lowestEarnEAST=div.sales;
break;
case 'W':
totalEarnWEST+=div.sales;
if(highestEarnWEST<div.sales)
highestEarnWEST=div.sales;
if(lowestEarnWESTdiv.sales)
lowestEarnWEST=div.sales;
break;
case 'N':
totalEarnEAST+=div.sales;
if(highestEarnNORTH<div.sales)
highestEarnNORTH=div.sales;
if(lowestEarnNORTH>div.sales)
lowestEarnNORTH=div.sales;
break;
case 'S':
totalEarnEAST+=div.sales;
if(highestEarnSOUTH<div.sales)
highestEarnSOUTH=div.sales;
if(lowestEarnSOUTH>div.sales)
lowestEarnSOUTH=div.sales;
break;
}

inFile.read(reinterpret_cast(&div), sizeof(div));
}
inFile.close();
//printing the values
cout<<"Total earning in EAST Division:"<<totalEarnEAST<<endl;
cout<<"Lowest earning in EAST Division:"<<lowestEarnEAST<<endl;
cout<<"Highest earning in EAST Division:"<<highestEarnEAST<<endl;
cout<<"Total earning in WEST Division:"<<totalEarnWEST<<endl;
cout<<"Lowest earning in WEST Division:"<<lowestEarnWEST<<endl;
cout<<"Highest earning in WEST Division:"<<highestEarnWEST<<endl;
cout<<"Total earning in NORTH Division:"<<totalEarnNORTH<<endl;
cout<<"Lowest earning in NORTH Division:"<<lowestEarnNORTH<<endl;
cout<<"Highest earning in NORTH Division:"<<highestEarnNORTH<<endl;
cout<<"Total earning in SOUTH Division:"<<totalEarnSOUTH<<endl;
cout<<"Lowest earning in SOUTH Division:"<<lowestEarnSOUTH<<endl;
cout<<"Highest earning in SOUTH Division:"<<highestEarnSOUTH<<endl;

}


Related Solutions

Johnny C. has two divisions. East division sells a component (L689) to West division. West then...
Johnny C. has two divisions. East division sells a component (L689) to West division. West then assembles a product, CAGE, using L689 and sells it to customers. East division incurs $50 of variable cost per unit of L689 and allocates $80 of fixed cost to each unit. East’s factory has limited space, so every unit of L689 it produces means one less unit of L690 is made. While L689 is only sold to West division, East division sells L690 to...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h>...
Hi, i need flowchart for this code (C++) please, THANX #include <iostream> #include <thread> #include <unistd.h> #include <semaphore.h> #include <pthread.h> using namespace std; #define NRO 6 // Número de coches //Puente declarado con matriz y valor entero void Puente(string array, int value); // Variable global int Norte = 1; int Sur = 1; sem_t mutex1; //Coche al norte void* NorteC(void* arg){ sem_wait(&mutex1); string array = "En el lado Norte "; // Norte cout<<array<<"del puente, el coche #"<<Norte<<" puede cruzar el...
East West Bearings Ltd wants to expand its operations in Geelong. Considering the competitive environment and...
East West Bearings Ltd wants to expand its operations in Geelong. Considering the competitive environment and macro uncertainty, East West wants to make sure that they should invest professionally so that they would not suffer either on account of profits or on account of cash flows on any project. As the sales are growing consistently, to meet the projected sales, East West wants to set up a new plant to manufacture bearings. In this regard, the director of East West...
West Company operates two divisions (Division A and Division B). TOTAL company sales = $500,000. Division...
West Company operates two divisions (Division A and Division B). TOTAL company sales = $500,000. Division A sales represent 40% of the total. Also, Division B reports the following information: Contribution margin = 45.0%; Traceable AND controllable fixed expenses = $68,000; and segment margin = 8.0%. Required: Compute Traceable NOT Controllable fixed expenses for Division B
You are the audit senior at East & West and are conducting the audit of Relaxing...
You are the audit senior at East & West and are conducting the audit of Relaxing Pool Ltd for the year ended 30 June 2018. Relaxing Pool retails spa pools and has stores across Australia. The audit assistant, John Cummins, has carried out tests of controls over payroll. An extract from his audit working papers is as follows: The tolerable rate of deviation for this test, as per the audit plan, is 5 per cent. Twenty-four employee’s pays were selected...
Hi, could you please assist with this question? You are an investment banking consultant advising a...
Hi, could you please assist with this question? You are an investment banking consultant advising a mining company. The CEO of the company tells you that she believes that capital structure does not have an impact on firm value. On what basis might they make this comment? State whether you agree or not with this position and explain why. Does the nature of this firm’s business risk change your answer? Fully explain your reasoning. Thanks kindly
Hi, could you please assist with this question? You are an investment banking consultant advising an...
Hi, could you please assist with this question? You are an investment banking consultant advising an investment company. The CEO of the company tells you that she believes that capital structure does not have an impact on firm value. On what basis might they make this comment? State whether you agree or not with this position and explain why. Does the nature of this firm’s business risk change your answer? Fully explain your reasoning.
Hi, could you provide an explantion for the following questions please in relation to the decision...
Hi, could you provide an explantion for the following questions please in relation to the decision making process. These questions are in relation to seeking assistance from other sources so that your decision regarding advice, feedback and support are the best they can be Q1 describe an example of how you sought advice as required to assist in the decision-making process? Q2 describe an example of how you sought feedback as required to assist in the decision-making process? Q3 describe...
Hi, can you please verify with the basic code of a beginner MATLAB user, and try...
Hi, can you please verify with the basic code of a beginner MATLAB user, and try explaining how to approach if possible. Thanks a lot! :) 1. Answer the following questions regarding complex numbers. You must provide all handwritten working and MATLAB code/outputs for the problems below. (a) Express the complex number w = √ 3+i in complex exponential form. (Provide a handwritten solution) (b) (1 mark) Use MATLAB to check your answer for part (a) by calculating the length...
Hi There Could you please assist on below short essay... DOMESTIC workers will no longer be...
Hi There Could you please assist on below short essay... DOMESTIC workers will no longer be subjected to meagre salaries as the government has adjusted the minimum wage for domestic workers, with effect from December last year. The announcement was made by the Department of Labour Minister Mildred Oliphant and it coincided with the signing into law of the National Minimum Wage Bill by President Cyril Ramaphosa. According to the Department of Labour’s new rates, domestic workers working in Area...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT