/* Slip no : 13_1 Write a C++
program to calculate area of cone, sphere and circle by using function
overloading. */
#include<iostream.h>
#include<conio.h>
class calculate
{
float
r_cn,r_s,side;
int
r_c;
public:
void
area(float r, float s)
{
r_c=r;
side=s;
cout<<"\nArea
of cone =\t\t"<<3.14*r_c*side;
}
void
area(float r)
{
r_s=r;
cout<<"\nArea
of sphere =\t"<<4*3.14*r_s*r_s;
}
void
area(int r)
{
r_c=r;
cout<<"\nArea
of circle =\t"<<3.14*r_c*r_c;
}
};
void main()
{
float
r_cone,side;
int
r_circle;
float
sp;
clrscr();
calculate
c;
cout<<"\nEnter
radius of cone\t";
cin>>r_cone;
cout<<"\nEnter
side of cone\t";
cin>>side;
cout<<"\nEnter
radius of sphere\t";
cin>>sp;
cout<<"\nEnter
radius of circle\t";
cin>>r_circle;
c.area(r_cone,side);
c.area(sp);
c.area(r_circle);
getch();
}
/* Slip no : 13_2 Create a class
Matrix and Write a C++ program with following functions:
i. To accept a Matrix
ii. To display a Matrix
iii. Overload unary minus ‘–‘
operator to calculate transpose of a Matrix
iv. Overload binary multiplication
'*’ operator to calculate multiplication of two matrices */
#include<iostream.h>
#include<conio.h>
class matrix
{
public:
int r,c,a[10][10],i,j;
void getdata()
{
cout<<"\n
Enter number of rows to be inserted in matrix : ";
cin>>r;
cout<<"\n
Enter number of columns to be inserted in matrix : ";
cin>>c;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
cout<<"\n
Enter matrix elements of "<<i<<" row";
cin>>a[i][j];
}
}
}
void display()
{
for(i=0;i<r;i++)
{
cout<<endl;
for(j=0;j<c;j++)
{
cout<<a[i][j];
cout<<"\t";
}
}
}
void operator-()
{
matrix
m(r,c);
for(i=0;i<r;i++)
{
cout<<endl;
for(j=0;j<c;j++)
{
m.a[i][j]=a[j][i];
}
}
m.display();
}
matrix()
{}
matrix(int row,int column)
{
r=row;
c=column;
}
friend matrix
operator*(matrix,matrix);
};
matrix operator*(matrix obj,matrix
obj1)
{
int i,j,k,sum;
if(obj.c==obj1.r)
{
matrix
k1(obj.r,obj1.c);
for(i=0;i<obj.r;i++)
{
//cout<<endl;
for(j=0;j<obj1.c;j++)
{
//k.a[i][j]=0;
sum=0
;
for(k=0;k<obj.c;k++)
{
sum=sum+obj.a[i][k]
* obj1.a[k][j];
}
k1.a[i][j]=sum;
}
}
return
k1;
}
else
{
cout<<"multipliction
is not possible";
matrix
k(0,0);
return
k;
}
}
void main()
{
clrscr();
matrix m1,m2,m3;
m1.getdata();
m2.getdata();
cout<<"\n first matrix
is :";
m1.display();
cout<<"\n 2nd matrix is
: ";
m2.display();
m3=m1*m2;
cout<<"\n Transpose of
1st matrix is : ";
-m1;
cout<<"\n mutiplication
of matrix is : \n";
m3.display();
getch();
}
slips 13
Reviewed by Dinesh Varal
on
January 17, 2018
Rating:
No comments: