CS304 Lecture 3 Programs

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

OOP Lecture No.

3 Programs

Topic: Classes
#include<iostream>
#include<conio.h>
using namespace std;
class Student
{
public:
int id;
string name,subject;
void set(int i,string n,string s)
{
id = i;
name = n;
subject = s;
}
void get()
{
cout<<"Student ID: "<<id;
cout<<"\nStudent Name: "<<name;
cout<<"\nStudent Studies: "<<subject;
}
};
main()
{
Student S1,S2,S3;
S1.set(100,"Ali","Mathematics");
S2.set(101,"Anam","Computer Science");
S3.set(102,"Sohail","Chemistry");
S1.get();
cout<<"\n\n";
S2.get();
cout<<"\n\n";
S3.get();
getch();
return 0;
}

Topic: Inheritance
#include<iostream>
#include<conio.h>
using namespace std;
class Person
{
protected:
void eat()
{
cout<<"\n\nEat Function";
}
void walk()
{
cout<<"\n\nWalk Function";
}
};
class Student: public Person
{
public:
void study()
{
cout<<"Student Function";
}
void heldExam()
{
cout<<"\n\nHeld Exam Function";
eat();
walk();
}
};
class Teacher: public Person
{
public:
void teach()
{
cout<<"\n\n\nTeach Function";
}
void takeExam()
{
cout<<"\n\nTake Exam Function";
eat();
walk();
}
};
class Doctor: public Person
{
public:
void checkup()
{
cout<<"\n\n\nCheckup Function";
}
void prescribe()
{
cout<<"\n\nPrescribe Function";
eat();
walk();
}
};
main()
{
Student S;
Teacher T;
Doctor D;
S.study();
S.heldExam();
T.teach();
T.takeExam();
D.checkup();
D.prescribe();
getch();
return 0;
}

You might also like