Question
Can someone help with this. I'll deifnitely give you credit. This is easy but I don't have time as I'm writing exams now. FOLLOW THESE
Can someone help with this. I'll deifnitely give you credit. This is easy but I don't have time as I'm writing exams now.
FOLLOW THESE STEPS. You need to do the following: 1. Add a static int member variable called objects to the student class. Initialize it to zero. Think about where it needs to be initialized. 2. Increment objects every time a new Student is created. 3. Add a destructor to Student. Make sure to decrement the number of objects before the cout statement provided. 4. Create an ENGMajor object. It should be derived from Student. It should just have a destructor and override the changePartyCount() method. The destructor should just have the provided cout statement and the changePartyCount() method should throw a PartyException (ENGMajors cant party). 5. Create a PartyException. It should be derived from exception. The body of the exception is provided. 6. Fill in the body of the saturdayNightPlans function as described. 7. Uncomment main. There are NO typos in main. 8. Make sure the program behaves as expected. You may need to make minor changes to code outside of main to get this to happen.
//Provided 12/18/17
#include
#include
#include
using namespace std;
class Student
{
public:
Student()
{
studying = 0;
partying = 0;
}
//Add static member variable here; don't forget to initialize it somewhere...
int studying;
int partying;
void changeStudyCount()
{
studying++;
}
void changePartyCount()
{
partying++;
}
//Add destructor here
//Output for the destructor
//cout << "Student deleted. " << objects << " objects left." << endl;
};
//Put PartyException here. It needs to be derived from exception.
//This is the body. You just need to wrap it in the definition header
/*
public:
Student *sPtr;
PartyException(Student *s)
{
cout << this->what() << ": ";
sPtr = s;
}
*/
//Add ENGMajor here
//Put this in the destructor: cout << "ENGMajor deleted. " << objects << " objects left." << endl;
//changePartyCount() should just throw a PartyException(this)
//DON'T MODIFY
void party(Student *s)
{
s->changePartyCount();
cout << typeid(s).name() << " was partying" << endl;
return;
}
//DON'T MODIFY
void study(Student *s)
{
s->changeStudyCount();
cout << typeid(s).name() << " was studying" << endl;
return;
}
void saturdayNightPlans(Student *s)
{
//Don't change the cout
cout << "Saturday night plans: ";
/*
If the argument to the function is a Student you should use that as the argument to the party method
If the argument to the function is a ENGMajor you should use that as the argument to the study method
*/
return;
}
int main()
{
cout << "Q3 running..." << endl;
//NO TYPOS - make sure this works
/*
Student *s = new Student();
ENGMajor *e = new ENGMajor();
saturdayNightPlans(s);
saturdayNightPlans(e);
cout << "Later in the week: ";
try{
party(s);
party(e);
}
catch (PartyException ex)
{
cout << typeid((*ex.sPtr)).name() << " can't party. Too much work to do!" << endl;
}
cout << "Party Count #1 = " << s->partying << endl;
cout << "Party Count #2 = " << e->partying << endl;
cout << "Study Count #1 = " << s->studying << endl;
cout << "Study Count #2 = " << e->studying << endl;
s=e;
delete s;
*/
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started