So I am in a C++ class for school and am doing a project where I must create 2 classes CStudent and CCourse where CStudent includes an array of 5 CCourses being the classes the student takes. I need to overload the insertion operator to display all of the information in CStudent, including all of the classes, except when the data in the array position is the default data for CCourse... I realize I am probably not explaining this very well, but I created a function to display courses when the course in the array does not have the default data, but I cannot get it to be called in the overloaded insertion operator... I can't figure out what to do. Any help would be great?
This is all of my code. Not looking for a cleanup or anything, just why I can't get this one thing to work (I am also finding that the total enrolled units is only displaying as 0 no matter what).
> I am also finding that the total enrolled units is only displaying as 0 no matter what
¿how did you see that if your code does not compile?
also, there isn't a main function.
My teacher provided me with a main function that does work when the code we have written works properly. I simply turned that line into a comment to test the rest of my code. Everything works properly except for that one line and the total enrolled units displays as 0.
//Source.cpp
#include <iostream>
#include "Course.h"
#include "Student.h"
usingnamespace std;
void main()
{
CCourse defaultCourse;
cout << "Information of the default course: \n" << defaultCourse;
CCourse math101("MA101", "Arithemetic Math", 3);
cout << "Information of the course Math101: \n" << math101;
CCourse csci123("C0123", "Introduction To Programming", 4);
cout << "Current ID of the course Computer Science 123: \n" << csci123.getid() << endl;
csci123.setId("CS123");
csci123.title = "Introduction To Programming with C++";
cout << "Updated information of the course Computer Science 123: \n" << csci123 << endl;
CStudent defaultStudent;
cout << "Information of the default student: \n" << defaultStudent;
CStudent firstStudent("S0000", "Toyota", "Camry", 'S', 'M', 3.5);
cout << "\nInformation of the first student: \n" << firstStudent;
cout << "\nChange the ID of the first student to S0001. \n";
firstStudent.setId("S0001");
cout << "Update the GPA of the first student to 3.65. \n";
firstStudent.setGpa(3.65);
cout << "\nThe new ID of the first student is: " << firstStudent.getId() << endl;
cout << "\nThe new GPA of the first student is: " << firstStudent.getGpa() << endl;
cout << "\nEnroll Math 101 for the first student.";
firstStudent.addCourse(math101);
cout << "\nEnroll CSCI123 for the first student.";
firstStudent.addCourse(csci123);
cout << "\nUpdated information of the first student: \n" << firstStudent;
cout << "\nDrop Math 101 for the first student.";
firstStudent.dropCourse(math101);
cout << "\nLast information of the first student: \n" << firstStudent;
system("Pause");
}
I'm obviously modifying Units improperly there. And we have been using void main for all of our main functions since our second assignment, so that isn't the problem. void mains work fine. That way we dont have to return 0 at the end. I also still need to find a way to get it to display the classes..
Just because it compiles doesn't mean you should use it. Void main is non-standard. The cpp standard is int main(void) or int main(int argc, char **argv).
Thank you for the input but that is not what I require assistance with. The sloppiness of my code should show I'm not going for perfection, just for it to do the job. This is only my first programming class, I am a beginner, I imagine I will get better as I go along. Right now, all I need is help with getting the units to display properly.
> I'm obviously modifying Units improperly there
of course, at that point you haven't enrolled to anything yet.
you may update it when you `addCourse()' and `dropCourse()'
> I also still need to find a way to get it to display the classes..
Again, const-correctness.
Or a quick and dirty hack ostream& operator << (ostream& outs, CStudent c)