I am creating a program with at least two classes, a base class and a derived class and that includes the following:
a composite object
an example of inheritance
at least one virtual and at least one pure virtual function
at least one overloaded function
at least one example of pointers as covered this week in class
at least one example of dynamic memory allocation as covered this week in class
My code is attached and it is a mess! The fireQuestion function is written but not called. I'm not sure how to implement this. Can someone help me unscramble this mess? I also know that it is a silly concept with the students and all but was trying to do something different.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
class Student //base class
{
public:
Student(); //Default constructor
Student(int); // Overloaded constructor
virtual ~Student(); //virtual destructor
string getName(string);
void fireQuestion(string,int, double, int, int, int);
virtual void talk() = 0; //pure virtual function
virtual void raiseHand() = 0; //virtual function
protected:
int questionsAsked;
int onSubject;
int offSubject;
double onSubjPercent;
string name;
int brains;
};
Student::Student()
{
questionsAsked = 0;
onSubject = 0;
offSubject = 0;
onSubjPercent = 0.0;
name = "Average Student";
brains = 0;
}
Student::Student(int greyMatter)
{
if (greyMatter >= 0)
{
brains = greyMatter;
}
}
void Student::fireQuestion(string nam,int brains, double onSubjPercent,
int onSubject, int offSubject, int questFired)
{
nam = name;
brains--;
questFired = onSubject + offSubject;
onSubjPercent = onSubject / questFired;
offSubject = questFired - onSubject;
cout << "Questions: " << questFired << endl;
cout << "Questions on subject %: " << onSubjPercent << endl;
}
Student::~Student()//destructor
{
}
class Milstudent : public Student
{
public:
Milstudent();
void raiseHand();
void talk();
};
Milstudent::Milstudent() :Student(10)
{
name = "Average Military Student";
}
void Milstudent::raiseHand()
{
cout << "Student has raised his hand." << endl;
}
void Milstudent::talk()
{
cout << "I have " << brains << " questions left." << endl;
}
class Colstudent : public Student
{
public:
void fireQuestion(string,int, double, int, int, int);
Colstudent();
void raiseHand();
void talk();
};
Colstudent::Colstudent()
{
name = "Average College Student";
}
void Colstudent::raiseHand()
{
cout << "Student has raised her hand." << endl;
}
void Colstudent::talk()
{
cout << "My name is " << name << "." << endl;
cout << "I have a question." << endl;
}
int main()
{
Milstudent *aStudent = new Milstudent(); // Pointer
aStudent->raiseHand();
aStudent->talk();
Colstudent *aColstudent = new Colstudent();
aColstudent->raiseHand();
aColstudent->talk();
// Free pointers
delete(aStudent);
delete(aColstudent);
}