Can someone please assist me with my homework questions (Class and Derived Class
ID: 3839605 • Letter: C
Question
Can someone please assist me with my homework questions
(Class and Derived Class) Create a class called 'Enterprize' it has one private member variable called 'category' (of character type, its value is either 'F' (for food), or 'C' (for clothing), or 'H' (for housing)). This class should have constructor and accessor functions Create a derived class (of Enterprize) called "not_for_profit' having one private member variable called 'sponsor' (of character type, its value is P (for private), or 'G' (for government)). This derived class should also have constructor and accessor functions. Create another derived class (of Enterprize) called 'for_profit' having one private member variable called "revenue" (of integer type). This derived class should also have constructor and accessor functions. Define all the functions (no need of default constructors). In the main function, declare one object (called Salvation_army) of class 'not_for_profit' that has private sponsor and deals with clothing Declare another object (called HEB) of class 'for profit' that has $1M revenue and deals with food. Write statements to check if Salvation_army and HEB are in the same category of Enterprize or not (food, clothing, or housing) and print appropriate messages (Friend function & Operator overloading) Write a friend function called 'equal' for the class Enterprize' that was created above. The function takes two objects of this class and compares their categories. It returns a (true) Boolean value if they are equal. Write only the function declaration and the function definition (do not write the class definition again). In the main function, write statements to compare the categories of Salvation_army and HEB using the friend function 'equal' and print appropriate messages Overload the '=='operator for the class "Enterprize' that was created above. It should carry out exactly the same steps as that of the 'equal' function above. Write only the function declaration and the function definition. In the main function, write statements to compare the categories of Salvation_army and HEB using the overloaded operator '=='and to print appropriate messages.Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
class Enterprize{
private:
char category;
public:
Enterprize(char c){
category = c;
}
char getCategory(){
return category;
}
void setCategory(char c){
category = c;
}
friend bool equal(Enterprize ent1,Enterprize ent2){
if(ent1.getCategory() == ent2.getCategory())
return true;
return false;
}
friend bool operator==( Enterprize c1, Enterprize c2){
if(c2.getCategory() == c1.getCategory())
return true;
return false;
}
};
class NotForProfit:public Enterprize
{
private :
char sponsor;
public:
NotForProfit(char c,char s)
:Enterprize(c)
{
sponsor = s;
}
char getSponsor(){
return sponsor;
}
void setSponsor(char s){
sponsor = s;
}
};
class ForProfit : public Enterprize
{
private:
int revenu;
public :
ForProfit(char c,int r)
:Enterprize(c)
{
revenu = r;
}
char getRevenu(){
return revenu;
}
void setRevenu(int r){
revenu = r;
}
};
int main(){
NotForProfit Salvation_army('C','P');
ForProfit HEB('F',1);
if(Salvation_army.getCategory() == HEB.getCategory()){
cout <<"Same Category"<<endl;
}
else{
cout <<"Not Same Category"<<endl;
}
return 0;
}