You are on page 1of 4

Ministry of Higher Education and Scientific Research

Al- Esraa University College


Dep. of Computer Engineering

Object Oriented Programming

(OOP)

MSc. Ahmed & Abeer

2022/2021
Object Oriented Programing MSc.Ahmed& Abeer
Computer Engineering Department -2 nd Stage Al- Esraa University Collage

Example 3: Design OOP program that include class name (Distance) as illustrated in
following chart :

Class Distance

Private Public

int feet getdist()

float inches showdist()

#include <iostream>
using namespace std;
class Distance{
private:
int feet;
float inches;
public:
void getdist(){
cout << "enter feet ";
cin >> feet;
cout << "enter inches ";
cin >> inches;
}
void showdist(){
cout << "Distance is feet " << feet << "inches " << inches << endl;
}
};
int main(){
Distance d2;
d2.getdist();
d2.showdist();
return 0;
}

2
Object Oriented Programing MSc.Ahmed& Abeer
Computer Engineering Department -2 nd Stage Al- Esraa University Collage

Example 4: Design OOP program that include class name (Student) as illustrated in
following chart :

#include <iostream>
#include<string>
using namespace std;
class Student{
private:
string name;
int grade;
public:
void getname(string n, int a){
name = n;
grade = a;
}
void printgrade(){
cout << "Name of student " << name << endl;
cout << "Grade of student " << grade << endl;
}
};
int main(){
Student q;
q.getname("Sham", 100);
q.printgrade();
return 0;
}

3
Object Oriented Programing MSc.Ahmed& Abeer
Computer Engineering Department -2 nd Stage Al- Esraa University Collage

You might also like