Answer to Question #55354 in C++ for jjkkl
Question #55354
Write a program that uses a structure named CorpData to store the following information
on a company division:
Division name (such as East, West, North, or South)
First quarter sales
Second quarter sales
Third quarter sales
Fourth quarter sales
Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData variable is created.
The program should create four CorpData variables, each representing one of the
following corporate divisions: East, West, North, and South. These variables should be
passed one at a time, as constant references, to a function that computes the division’s
annual sales total and quarterly average, and displays these along with the division name.
on a company division:
Division name (such as East, West, North, or South)
First quarter sales
Second quarter sales
Third quarter sales
Fourth quarter sales
Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData variable is created.
The program should create four CorpData variables, each representing one of the
following corporate divisions: East, West, North, and South. These variables should be
passed one at a time, as constant references, to a function that computes the division’s
annual sales total and quarterly average, and displays these along with the division name.
Expert's answer
Answer on Question#55354 — Programming — C++
#include <iostream>
using namespace std;
struct CorpData {
CorpData(const char *n, double f, double s, double t, double fo)
:name(n),first(f),second(s),third(t),fourth(fo){}
const char *name;
double first;
double second;
double third;
double fourth;
};
void function(const struct CorpData &item) {
double total;
double average;
total=item.first+item.second+item.third+item.fourth;
average=total/4;
cout<<"Name: "<<item.name<<"\t Average: "
<<average<<"\t Total: "<<total<<endl;
}
int main() {
struct CorpData East("East",100,200,150,300);
struct CorpData West("West",200,130,180,400);
struct CorpData South("South",80,100,500,200);
struct CorpData North("North",400,100,30,900);
function(East);
function(West);
function(South);
function(North);
return 0;
#include <iostream>
using namespace std;
struct CorpData {
CorpData(const char *n, double f, double s, double t, double fo)
:name(n),first(f),second(s),third(t),fourth(fo){}
const char *name;
double first;
double second;
double third;
double fourth;
};
void function(const struct CorpData &item) {
double total;
double average;
total=item.first+item.second+item.third+item.fourth;
average=total/4;
cout<<"Name: "<<item.name<<"\t Average: "
<<average<<"\t Total: "<<total<<endl;
}
int main() {
struct CorpData East("East",100,200,150,300);
struct CorpData West("West",200,130,180,400);
struct CorpData South("South",80,100,500,200);
struct CorpData North("North",400,100,30,900);
function(East);
function(West);
function(South);
function(North);
return 0;
Need a fast expert's response?
Submit orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment