Question

In: Computer Science

1. Copy the files from Assignment 1 to Assignment 3. 2. Modify the PetFoodCompany header to...

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

Solutions

Expert Solution

//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


Related Solutions

1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3...
1. Copy the files from Assignment 1 to Assignment 2. Relabel as necessary 2. Create 3 instances of the PetFoodCompany class - dogFoodMaker, catFoodMaker, fishFoodMaker. 3. Internally set the division name for each instance. (I.E. "Alpo" for dogFoorMaker, "Purina" for CatFoodMaker, "GloFish" for fishFoodMater) 4. Prompt me to enter the Company Name and Quarter only once. 5. For each of the above instances, prompt me for total sales and total expenses. A loop is not expected. 6. For each instance...
You are to modify your payroll program from the last assignment to take the new copy...
You are to modify your payroll program from the last assignment to take the new copy of the payroll file called DeweyCheatemAndHow.txt which has the fields separated by a comma to use as input to your program and produce a file that lists all the salaried employee and their gross pay, then each hourly employee and their gross pay and finally each piece rate employee and their gross pay . You are to process all the entries provided in the...
In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A...
In this programming assignment, you need to create 3 files. 1. DateType.h 2. DateType.cpp 3. A test driver for testing the class defined in the other 2 files. You can name your file in the way you like. Remember it must be a .cpp file. In DateType.h file, type these lines: // To declare a class for the Date ADT // This is the header file DateType.h class DateType { public: void Initialize(int newMonth, int newDay, int newYear); int GetYear()...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are...
C++ question. Need all cpp and header files. Part 1 - Polymorphism problem 3-1 You are going to build a C++ program which runs a single game of Rock, Paper, Scissors. Two players (a human player and a computer player) will compete and individually choose Rock, Paper, or Scissors. They will then simultaneously declare their choices and the winner is determined by comparing the players’ choices. Rock beats Scissors. Scissors beats Paper. Paper beats Rock. The learning objectives of this...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify the parent class (Plant) by adding the following abstract methods: a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify...
Problem Write in drjava is fine. Using the classes from Assignment #2, do the following: Modify the parent class (Plant) by adding the following abstract methods: a method to return the botanical (Latin) name of the plant a method that describes how the plant is used by humans (as food, to build houses, etc) Add a Vegetable class with a flavor variable (sweet, salty, tart, etc) and 2 methods that return the following information: list 2 dishes (meals) that the...
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and...
Modify programming problem 4 from Assignment 2. You will create a number of threads—for example, 100—and each thread will request a pid, sleep for a random period of time, and then release the pid. (Sleeping for a random period of time approximates the typical pid usage in which a pid is assigned to a new process, the process executes and then terminates, and the pid is released on the process's termination.) On UNIX and Linux systems, sleeping is accomplished through...
Assignment 3 Note: Tables referred in this assignment are same as that of Assignment 2. 1....
Assignment 3 Note: Tables referred in this assignment are same as that of Assignment 2. 1. For each table, append your student id along with the table name. For e.g. employee_student id (employee_T16363737) 2. Format for questions: a. Question: b. SQL statement solution c. Screenshot for correct input d. Screenshot for violation (if any) Q1) Check the structure of tables. Q2) Check the constraint name for applied constraints? Q3) Drop the unique constraint on ENAME Q4) Drop the Foreign Key...
What are the UNIX commands for each of these steps? 1. Copy all of the files...
What are the UNIX commands for each of these steps? 1. Copy all of the files in your Files directory to the Backup directory. 2. Create an ITE130 directory in the Classes Directory 3. Move all the ITE 130 files from the backup directory to the ITE130 directory. 4. Redirect echo step 19 to mark this step in the lab3.txt file 5. Display all of the directories and sub-directories including files so I can verify you completed all the above...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT