Polymorphism

How to implement a c++ program using arrays for the following scenario?

The program is about student details wherein the program should display the name, identity no, phone in the base class(student). It inherits two derived classes(undergraduate and postgraduate). The undergraduate class takes courses[] as an attribute and postgraduate class takes ResearchTitle as an attribute.

I'm done with the base class and PostGraduate class implementation. I would like to know how to represent the list of courses that corresponds to a particular student using arrays in the undergraduate class(derived) implementation.

student.h
#ifndef STUDENT_H_INCLUDED
#define STUDENT_H_INCLUDED
#include<iostream>
using namespace std;

class student
{
public:
void printProfile();

protected:
string name;
string IC;
long int phone;
};
#endif // STUDENT_H_INCLUDED

Student.cpp
#include <iostream>
#include"Student.h"

using namespace std;

void student::printProfile()
{
cout<<"Welcome to student profile:\n"<<endl;
cout<<endl;
cout<<"Name: ";
cin>>name;
cout<<"\nNRIC: ";
cin>>IC;
cout<<"\nPhone: ";
cin>>phone;
}

int main()
{
student myStudent;
myStudent.printProfile();
}

Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
#include<string>  // 1 you are missing this
using namespace std;

class student
{
public:
void printProfile();

private:
string name;
string IC;
long phone;
};

void student::printProfile()
{
cout<<"Welcome to student profile:\n\n\n"; // 2
cout<<"Name: ";
cin>>name;
cout<<"\n NRIC: ";
cin>>IC;
cout<<"\n Phone: ";
cin>>phone;
}

int main()
{
student myStudent;
myStudent.printProfile();
}
Topic archived. No new replies allowed.