I'm currently trying to extend my student class with a course class & by extending the driver.cpp to enrol 3 students into the course.
However, i've gotten some errors & can't seem to figure whats wrong with them, i might have missed out something. I was hoping to get some help on these issues & to point out what mistakes I might be made.
Thanks.
here are my codes
Student.cpp
#include <iostream>
#include <string>
#include "Student.h"
using namespace std;
// constructor for your class
Student::Student()
{
}
Student::Student(int newID, string newName)
{
ID = newID;
Name = newName;
}
// destructor for your class
Student::~Student()
{
}
//Accessor Functions
int Student::getStudentID()
{
return ID;
}
string Student::getStudentName()
{
return Name;
}
//Sets the student name attribute data/Mutator
void Student::setStudentName(string newName)
{
Name = newName;
}
//Sets the student ID attribute data/Mutator
void Student::setStudentID(int newID)
{
ID = newID;
}
//displays the output
void Student::display()
{
cout << "Name: "<< Name << endl;
cout << "ID: " << ID << endl;
}
Student.h
#include <iostream>
#include <string>
using namespace std;
#ifndef STUDENT_H
#define STUDENT_H
class Student
{
public:
// constructor
Student();
Student(int, string);
// destructor
~Student();
//Accessors
string getStudentName();
int getStudentID();
//declaration of private methods
void setStudentName(string newName);
void setStudentID(int newID);
void display();
private:
int ID; //Student ID
string Name; //Student Name
};
#endif
Course.cpp
#include <iostream>
#include <vector>
#include <string>
#include "Course.h"
using namespace std;
Course::Course(string a)
{
CourseName=a;
}
string Course::getCourseName()
{
return CourseName;
}
bool Course::isEnrolled(string StudentID)
{
for (int i=0; i<students.size(); i++)
{
if (students[i]==StudentID)
{
return true;
break;
}
else
{
return false;
break;
}
}
}
void Course::enrolStudents(Student)
{
int i;
students.push_back();
}
void Course::display()
{
cout << "Course Name: "<< CourseName << endl;
}
Course.h
#include <iostream>
#include <string>
#include <vector>
#ifndef COURSE_H
#define COURSE_H
class Course
{
public:
// constructor
Course();
Course(std::string a);
// destructor
~Course();
//Accessors
std::string getCourseName();
//declaration of private methods
bool isEnrolled(std::string StudentID);
void enrolStudents(Student);
void display();
private:
std::string CourseName; //Course Name
vector<Student> students; //vector to store students
};
#endif // end of class definition
driver.cpp
#include "Student.h"
#include "Course.h"
int main()
{
Student student;
Course course;
string temp = "student1";
student.setStudentID(23456);
student.setStudentName("Tom");
temp = "student2";
student.setStudentID(24680);
student.setStudentName("John");
temp = "student3";
student.setStudentID(13579);
student.setStudentName("Jason");
student.display();
course.display();
return 0;
}
these are the errors, i am getting:
(course.h)error C2061: syntax error : identifier 'Student'
(course.h)error C2143: syntax error : missing ';' before '<'
(course.h)error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(course.h)error C2238: unexpected token(s) preceding ';'
(course.cpp)error C2065: 'students' : undeclared identifier
(course.cpp)error C2228: left of '.size' must have class/struct/union type is ''unknown-type''
(course.cpp)error C2065: 'students' : undeclared identifier
(course.cpp)error C2065: 'Student' : undeclared identifier
(course.cpp)error C2448: 'Course::enrolStudents' : function-style initializer appears to be a function definition