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

Lecture No.

07 OOP Programs

Topic: Class Code Example


#include<iostream>
#include<conio.h>
using namespace std;
class Student
{
private:
int id;
string name;
public:
void set()
{
id = 100;
name = "Ali";
}
void get()
{
cout<<"Student ID: "<<id;
cout<<"\nStudent Name: "<<name;
}
};
main()
{
Student s;
s.set();
s.get();
getch();
return 0;
}

Topic: Types of User Defined Type


#include<iostream>
#include<conio.h>
using namespace std;
// Class Student
class Student // User Defined Data Type Student
{
// Class Body
};
// Structure Employee
struct Employee // User Defined Data Type Employee
{
// Structure Body
};
main()
{
getch();
return 0;
}

Topic: Access specifier

#include<iostream>
#include<conio.h>
using namespace std;
class Student
{
private:
int a; // a variable only use in this class
protected:
int b; // b variable use both parent & child class
public:
int c; // c variable use any where with the help of object
};
main()
{

getch();
return 0;
}

You might also like