Question

In: Computer Science

language is C++ 1. Design a class that manages a Pet Food Company's quarterly summarized activity....

language is C++

1. Design a class that manages a Pet Food Company's quarterly summarized activity. It should contain the following:

( This is all private data )

Company Name - char[40]   //  This is a static member 
Quarter              - char         // This is a static member.  Validate to be 1-4 in the setter method

Division Name - char[40]

BonusBudgetRate - float   - set to 0.02
Total Sales        - float
Total Expenses - float

1a. Create a public method named netIncome() which will return total sales - total expenses as float.

 

2. Create public class methods (Setters and Getters) that load the data values.

3. Do not create getter/setter methods for the BonusBudgetRate item. It can be set in a constructor or initialized to the default value of 0.02. There is no other reference to it.

4. This class needs a header file and a corresponding cpp file.

5. Create a 'driver' program that contains the main() method and includes the header file for PetFoodCompany class.

   In the driver program, create an instance of the object PetFoodCompany. 
   Internally set the Quarter to 1 and the CompanyName to a name of your choosing.
   Display the CompanyName and Quarter values
   Prompt for total sales and total expenses for this object
   Display the result of netIncome(). 

Below is an example:

 
Company Name is myCompanyName
Current Quarter is 1

Enter Total Sales: 1000

Enter Total Expenses: 600
Net Income = 400

The deliverable is a working program (CPPs & H files) and a UML diagram of the this class.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

UML Diagram:

==========================================
// PetFoodCompany.h

#ifndef PETFOODCOMPANY_H
#define PETFOODCOMPANY_H

class PetFoodCompany
{
public:
PetFoodCompany();
  
       char getQuarter();

       void setQuarter(char quarter);

       float getTotalSales();

       void setTotalSales(float totalSales);

       float getTotalExpences();
       void setTotalExpences(float totalExpences);
double netIncome();
char * getCompanyName();
void setCompanyName(char name[]);
char * getDivisionName();
void setDivisionName(char dname[]);
  
  
private:
// Declaring variables
char companyName[40];
static char quarter;
char divisionName[40];
static double BonusBudgetRate;
float totalSales;
float totalExpences;
};
#endif

=========================================

=========================================

#include <iostream>
#include <cstring>
using namespace std;
#include "PetFoodCompany.h"

double PetFoodCompany::BonusBudgetRate = 0.02;
char PetFoodCompany::quarter = '1';

PetFoodCompany::PetFoodCompany()
{
strcpy(companyName, "myCompanyName");
}
char PetFoodCompany::getQuarter()
{
return quarter;
}

void PetFoodCompany::setQuarter(char quarter)
{
if (quarter == '1' || quarter == '2' || quarter == '3' || quarter == '4')
this->quarter = quarter;
}

float PetFoodCompany::getTotalSales()
{
return totalSales;
}

void PetFoodCompany::setTotalSales(float totalSales)
{
this->totalSales = totalSales;
}

float PetFoodCompany::getTotalExpences()
{
return totalExpences;
}
void PetFoodCompany::setTotalExpences(float totalExpences)
{
this->totalExpences = totalExpences;
}
char* PetFoodCompany::getCompanyName()
{
return companyName;
}
void PetFoodCompany::setCompanyName(char name[])
{
strcpy(companyName, name);
}
char* PetFoodCompany::getDivisionName()
{
return divisionName;
}
void PetFoodCompany::setDivisionName(char dname[])
{
strcpy(this->divisionName, dname);
}

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

=========================================

=========================================

// main.cpp

#include <iostream>
#include <cstring>
using namespace std;
#include "PetFoodCompany.h"
int main()
{
double totalSales,totExpences;
PetFoodCompany pfc;
cout<<"Company Name is "<<pfc.getCompanyName()<<endl;
cout<<"Current Quarter is "<<pfc.getQuarter()<<endl;
  
  
cout<<"Enter Total Sales: ";
cin>>totalSales;
cout<<"Enter Total Expences: ";
cin>>totExpences;

pfc.setTotalExpences(totExpences);
pfc.setTotalSales(totalSales);
  
cout<<"Net Income :"<<pfc.netIncome()<<endl;
  
return 0;
}

=========================================

======================================

Output:

=====================Could you plz rate me well.Thank You


Related Solutions

Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the...
Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the following fields: • name: The name field holds the name of a pet. • type: The type field holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”. • age: The age field holds the pet’s age. The Pet class should also have the following methods: • setName: The setName method stores a value in the name field....
You has been requested to design and develop a food ordering system in C++ language based...
You has been requested to design and develop a food ordering system in C++ language based on following requirements: The system shall allow the user to place an order for the food(s), view the food details, modify or delete the details of the food if necessary. Your program should be menu driven, giving the user various choices. You shall design the system by demonstrating the full understanding of object-oriented and use of list/link-list concept. For every food order, the following...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class...
IN C++!!! Exercise #1: Design and implement class Rectangle to represent a rectangle object. The class defines the following attributes (variables) and methods: Two Class variables of type double named height and width to represent the height and width of the rectangle. Set their default values to 0 in the default constructor. A non-argument constructor method to create a default rectangle. Another constructor method to create a rectangle with user-specified height and width. Method getArea() that returns the area. Method...
PUT IN JAVA PROGRAMMING LANGUAGE The Rectangle class: Design a class named Rectangle to represent a...
PUT IN JAVA PROGRAMMING LANGUAGE The Rectangle class: Design a class named Rectangle to represent a rectangle. The class contains: • Two double data fields named width and height that specify the width and height of a rectangle. The default values are 1 for both width and height. • A no-arg (default) constructor that creates a default rectangle. • A constructor that creates a rectangle with the specified width and height. • A method named findArea() that finds the area...
Design a class named Pet, which should have the following fields: Name – The name field...
Design a class named Pet, which should have the following fields: Name – The name field holds the name of a pet. Type – The type field holds the type of animal that is the pet. Example values are “Dog”, “Cat”, and “Bird”. Age – The age field holds the pet’s age. The Pet class should also have the following methods: setName – The setName method stores a value in the name field. setType – The setType method stores a...
In C++ Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private:...
In C++ Design an Essay class that is derived from the GradedActivity class: class GradedActivity{ private: double score; public: GradedActivity() {score = 0.0;} GradedActivity(double s) {score = s;} void setScore(double s) {score = s;} double getScore() const {return score;} char getLetterGrade() const; }; char GradedActivity::getLetterGrade() const{ char letterGrade; if (score > 89) { letterGrade = 'A'; } else if (score > 79) { letterGrade = 'B'; } else if (score > 69) { letterGrade = 'C'; } else if (score...
Write a java program using the information given Design a class named Pet, which should have...
Write a java program using the information given Design a class named Pet, which should have the following fields (i.e. instance variables):  name - The name field holds the name of a pet (a String type)  type - The type field holds the type of animal that a pet is (a String type). Example values are “Dog”, “Cat”, and “Bird”.  age - The age field holds the pet’s age (an int type) Include accessor methods (i.e. get...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
Class object in C++ programming language description about lesson base class and derived class example.
Class object in C++ programming language description about lesson base class and derived class example.
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to...
program language: JAVA For this project, you get to design and write a WeightedCourseGrade class to keep track of a student's current grade. You also get to design and write WeightedCourseGradeDriver class that requests input from the user and interacts with the WeightedCourseGrade class. Your WeightedCourseGrade class should store the following information: Weighted subtotal (the sum of all of the categories multiplied by the grade category weight) Total category weights (the sum of all the grade category weights) Provide the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT