Hi, these are my codes and, it works well. Please, I need help with the comments
ID: 3581010 • Letter: H
Question
Hi, these are my codes and, it works well. Please, I need help with the comments in this program such as main has sufficient comments to explain what is being done, every function has specifications.
Program specification:
A corporation has four regions, each responsible for sales to a different geographic location. Design a DivSales class that keeps sales data for a division, with the following members:
A data member that holds the region name, possible values are (“East”, “West”, ”North”, “South”).
An array with four elements for holding four quarters of sales figures for the region.
A private static variable for holding the total corporate sales for all divisions for the entire year.
A constructor that initializes the name to null “”, and the quarters to 0;
A null destructor.
A member function that prompts the user to enter the region name and sales for four quarters for that region. The value entered should be added to the static variable that holds the yearly corporate sales.
A member function that returns the region name.
A function that takes an integer argument with the range 0 to 3. The argument is to be used as a subscript into the regions quarterly sales array. The function should return the value of the array element with that subscript.
A member function that returns the total sales for any given region.
A member function that returns the total sale for all regions.
this are my codes:
//code.h:
#ifndef CODE_H
#define CODE_H
#include <iostream>
using namespace std;
class DivSales{
public:
string region;
int quarters [4];
double yearlySale;
double allregtot;
DivSales();
~DivSales();
void getValues();
string getRegion();
double getquatsale(int);
double getyearlysale();
double gettotsale();
};
DivSales::DivSales(){
region = "";
yearlySale = 0;
allregtot = 0;
for(int i=0; i<4; i++){ quarters[i]=0; }
}
DivSales::~DivSales(){
}
void DivSales::getValues(){
cout<<" Enter Region: ";
cin>>region;
for(int i = 0; i<4;i++)
{
cout<<setw(15)<<" Quarter "<<i+1<< ": ";
cin>> quarters[i];
yearlySale = yearlySale + quarters[i];
}
allregtot = allregtot + yearlySale;
}
string DivSales::getRegion(){
return region;
}
double DivSales::getquatsale(int index){
return quarters[index];
}
double DivSales::getyearlysale(){
return yearlySale;
}
double DivSales::gettotsale(){
return allregtot;
}
#endif
----------------------------------------------------------
//code cpp.
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include "code.h"
using namespace std;
int main(){
DivSales obj[4];
int allregquat [4];
int tot=0;
cout<<setiosflags(ios::fixed|ios::showpoint); // using stream manipulator
cout<<setprecision(2); // to control output displays
for (int i =0; i<4; i++)
{
obj[i].getValues();
}
cout<<" ----------------------- ";
for(int i=0; i<4; i++)
{
cout<<" "<<obj[i].getRegion();
for(int j=0; j<4; j++)
{
cout<<" Quarter "<<j+1<< ": "<<
obj[i].quarters[j];
}
cout<<" ";
cout<<" Region's total: "<<obj[i].yearlySale;
cout<<" ";
}
for(int i =0; i<4; i++)
{
tot= tot+ obj[i].gettotsale();
}
cout<<" ";
cout<<" All Regions Total: "<< tot;
for(int i=0; i<4; i++)
{
allregquat[i]=0;
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
allregquat[i]=allregquat[i]+ obj[j].quarters[i];
}
}
cout<<" ";
cout<<" Extra work: ";
for(int i=0; i<4; i++)
{
cout<<" ALL regiongs Quarter"<<i+1<<" : "<<
allregquat[i];
}
cout<<" ";
system("pause");
return 0 ;
}
I only need help with the comments.
thanks u
Explanation / Answer
#ifndef CODE_H
#define CODE_H
#include <iostream>
using namespace std;
class DivSales{ // this is DivSales class
public:
string region;// these are member variables
int quarters [4];
double yearlySale;
double allregtot;
DivSales();// divsales default constructer
~DivSales();// divsales default disstructer
// method declarations in Divsales class
void getValues();// getValues method
string getRegion();// getRegion() method
double getquatsale(int);// sales method
double getyearlysale();
double gettotsale();
};
// default values for divsales
DivSales::DivSales(){
region = "";
yearlySale = 0;
allregtot = 0;
for(int i=0; i<4; i++){ quarters[i]=0; }
}
// here calling the distructor
DivSales::~DivSales(){
}
// implementing getValues method
void DivSales::getValues(){
cout<<" Enter Region: ";// user promt
cin>>region;// getting resion
for(int i = 0; i<4;i++)// it runs for 4 quarter
{
cout<<setw(15)<<" Quarter "<<i+1<< ": ";// printing quarter number with setwidth
cin>> quarters[i];// entered values are storing into quarters array with respective indexes
yearlySale = yearlySale + quarters[i];// adding quarters into yearlySale and setting new yearlySale
}
allregtot = allregtot + yearlySale;//
}
// getting reagion and returning region
string DivSales::getRegion(){
return region;
}
// getting quarter sale for this method passing index as variable
double DivSales::getquatsale(int index){
return quarters[index];// returning quarter with respective to index positoin
}
// getting yearlysale and returning yearlysale
double DivSales::getyearlysale(){
return yearlySale;
}
// getting total sale and returning it
double DivSales::gettotsale(){
return allregtot;
}
#endif
----------------------------------------------------------
//code cpp.
#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include "code.h"
using namespace std;
int main(){
DivSales obj[4];
int allregquat [4];
int tot=0;
cout<<setiosflags(ios::fixed|ios::showpoint); // using stream manipulator
cout<<setprecision(2); // to control output displays
for (int i =0; i<4; i++)
{
obj[i].getValues();// calling getValues method from code.h
}
cout<<" ----------------------- ";
for(int i=0; i<4; i++)
{
cout<<" "<<obj[i].getRegion();// calling getRegion method getting Region()
for(int j=0; j<4; j++)
{
cout<<" Quarter "<<j+1<< ": "<<
obj[i].quarters[j];
}
cout<<" ";
cout<<" Region's total: "<<obj[i].yearlySale;// getting yearlysale from obj array
cout<<" ";
}
for(int i =0; i<4; i++)
{
tot= tot+ obj[i].gettotsale();// here adding values to total total sale
}
cout<<" ";
cout<<" All Regions Total: "<< tot; // printing total sale
for(int i=0; i<4; i++)
{
allregquat[i]=0; // setting all values in an array to zero
}
for(int i=0; i<4; i++)
{
for(int j=0; j<4; j++)
{
allregquat[i]=allregquat[i]+ obj[j].quarters[i];
}
}
cout<<" ";
cout<<" Extra work: ";
for(int i=0; i<4; i++)
{
cout<<" ALL regiongs Quarter"<<i+1<<" : "<<
allregquat[i];// here displaying all regions quarters total
}
cout<<" ";
system("pause");// pauses system to watch results
return 0 ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.