Hi,
I am Supposed to be reading from a student file and store it in array of pointers to student Objects(Objects of Student class).
The file contains data like:
102022 Jonathan James L
Dayton, Ohio
775665
M 2 25 2.5
ENGR
Where the 1st line contains the student id, first name, last name. 2nd line is the home town.3rd line is the phone number,4th line contains Sex, Year, Total Credits, GPA, Major
I am able to read the file and store in Array of pointers to student objects. However i am stuck at the below issue:
Then i need to write another class Course which needs to have Dynamically alllocated array of Student Objects
I am not sure how to link the course class to a student class.
Please help.
Here is my student.h file:
I tried to make some headway in Course Class:
I am Supposed to be reading from a student file and store it in array of pointers to student Objects(Objects of Student class).
The file contains data like:
102022 Jonathan James L
Dayton, Ohio
775665
M 2 25 2.5
ENGR
Where the 1st line contains the student id, first name, last name. 2nd line is the home town.3rd line is the phone number,4th line contains Sex, Year, Total Credits, GPA, Major
I am able to read the file and store in Array of pointers to student objects. However i am stuck at the below issue:
Then i need to write another class Course which needs to have Dynamically alllocated array of Student Objects
I am not sure how to link the course class to a student class.
Please help.
Here is my student.h file:
Code:
#include <iostream>
#include<vcl.h>
#include <fstream>
#include<string>
#include<stdlib>
#ifndef STUDENT_H
#define STUDENT_H
//#define FILE_SIZE 102400;
using namespace std;
class student
{
private:
int Student_Id;
string Name;
string HomeTown;
string PhoneNo;
string Gender;
int Year;
int TotalCredit;
float Gpa;
string Major;
public:
student();
student(int Student_Id, string Name);
void change(char *r,char *t);
float modify(int s,float g);
int SetStudentInfo(int Student_Id_In,string Name_In,
string HomeTown_In,string PhoneNo_In,
string Gender_In,int Year_In,int TotalCredit_In,
float Gpa_In,string Major_In );
void OutputData();
int GetStudentInfo();
int GetStudentId();
string GetStudentName();
};
//Constructor
student::student()
{
Student_Id = NULL;
Name = " ";
HomeTown = " ";
PhoneNo = " ";
Gender = " ";
Year = NULL;
TotalCredit = NULL;
Gpa = NULL;
Major = " ";
}
student::student(int Student_Id,string Name)
{
this->Student_Id = Student_Id;
this->Name = Name;
}
student::SetStudentInfo(int Student_Id_In,string Name_In,
string HomeTown_In,string PhoneNo_In,
string Gender_In,int Year_In,int TotalCredit_In,
float Gpa_In,string Major_In)
{
Student_Id=Student_Id_In;
Name = Name_In;
HomeTown= HomeTown_In;
PhoneNo=PhoneNo_In;
Gender=Gender_In;
Year= Year_In;
TotalCredit = TotalCredit_In;
Gpa= Gpa_In;
Major=Major_In;
}
void student::OutputData()
{
cout<<Student_Id<<endl;
cout<<Name<<endl;
cout<<HomeTown<<endl;
cout<<PhoneNo<<endl;
cout<<Gender<<" "<<Year<<" "<<Gpa<<endl;
cout<<Major;
system("Pause");
}
int student::GetStudentId()
{
return Student_Id;
}
string student::GetStudentName()
{
return Name;
}
#endif
Code:
#include <iostream>
#include<vcl.h>
#include <fstream>
#include<string>
#include<stdlib>
#include "Student.h"
using namespace std;
class Course{
private:
int Student_Id;
string Name;
student *s[500];
int num_students;
public:
Course();
Course(int Student_Id,string Name);
void addStudent(student *s[]);
};
Comment