Question

In: Computer Science

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 of the class, display the Company Name, Quarter. Division Name, Total Sales, Total Expenses and Net Income. The company name and quarter should be displayed for all instances.

5 Points Extra Credit: Create a method in the PetFoodCompany class that will do step 6 and call it from main() for the 3 instances.

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

OUTPUT:

CODE:
#include <iostream>
#include <string>
using namespace std;


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();
void print();

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_s(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_s(company, name);
}

void PetFoodCompany::setDivision(char dname[])
{
strcpy_s(division, dname);
}

double PetFoodCompany::netIncome()
{
return (totalSales - totalExpences);
}

void PetFoodCompany::print()
{
cout << "\nCmpName : " << company;
cout << "\nQuarter : " << quart;
cout << "\nDivision : " << division;
cout << "\nT Sales : " << totalSales;
cout << "\nT Expenses : " << totalExpences;
cout << "\nNet income : " << netIncome();
}
//PetFoodMain.cpp:

#include <iostream>
#include <cstring>
#include "PetFoodComp.h"


using namespace std;

int main()
{
PetFoodCompany dogFoodMaker,catFoodMaker,fishFoodMaker;
char divName1[] = "Alpo";
dogFoodMaker.setDivision(divName1);
char divName2[] = "GloFish";
fishFoodMaker.setDivision(divName2);
char divName3[] = "Purina";
catFoodMaker.setDivision(divName3);
cout << "\nEnter Company Name is ";
string cmpName, currentQtr;
getline(cin, cmpName);
cout << "\nEnter Current Quarter is ";
getline(cin, currentQtr);

dogFoodMaker.setCompany(const_cast<char*>(cmpName.c_str()));
catFoodMaker.setCompany(const_cast<char*>(cmpName.c_str()));
fishFoodMaker.setCompany(const_cast<char*>(cmpName.c_str()));

dogFoodMaker.setQuart(currentQtr[0]);
catFoodMaker.setQuart(currentQtr[0]);
fishFoodMaker.setQuart(currentQtr[0]);

double totalSales1, totalExpenses1;
cout << "\nEnter Total Sales and total expenses for dogfoodmaker";
cin >> totalSales1 >> totalExpenses1;
dogFoodMaker.setTotalSales(totalSales1);
dogFoodMaker.setTotalExpences(totalExpenses1);
  
double totalSales2, totalExpenses2;
cout << "\nEnter Total Sales and total expenses for catfoodmaker";
cin >> totalSales2 >> totalExpenses2;
catFoodMaker.setTotalSales(totalSales2);
catFoodMaker.setTotalExpences(totalExpenses2);

double totalSales3, totalExpenses3;
cout << "\nEnter Total Sales and total expenses for fishfoodmaker";
cin >> totalSales3 >> totalExpenses3;

fishFoodMaker.setTotalSales(totalSales3);
fishFoodMaker.setTotalExpences(totalExpenses3);


dogFoodMaker.print();
catFoodMaker.print();
fishFoodMaker.print();

return 0;
}


Related Solutions

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...
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()...
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...
Question 1 Download the files Book.java and BookInfo.txt from Content->Chapter 12 Quiz Files. Create a BookDriver.java...
Question 1 Download the files Book.java and BookInfo.txt from Content->Chapter 12 Quiz Files. Create a BookDriver.java class with a main method. In the main method, create an ArrayList of Book objects, read in the information from BookInfo.txt and create Book objects to populate the ArrayList. After all data from the file is read in and the Book objects added to the ArrayList- print the contents of the ArrayList. Paste your BookDriver.java text (CtrlC to copy, CtrlV to paste) into the...
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...
Python Create Loop 1 = 1 1 + 2 = 3 1 + 2 + 3...
Python Create Loop 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 Create a loop in python that makes this pattern
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...
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2....
For this assignment you are expected to submit the following two files: 1. ????ℎ??????ℎ??????. ℎ 2. ????ℎ??????ℎ??????. ??? You are being asked to write a class for simple weather data storage. Each instance of the class will hold data for exactly one month (30 days). Each day’s weather will be classified as either rainy (‘R’), cloudy (‘C’), or sunny (‘S’). To achieve this, your class will contain a character array of length 30. The class will provide three functions to...
Refactor Assignment 1 into 3 project related files. Customer.h - Class Specification Customer.cpp - Class Implementation...
Refactor Assignment 1 into 3 project related files. Customer.h - Class Specification Customer.cpp - Class Implementation (Methods) TestCustomer.cpp - Your code that performs the logic from Assignment 1. The 3 files need to be named as listed above and should compile without errors. I am not understanding how to do this. Below is the code: #include #include using namespace std; const int NAME_SIZE = 20; const int STREET_SIZE = 30; const int CITY_SIZE = 20; const int STATE_CODE_SIZE = 3;...
Visual Basic Make a directory and copy some files from desktop to the created directory
Visual Basic Make a directory and copy some files from desktop to the created directory
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT