Hey everyone, I haven't been here in sometime but I'm in need of some guidance. One of the questions I have is how do I enter the name, length, and time for each course? Thanks in advance for the help. Here's what I'm supposed to do:
Using OOp inheritance and polymorphism, create four classes as follows:
(1) CSci_Course:
-an abstract class with virtual function getClassTime(); Reason: it is meaningless to have a real classTime for a general CSci class.
-with variables classTime, length, className;
(2) CSci_41:
-an implementation of function getClassTime();
-with variable classTime, className;
-Constructor with arguments of classTime, length, className.
(3) CSci_148:
-an implementation of function getClassTime();
-with variable classTime, className;
-Constructor with arguments of classTime, length, className.
(4) CSci_156:
-an implementation of function getClassTime();
-with variable classTime, className;
-Constructor with arguments of classTime, length, className.
The main program asks the starting time, length, and name of each class. Then, creates 3 pointers of type Csci-Course, and calls getClassTime() function. It should return the actual time of different courses. Finally, if there is a conflict on time schedule, a warning should be provided with clear message which two courses have a conflict.
Note:
(1) you must use Polymorphism;
(2) Make an individual file for each class and the main function;
(3) main function should be put in a file "schedule.cc".
Here's what I have so far:
#include <iostream>
#include <string>
using namespace std;
class CSci_Course
{
public:
CSci_Course();
virtual int getClassTime() = 0;
protected:
string className;
int classTime;
int classLength;
};
class CSci_41: public CSci_Course
{
public:
CSci_41(string name, int time, int length) : CSci_Course()
{
className = name;
classTime = time;
classLength = length;
}
void setClassName( string newClassName )
{
className = newClassName;
}
string getClassName()
{
return className;
}
void setClassTime( int newClassTime )
{
classTime = newClassTime;
}
int getClassTime()
{
return classTime;
}
void setClassLength( int newClassLength )
{
classLength = newClassLength;
}
int getClassLength()
{
return classLength;
}
};
class CSci_148: public CSci_Course
{
public:
CSci_148( string name, int time, int length )
{
className = name;
classTime = time;
classLength = length;
}
void setClassName( string newClassName2 )
{
className = newClassName2;
}
string getClassName()
{
return className;
}
void setClassTime( int newClassTime )
{
classTime = newClassTime;
}
int getClassTime()
{
return classTime;
}
void setClassLength( int newClassLength )
{
classLength = newClassLength;
}
int getClassLength()
{
return classLength;
}
};
class CSci_156 : public CSci_Course
{
public:
CSci_156( string name, int time, int length )
{
className = name;
classTime = time;
classLength = length;
}
int getClassTime()
{
return classTime;
}
string getClassName()
{
return className;
}
int getClassLength()
{
return classLength;
}
};
int main()
{
CSci_41 C41( "CSCI 41",1100,50 );
CSci_148 C148( "CSCI 148", 1500, 50 );
CSci_156 C156( "CSCI 148", 1500, 50 );
CSci_Course *C1 = &C41;
CSci_Course *C2 = &C148;
CSci_Course *C3 = &C156;
cout << C1->getClassTime();
cout << C1->getClassName();
cout << C1->getClassLength();
return 0;
}