In: Computer Science
1. Copy the files from Assignment 1 to Assignment 3.
2. Modify the PetFoodCompany header to mention a friend function called "computeBonusBudget". This method should compute the bonus budget as netIncome() * BonusBudgetRate and this method should exist in the driver program - not the Class defintion.
3. Modify the output of the program to display the results of the computeBonusBudget.
Enter Total Sales: 1000
Enter Total Expenses: 600 Net Income = 400 Bonus Budget = 8
Here is the code:
PetFoodComp.h:
class PetFoodCompany
{
public:
PetFoodCompany();
char getQuart();
char* getCompany();
char* getDivision();
void setQuart(char quart);
void setTotalSales(float totalSales1);
void setTotalExpences(float totalExpences1);
void setCompany(char name[]);
void setDivision(char name1[]);
float getTotalSales();
float getTotalExpences();
double netIncome();
private:
char company[40];
char division[40];
static char quart;
static double BonusRate;
float totalSales;
float totalExpences;
};
PetFood.cpp:
#include <iostream>
#include <cstring>
#include "PetFoodComp.h"
using namespace std;
double PetFoodCompany::BonusRate = 0.02;
char PetFoodCompany::quart = '1';
PetFoodCompany::PetFoodCompany()
{
strcpy(company, "myCompanyName");
}
char PetFoodCompany::getQuart()
{
return quart;
}
float PetFoodCompany::getTotalSales()
{
return totalSales;
}
float PetFoodCompany::getTotalExpences()
{
return totalExpences;
}
char* PetFoodCompany::getCompany()
{
return company;
}
char* PetFoodCompany::getDivision()
{
return division;
}
void PetFoodCompany::setQuart(char quart1)
{
if (quart1 == '1' || quart1 == '2' || quart1 == '3' ||
quart1 == '4')
quart = quart1;
}
void PetFoodCompany::setTotalSales(float totalSales1)
{
totalSales = totalSales1;
}
void PetFoodCompany::setTotalExpences(float
totalExpences1)
{
totalExpences = totalExpences1;
}
void PetFoodCompany::setCompany(char name[])
{
strcpy(company, name);
}
void PetFoodCompany::setDivision(char dname[])
{
strcpy(division, dname);
}
double PetFoodCompany::netIncome()
{
return (totalSales - totalExpences);
}
PetFoodMain.cpp:
#include <iostream>
#include <cstring>
#include "PetFoodComp.h"
using namespace std;
int main()
{
double totalSales, totalExpences;
PetFoodCompany pet;
cout << "Company Name is " <<
pet.getCompany() << "\n";
cout << "Current Quarter is " <<
pet.getQuart() << "\n";
cout << "Enter Total Sales: ";
cin >> totalSales;
cout << "Enter Total Expences: ";
cin >> totalExpences;
pet.setTotalExpences(totalExpences);
pet.setTotalSales(totalSales);
cout << "Net Income: " << pet.netIncome() << "\n";
return 0;
}
//PetFoodComp.h:
class PetFoodCompany
{
public:
PetFoodCompany();
char getQuart();
char* getCompany();
char* getDivision();
void setQuart(char quart);
void setTotalSales(float totalSales1);
void setTotalExpences(float totalExpences1);
void setCompany(char name[]);
void setDivision(char name1[]);
friend float computeBonusBudget(PetFoodCompany pet);
float getTotalSales();
float getTotalExpences();
double netIncome();
private:
char company[40];
char division[40];
static char quart;
static double BonusRate;
float totalSales;
float totalExpences;
};
//PetFood.cpp:
#include <iostream>
#include <cstring>
#include "PetFoodComp.h"
using namespace std;
double PetFoodCompany::BonusRate = 0.02;
char PetFoodCompany::quart = '1';
PetFoodCompany::PetFoodCompany()
{
strcpy(company, "myCompanyName");
}
char PetFoodCompany::getQuart()
{
return quart;
}
float PetFoodCompany::getTotalSales()
{
return totalSales;
}
float PetFoodCompany::getTotalExpences()
{
return totalExpences;
}
char* PetFoodCompany::getCompany()
{
return company;
}
char* PetFoodCompany::getDivision()
{
return division;
}
void PetFoodCompany::setQuart(char quart1)
{
if (quart1 == '1' || quart1 == '2' || quart1 == '3' ||
quart1 == '4')
quart = quart1;
}
void PetFoodCompany::setTotalSales(float totalSales1)
{
totalSales = totalSales1;
}
void PetFoodCompany::setTotalExpences(float
totalExpences1)
{
totalExpences = totalExpences1;
}
void PetFoodCompany::setCompany(char name[])
{
strcpy(company, name);
}
void PetFoodCompany::setDivision(char dname[])
{
strcpy(division, dname);
}
double PetFoodCompany::netIncome()
{
return (totalSales - totalExpences);
}
float computeBonusBudget(PetFoodCompany pet)
{
return (pet.netIncome() *
PetFoodCompany::BonusRate);
}
//PetFoodMain.cpp:
#include <iostream>
#include <cstring>
#include "PetFoodComp.h"
using namespace std;
int main()
{
double totalSales, totalExpences;
PetFoodCompany pet;
cout << "Company Name is " <<
pet.getCompany() << "\n";
cout << "Current Quarter is " <<
pet.getQuart() << "\n";
cout << "Enter Total Sales: ";
cin >> totalSales;
cout << "Enter Total Expences: ";
cin >> totalExpences;
pet.setTotalExpences(totalExpences);
pet.setTotalSales(totalSales);
cout << "Net Income: " <<
pet.netIncome() << "\n";
cout<<"computeBonusBudget:
"<<computeBonusBudget(pet)<<endl;
return 0;
}
comment:-Please like the solution. if you have any doubt in solution please comment
i will resolve your Query