0% found this document useful (0 votes)
12 views2 pages

Lab 1

Uploaded by

Ali Lak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Lab 1

Uploaded by

Ali Lak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <string>
using namespace std;

class Student {
protected:
string name;
string department;
public:
virtual void get_data() = 0;
virtual void show_data() = 0;
virtual ~Student() {} // Virtual destr
};

class Medical : public Student {


public:
void get_data() override {
cout << "Enter name of Medical student: ";
getline(cin, name);
department = "Medical";
}

void show_data() override {


cout << "Medical Student: " << name << ", Department: " << department <<
endl;
}
};

class Engineering : public Student {


public:
void get_data() override {
cout << "Enter name of Engineering student: ";
getline(cin, name);
department = "Engineering";
}

void show_data() override {


cout << "Engineering Student: " << name << ", Department: " << department
<< endl;
}
};

class Science : public Student {


public:
void get_data() override {
cout << "Enter name of Science student: ";
getline(cin, name);
department = "Science";
}

void show_data() override {


cout << "Science Student: " << name << ", Department: " << department <<
endl;
}
};

int main() {
//array of pointer to the base class
Student* students[3];
// Assign derived class objects to the base class pointers
students[0] = new Medical();
students[1] = new Engineering();
students[2] = new Science();

//input for each student r


for (int i = 0; i < 3; ++i) {
students[i]->get_data();
}

cout << "\nDisplaying student records:\n";

for (int i = 0; i < 3; ++i) {


students[i]->show_data();
}

for (int i = 0; i < 3; ++i) {


delete students[i];
}

return 0;
}

You might also like