Beruflich Dokumente
Kultur Dokumente
07514802717
4th SEMESTER
EXPERIMENT 01
SOURCE CODE:
#include<iostream>
#include<conio.h>
#include<stdlib.h>
int main()
system("color f0");
system("cls");
int a[10][10],b[10][10],mult[10][10],r1,c1,r2,c2,i,j,k,sum=0;
cin>>r1>>c1;
cin>>r2>>c2;
if(c1!=r2)
else
for(j=0;j<c1;j++)
cin>>a[i][j];
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
cin>>b[i][j];
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{ sum=0;
for(k=0;k<c1;k++)
sum+=a[i][k]+b[k][j];
mult[i][j]=sum;
cout<<"1st Matrix:\n";
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
cout<<a[i][j]<<"\t";
cout<<endl;
SUMIT
07514802717
4th SEMESTER
}
cout<<"\n2nd Matrix:\n";
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
cout<<b[i][j]<<"\t";
cout<<endl;
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
cout<<mult[i][j]<<"\t";
cout<<endl;
return 0;
}
SUMIT
07514802717
4th SEMESTER
OUTPUT:
SUMIT
07514802717
4th SEMESTER
EXPERIMENT 02
SOURCE CODE:
#include<iostream>
#include<stdlib.h>
class A;
class B{
private:
int b;
public:
B(int y) {
b=y;}
};
class A{
private:
int a;
public:
A(int b) {
a=b;}
if(x.a>y.b)
return x.a;
else
return y.b;
int main()
system("color f0");
int m,n;
cin>>m>>n;
A obj(m);
B obj1(n);
int maxnum=max_fun(obj,obj1);
cout<<maxnum<<" is greater";
return 0;
OUTPUT:
SUMIT
07514802717
4th SEMESTER
VIVA QUESTIONS:
1. What is the difference between friend function and friend class?
Ans-> In short, one is a class and one is a function. For the function, just that
one function gets access to private members. For a class, the whole class and all
its functions get access to the private members of the befriended class. The
friend keyword is used to grant access to private data members.
2. What are the Advantages of using friend classes?
Ans-> The volatile keyword is intended to prevent the compiler from applying
any optimizations on objects that can change in ways that cannot be
determined by the compiler.
volatile uint16_t x;
SOURCE CODE:
#include<iostream>
#include<stdlib.h>
class Complex
int real;
int imag;
public:
Complex(){}
Complex(int r)
real=r;
imag=r;
Complex(int x,int y)
real=x;
imag=y;
real=t.real+p.real;
imag=t.imag+p.imag;
void display()
cout<<real<<" + "<<imag<<"i\n";
};
int main()
system("cls");
system("color f0");
Complex c;
Complex c1(2);
Complex c2(3);
cout<<"Before addition:\n";
c1.display();
c2.display();
c.add(c1,c2);
c.display();
}
SUMIT
07514802717
4th SEMESTER
OUTPUT:
SUMIT
07514802717
4th SEMESTER
VIVA QUESTIONS:
1. Explain Default constructor.
Ans-> Deleting a derived class object using a pointer to a base class that has a
non-virtual destructor results in undefined behavior. To correct this situation,
the base class should be defined with a virtual destructor.