Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ This is my program and works well. Can you check if I met these parameters:

ID: 3580959 • Letter: C

Question

c++

This is my program and works well. Can you check if I met these parameters:

5 points         main has sufficient comments to explain what is being done.

10 points         every function has specifications.

5 points         A header file contains the class definition.

5 points         A cpp file contains the functions definitions/implementations.

5 points         The #ifndef guard is properly used where necessary.

10 points         a constructor and destructor are defined and do what they supposed to.

5 points         a static variable accumulates the sales for all regions.

5 points         All accessor member functions are constant.

5 points         an array of objects is declared in main and calls a function to read the data for each of the regions.

20 points         Program runs efficiently, correctly and performs the specified task.

10 points         Structure of the program (neatness, spacing, indentation, use of variables, organization)

Additional 30 points if at the end, the total of each quarter for the regions is printed by accessing a member function to accumulate the quarters (may require another static variable if you wish).

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 ;
}

Explanation / Answer

Yes

//----------------------------------------------------------------------------------------------------------------------------

#ifndef CODE_H
#define CODE_H
#include <iostream>
using namespace std;

class DivSales{
public:
string region;
int quarters [4];
double yearlySale;
static double allregtot;
DivSales();
~DivSales();
void getValues();
string getRegion();
double getquatsale(int);
double getyearlysale();
double gettotsale();
};

DivSales::DivSales(){ // constructor for class DivSales
region = "";
yearlySale = 0;
allregtot = 0;
for(int i=0; i<4; i++){ quarters[i]=0; }
}

DivSales::~DivSales(){ // destructor for class DivSales
}

// method to input quarterly values for a region
void DivSales::getValues() const {
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;
}

// Method to get region name
string DivSales::getRegion(){
return region;
}

// Method to get quaterly sale of a region
double DivSales::getquatsale (int index) const {
return quarters[index];
}

// Method to get yearly sale of a region
double DivSales::getyearlysale() const {
return yearlySale;
}

// Method to get total sales
double DivSales::gettotsale() const {
return allregtot;
}
#endif

//------------------------------------------------------------------------------------------------

#include<iostream>
#include<string>
#include<cstdlib>
#include<iomanip>
#include "code.h"
using namespace std;

/*
This program is to get the quarterly sales of different
regions from the user and store them. The program also
calculates the yearly cumulative sales for each
region.
*/

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 ;
}

5 points         main has sufficient comments to explain what is being done. Added 10 points         every function has specifications. Added 5 points         A header file contains the class definition. Yes 5 points         A cpp file contains the functions definitions/implementations. No. Move the implementations from the header file to the .cpp file 5 points         The #ifndef guard is properly used where necessary. Yes 10 points         a constructor and destructor are defined and do what they supposed to. Yes 5 points         a static variable accumulates the sales for all regions. No. Make allregtot as static 5 points         All accessor member functions are constant. No. Added 5 points         an array of objects is declared in main and calls a function to read the data for each of the regions. Yes 20 points         Program runs efficiently, correctly and performs the specified task. Yes 10 points         Structure of the program (neatness, spacing, indentation, use of variables, organization) Yes Additional 30 points if at the end, the total of each quarter for the regions is printed by accessing a member function to accumulate the quarters

Yes

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote