Oop Practical
Oop Practical
PR ’++
’æ *’
’**W• #’
_ .'
',\/ \/- ’’ -
- ’- ' . '
MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION
Certificate
. ... . .... .................................
ROI1N O.. of ThirdSemesterofDiplomain
(Code: .... .... . ...) has completed ihc term work satisfactorily in course
Ob)ert Orlenied Programming Using C + (22316} tor the academic year
20........ to 20.as prescribed in ihe curriculum.
9 -.
9
C
//Exercise:
#include <iostream.h>
#include <conio.h>
Void main()
Int year;
Clrscr();
Cin>> year;
If (year % 4 == 0)
Else
Getch();
}
//2) Write a C++ Program armstrong between two numbers
#include <iostream.h>
#include <conio.h>
#include <math.h>
Int main()
sum;
Cin>>num1;
Cin>>num2;
Sum =0;
Num =I;
If (sum == i)
Cout<<i<<endl;
Return 0;
//3)
#include <iostream.h>
#include <conio.h>
Int main()
Cin>>num;
Temp = num;
While (temp>0)
Rem = temp%10;
Rev = (rev*10)+rem;
Temp = temp/10;
If (rev == num)
Else
Cout<<endl;
Return 0;
}
,y
L
//EXercise
#include<iostream.h>
int main()
num=7;
tab=num*i;
}
//2) Write A C++ Program to print 100 to 1
#include <iostream.h>
#include <conio.h>
Void main()
Clrscr();
Int I;
Cout<<i<<endl;
Getch();
}
//3] Wrote a C++ Program which will print (half pyramid) pttern of the natural numbers
#include <iostream.h>
#include <conio.h>
Void main()
Clrscr();
Int rows =
5; Int I;
Int j;
Cout<< j<< “ “;
Cout<< “\n”;
Getch();
}
//4] Write A C++ program ask the user to enter the number of rows to print the pyramid of stars(*)
#include <iostream.h>
#include <conio.h>
Int main()
Int rows;
Cout << “* “;
Getch();
}
0
° **1 ”"
zoo y•• ‘l ’“ L
//Exercise
//1) Write a C++ program to declare a class “Book” having data members book_name, author and
price. Accept and display data for book having maximum price.
#include<iostream.h>
#include<conio.h>
#include<string.h>
Class Book
Int no_of_pages;
Char book_name[50];
Public:
Float price;
Void getdata()
Cin>>book_name;
Cin>>price;
Cout<<”Enter No of pages:-> “;
Cin>>no_of_pages;
}
Void display()
Cout<<”\nBook Price:->”<<price;
};
Void main()
Book b1,b2;
Clrscr();
B1.getdata();
B2.getdata();
If(b1.price>b2.price)
B1.display();
Else
B2.display();
Getch();
}
//2) Write a C++ program to declare a class “staff having data members name. basic salary, DA, HRA
and calculate gross salary. Accept and display data for one staff.
// ii. Gross_salary-basic+HRA+DA
#include<iostream.h>
#include<conio.h>
Class staff
{
Float
basic,gross_sal;
Public:
Void accept()
Cin>>basic;
};
Gross_sal=(basic*DA/100)+(basic*HRA/100)+basic;
Return(gross_sal);
Void main()
Clrscr();
Staff s1;
S1.accept();
Getch();
}
Output Prepared By Khan Abdullah Rżyaz
Enter Basic Salary of Staff: 30000
Gross Salary of Employee 61350
[Program finished]
› ‹ . . -”i- » ”<
0
re.• cc • r-* ° °
_‹.. a.-=›. •î
*“ "’*
//Exercise
//1) Write a C++ program to define a class “Employee” having data members emp_id, emp_name and
emp_salary. Accept and display data for employees having salary greater than 25,000/-.
#include<iostream.h>
#include<conio.h>
Class Employee
Int emp_id;
Char emp_name[20];
Public:
Float emp_salary;
Void accept()
Cin>>emp_id;
Cin>>emp_salary;
Void display()
};
Void main()
Int I;
Clrscr();
Employee e[2];
For(i=0;i<2;i++)
{
E[i].accept();
For(i=0;i<3;i++)
If(e[i].emp_salary>25000)
E[i].display();
Getch();
}
//2)Write a C++ program to define a class “City” having data members name, population.Accept and
display data for 10 cities.
#include<iostream.h>
#include<conio.h>
Class City
Char city_name[20];
Public:
Void accept()
Cin>>city_name;
Cin>>population;
Void display()
{
Cout<<endl<<”City Name=> “<<city_name<<endl;
Cout<<”Population=> “<<population<<endl;
};
Void main()
Int I;
Clrscr();
City c[2];
For(i=0;i<2;i++)
C[i].accept();
For(i=0;i<2;i++)
{
C[i].display();
Getch();
}
0
0
c>• 1-
// 1) C++ Program to swap two numbers using friend function
#include <iostream.h>
#include <conio.h>
Class Swap {
Int temp, a, b;
Public:
Swap(int a, int b)
This->a = a;
This->b = b;
}
// Declare the friend function to swap, take arguments
// as call by reference
};
// the function
S1.temp = s1.a;
S1.a = s1.b;
S1.b = s1.temp;
Cout << “\nAfter Swapping: “ << s1.a << “ “ << s1.b;
// Driver Code
Int main()
Swap(s);
Return 0;
}
//2) Write a C++ program to define a class “Distance” having data member as meters.Display the
addition of two Distance objects using friend function.
#include <iostream.h>
#include <conio.h>
Class DM
Public:
DM()
Cin>>distm;
};
Void main()
{
Clrscr();
DM d1;
DM d2;
Totaldist(d1,d2);
Getch();
}
!1
iÈ
‹
9
9
6
L*
9
a
0
.
Duted signature
Marks Obtained
of Teacher
Process Product
Total(50)
Related(35) Related(IS)