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, please could someone be of assistance with this assignment for me. Thank you The objective...
Hi, please could someone be of assistance with this assignment for me. Thank you The objective of this assignment is to practice the use of control objects in GUI design. You are required to create a 4- function calculator. See pic below. Calculator.png The calculator should have buttons for all 10 numbers, the decimal point, the four operations (+,-,/,*), an equal “=” button, a "main display" (TextBox or RichTextBot), a backspace button and a clear “C” button. When you create...
Please write this code in C++, also if you could please bold the names of the...
Please write this code in C++, also if you could please bold the names of the input files and provide comments for each choice. For this part, the program gives the user 4 choices for encrypting (or decrypting) the first character of a file. Non-lowercase characters are simply echoed. The encryption is only performed on lowercase characters. If c is char variable, then islower(c) will return true if c contains an lowercase character, false otherwise To read a single character...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT