﷽
M.Shahid Zafar
M.Sarmad Shuja
M.Ahsan
Wamiq Ali Zain Abid
WHAT IS CLASS ?
The building block of C++ that leads to Object
Oriented programming is a Class. It is a user
defined data type, which holds its own data
members and member functions, which can be
accessed and used by creating an instance of that
class. A class is like a blueprint for an object.
FOR EXAMPLE
Consider the Class of Cars. There may be many
cars with different names and brand but all of them
will share some common properties like all of them
will have 4 wheels, Speed Limit, Mileage range etc.
So here, Car is the class and wheels, speed limits,
mileage are their properties.
WHAT IS CONSTRUCTOR ?
A constructor is a member function of a class which
initializes objects of a class. In C++, Constructor is
automatically called when object(instance of class)
create. It is special member function of the class.
HOW CONSTRUCTORS ARE DIFFERENT
FROM A NORMAL MEMBER FUNCTION?
• Constructor has same name as the class itself
• Constructors don’t have return type
• A constructor is automatically called when an object
is created.
• If we do not specify a constructor, C++ compiler
generates a default constructor for us (expects no
parameters and has an empty body).
PETROLEUM PUMP
#include <iostream>
using namespace std;
class pump{
private:
int num;
float amount , petrol , diesel , cng ;
public:
void input();
void output();
pump()
{
petrol=117.83;
diesel=132.47;
cng=79.82;
}
};
PROGRAM
void pump::input()
{
cout<<"Press 1 for Petrol :: "<<endl;
cout<<"Press 2 for Diesel :: "<<endl;
cout<<"Press 3 for CNG :: "<<endl;
cin>>num;
}
void pump::output()
{
if(num==1)
{
cout<<"Petrol liter :: "<<petrol<<endl<<"Enter the amount :: ";
cin>>amount;
petrol=amount/petrol;
cout<<"liter :: "<<petrol;
}
}
int main()
{
pump a;
a.input();
a.output();
}
HOSTEL MANAGEMENT
OUT PUT
PROGRAM
#include <iostream>
using namespace std;
class hostel{
private:
int num;
public:
void input();
void output();
};
void hostel::input()
{
cout<<"Enter the student id :: ";
cin>>num;
}
void hostel::output()
{
if(num==1)
{
cout<<"student Name ::ttwamiq"<<endl;
cout<<"Class::tttBSCS"<<endl;
cout<<"Room number ::tt5"<<endl;
cout<<"Institute Name ::tNCBA&E"<<endl;
cout<<"Phone number ::t+92-556248585"<<endl;
cout<<"student Fee ::tt6000 per month"<<endl;
cout<<"Address ttMultan";
}
}
int main()
{
hostel b;
b.input();
b.output();
}
FEE MANAGEMENT
#include <iostream>
using namespace std;
class student{
private:
int num,wamiq,fe,total;
public:
void get_roll();
void show_data();
void fee_data();
void latest_data();
student()
{
wamiq=350000;
}
};
void student::get_roll()
{
cout<<"Enter the student roll number :: ";
cin>>num;
}
void student::show_data()
{
if(num==1)
{
cout<<"NametttWamiq"<<endl<<"Father NamettLiaqat
Ali"<<endl<<"ClasstttBSCS(B)"<<endl<<"Total
Feett"<<wamiq<<endl<<"Installmenttt10000"<<endl;
}
}
void student::fee_data()
{
cout<<"Enter the Fee :: ";
cin>>fe;
}
void student::latest_data()
{
cout<<endl<<endl;
if(num==1)
{
total=wamiq-fe;
cout<<"NametttWamiq"<<endl<<"Father NamettLiaqat
Ali"<<endl<<"ClasstttBSCS(B)"<<endl<<"Total
Feett"<<wamiq<<endl<<"Installmenttt10000"<<endl<<"Remaining
Feett"<<total;
}
}
int main()
{
student a;
a.get_roll();
a.show_data();
a.fee_data();
a.latest_data();
}
MONEY EXCHANGE
#include <iostream>
using namespace std;
class curency
{
private:
float dollar/* for input value */,pound,dinar,euro,pakistan;
public:
void get_data();
void output();
curency(){
pound=0.81;
dinar=0.3;
euro=0.9;
pakistan=161.1;
}
};
void curency::get_data()
{
cout<<"Enter amount in dollars($): ";
cin>>dollar;
}
void curency::output()
{
cout << "$" <<dollar << " = " <<dollar*pakistan<<"ttpakistan"<<endl;
cout << "$" << dollar << " = " << dollar*pound << "ttPounds" << endl;
cout << "$" << dollar << " = " << dollar*dinar << "ttDinar" << endl;
cout << "$" << dollar << " = " << dollar*euro << "ttEuro" << endl;
}
int main()
{
curency b;
b.get_data();
b.output();
}
Thank you
Any Question ?

Object Oriented Programming

  • 1.
  • 2.
  • 3.
    WHAT IS CLASS? The building block of C++ that leads to Object Oriented programming is a Class. It is a user defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. A class is like a blueprint for an object.
  • 4.
    FOR EXAMPLE Consider theClass of Cars. There may be many cars with different names and brand but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range etc. So here, Car is the class and wheels, speed limits, mileage are their properties.
  • 5.
    WHAT IS CONSTRUCTOR? A constructor is a member function of a class which initializes objects of a class. In C++, Constructor is automatically called when object(instance of class) create. It is special member function of the class.
  • 6.
    HOW CONSTRUCTORS AREDIFFERENT FROM A NORMAL MEMBER FUNCTION? • Constructor has same name as the class itself • Constructors don’t have return type • A constructor is automatically called when an object is created. • If we do not specify a constructor, C++ compiler generates a default constructor for us (expects no parameters and has an empty body).
  • 7.
  • 8.
    #include <iostream> using namespacestd; class pump{ private: int num; float amount , petrol , diesel , cng ; public: void input(); void output(); pump() { petrol=117.83; diesel=132.47; cng=79.82; } }; PROGRAM
  • 9.
    void pump::input() { cout<<"Press 1for Petrol :: "<<endl; cout<<"Press 2 for Diesel :: "<<endl; cout<<"Press 3 for CNG :: "<<endl; cin>>num; } void pump::output() { if(num==1) { cout<<"Petrol liter :: "<<petrol<<endl<<"Enter the amount :: "; cin>>amount; petrol=amount/petrol; cout<<"liter :: "<<petrol; } }
  • 10.
  • 11.
  • 12.
  • 13.
    PROGRAM #include <iostream> using namespacestd; class hostel{ private: int num; public: void input(); void output(); };
  • 14.
    void hostel::input() { cout<<"Enter thestudent id :: "; cin>>num; } void hostel::output() { if(num==1) { cout<<"student Name ::ttwamiq"<<endl; cout<<"Class::tttBSCS"<<endl; cout<<"Room number ::tt5"<<endl; cout<<"Institute Name ::tNCBA&E"<<endl; cout<<"Phone number ::t+92-556248585"<<endl; cout<<"student Fee ::tt6000 per month"<<endl; cout<<"Address ttMultan"; } }
  • 15.
  • 16.
    FEE MANAGEMENT #include <iostream> usingnamespace std; class student{ private: int num,wamiq,fe,total; public: void get_roll(); void show_data(); void fee_data(); void latest_data(); student() { wamiq=350000; } };
  • 17.
    void student::get_roll() { cout<<"Enter thestudent roll number :: "; cin>>num; } void student::show_data() { if(num==1) { cout<<"NametttWamiq"<<endl<<"Father NamettLiaqat Ali"<<endl<<"ClasstttBSCS(B)"<<endl<<"Total Feett"<<wamiq<<endl<<"Installmenttt10000"<<endl; } }
  • 18.
    void student::fee_data() { cout<<"Enter theFee :: "; cin>>fe; } void student::latest_data() { cout<<endl<<endl; if(num==1) { total=wamiq-fe; cout<<"NametttWamiq"<<endl<<"Father NamettLiaqat Ali"<<endl<<"ClasstttBSCS(B)"<<endl<<"Total Feett"<<wamiq<<endl<<"Installmenttt10000"<<endl<<"Remaining Feett"<<total; } }
  • 19.
  • 20.
    MONEY EXCHANGE #include <iostream> usingnamespace std; class curency { private: float dollar/* for input value */,pound,dinar,euro,pakistan; public: void get_data(); void output(); curency(){ pound=0.81; dinar=0.3; euro=0.9; pakistan=161.1; } };
  • 21.
    void curency::get_data() { cout<<"Enter amountin dollars($): "; cin>>dollar; } void curency::output() { cout << "$" <<dollar << " = " <<dollar*pakistan<<"ttpakistan"<<endl; cout << "$" << dollar << " = " << dollar*pound << "ttPounds" << endl; cout << "$" << dollar << " = " << dollar*dinar << "ttDinar" << endl; cout << "$" << dollar << " = " << dollar*euro << "ttEuro" << endl; }
  • 22.
  • 23.