Professional Documents
Culture Documents
Amar Oops
Amar Oops
ORIENTED
PROGRAMMING
By-
GURKARAN SINGH
IT-1
01913203118
PRACTICAL – 1
WAP to input 2 matrices and multiply the matrices.
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
clrscr();
cout<<"\n Enter number of rows and columns of first matrix : ";
cin>>m>>n;
cout<<"\n Enter elements of first matrix : ";
for (c=0 ; c<m ; c++)
{
for (d=0 ; d<n ; d++)
{
cout<<"\n Enter "<<c+1<<"-"<<d+1<<" element : ";
cin>>first[c][d];
}
}
cout<<"\n Enter number of rows and columns of second matrix : ";
cin>>p>>q;
if (n != p)
cout<<"\n The matrices can't be multiplied with each other.";
else
{
cout<<"\nEnter elements of second matrix : ";
OUTPUT:
PRACTICAL – 2
WAP to create a class STUDENT and its object and input details.
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class student
{
char name[30];
char rno[10];
char batch[10];
public:
void display();
void input();
};
void student::input(void)
{
cout<<"\n Enter Name : ";
gets(name);
cout<<"\n Enter Roll No.: ";
gets(rno);
cout<<"\n Enter the Batch : ";
gets(batch);
}
void student::display(void)
{
cout<<"\n Name : "<<name;
cout<<"\n Roll No.: "<<rno;
cout<<"\n Batch : "<<batch;
}
void main()
{
clrscr();
student s;
cout<<"\n\t Enter Student Information ";
s.input();
cout<<"\n\t Student Information ";
s.display();
getch();
}
OUTPUT:
PRACTICAL – 3
WAP to print smallest of 2 numbers using inline function.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"Enter 2 numbers:";
cin>>a>>b;
cout<<"Smallest of the numbers is : "<<small(a,b);
getch();
OUTPUT:
PRACTICAL – 4
WAP to demonstrate the default arguments.
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
OUTPUT:
PRACTICAL – 5
WAP to demonstrate the use of static member function.
#include<iostream.h>
#include<conio.h>
class ADD
{ static int a;
static int b;
public:
static void print()
{
cout<<"\nValue of A : "<<a;
cout<<"\nValue of B : "<<b;
}
};
int ADD::a=20;
int ADD::b=40;
void main()
{
clrscr();
ADD abc;
cout<<"Print through object name : ";
abc.print();
cout<<"\nPrint through class name : ";
ADD::print();
getch();
}
OUTPUT:
PRACTICAL – 6
WAP to demonstrate the use of friend function.
#include<iostream.h>
#include<conio.h>
class ABC
{
private:
int num;
public:
ABC() : num(50){};
friend void display(ABC obj);
};
void display(ABC obj)
{
cout<<obj.num<<endl;
}
void main()
{
clrscr();
ABC object1;
display(object1);
getch();
}
OUTPUT:
PRACTICAL – 7
WAP to demonstrate the use of friend class.
#include<iostream.h>
#include<conio.h>
class XYZ
{
private :
int num;
public:
XYZ() : num(50){};
friend class ABC;
};
class ABC
{
public:
void display(XYZ obj)
{
cout<<obj.num<<endl;
}
};
void main()
{
clrscr();
XYZ object1;
ABC object2;
object2.display(object1);
getch();
}
OUTPUT: