In: Computer Science
A) csc 401 c++
Write a class CorpData to store the following information on a company division:
a. Division name (such as East, West, North, or South)
b. First quarter sales c. Second quarter sales d. Third quarter sales e. Fourth quarter sales Include a constructor that allows the division name and four quarterly sales amounts to be specified at the time a CorpData object is created. The program should create four CorpData objects, each representing one of the following corporate divisions: East, West, North, and South. These objects should be passed one at a time, to a function that computes the division's annual sales total and quarterly average, and displays these along with the division name.
Hi,
Hope you doing fine. I have coded the above question in C++ keeping all the conditions in mind. The logic of the code is pretty straight forward and it is clearly explained using comments that have been highlighted in bold, Also find the coode snippet and the sample output to get a clearer picture.
Program:
#include<iostream>
using namespace std;
//declaring class
class CorpData{
//declaring class attributes
public:
string name;
double firstquarter;
double secondquarter;
double thirdquarter;
double fourthquarter;
//creating parameterized
constructor
public:
CorpData(string division,double
first,double second,double third,double fourth){
//assigning values to each attribute of class.
name=division;
firstquarter=first;
secondquarter=second;
thirdquarter=third;
fourthquarter=fourth;
}
};
//function to display the division name, total sales and
average sales per quarter
void displaySales(CorpData data)
{
double total,avg;
//calculating totaal sales
total=data.firstquarter+data.secondquarter+data.thirdquarter+data.fourthquarter;
//calculating average quarterly
sale
avg=total/4;
//printing output
cout << "Division name:
"<<data.name<<"\n";
cout <<"Annual sales total:
"<<total<<"\n";
cout <<"Quarterly average:
"<<avg<<"\n\n";
}
//main function
int main()
{
//creating 4 object sof class CorpData using
the parameterized constructor
CorpData obj1("East",100,200,300,400);
CorpData obj2("West",150,20,30,40);
CorpData obj3("North",85,250,100,125);
CorpData obj4("South",500,200,500,400);
//calling displaySales() for each object to
display results
displaySales(obj1);
displaySales(obj2);
displaySales(obj3);
displaySales(obj4);
}
Executable code snippet:
Output: