Hello accuracy12,
You first wrote:
I have a student, class and school class.
I assign random names and numbers to fields in the student class. I randomly assign the class name to classes.
These random students that I create form a class. I'm writing this class to a txt file.
write to records.txt
|
This is a nice start, but I do not feel as these are the full instructions that you were given.
The header files and input file that you have posted are a help, but not enough. The ".cpp" files are missing and I have to guess at some of the code. The function
File::SaveClass()
suggests that there is a "File" class that is missing.
I feel like you want me to write a program based on one function and the header files.
Not seeing what you have done so far the code I can write may contain some things that you are not ready for, but work the best.
To do what I believe is best I will have to write the code I have in a new way. It would help to know how the program should work without having to guess at what to do.
After doing some reading the code I showed you with inheritance should work, but I did have some trouble trying to change the code I had first come up with. For this I am trying to start over.
While I am here:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class Student
{
public:
string getName();
string getSurname();
void setNo(int);
int getNo();
Student();
~Student();
private:
string name, surname;
int studentNo;
};
|
Lines 9 and 10 are not needed unless you actually put something in the function body to set the variables. Otherwise the compiler will create a default ctor and dtor for you. If you create an overloaded ctor you will need to include the default ctor, but the compiler will still create the default dtor.
This holds true for all three classes.
I am thinking that the variable
TotalClassroomCount
should be defined in the "School" header file, but
std::list<Classroom> classroomsList
along with the ".size()" function would negate the need for "TotalClassroomCount" as long as the input file has no duplicate classrooms. And I did change the name of the list as there are to many "classroom"s used in the program also the name gives a better name of what the "list" is for.
Hope that helps,
Andy