Ques 1 Write A Program To Find The Area of Square, Rectangle, Triangle and Circle
Ques 1 Write A Program To Find The Area of Square, Rectangle, Triangle and Circle
M.Sc. Electronics
1st Semester
Ques 1 Write a program to find the area of square ,rectangle , triangle
and circle.
Program:-
#include <iostream>
#include<math.h>
int main(){
int a,are,a1,a2,b1,b2,c1,c2,are1,s,r;
float are2,are3;
cin>>a;
are=a*a;
cin>>a1>>b1;
are1=a1*b1;
cin>>a2>>b2>>c2;
s=(a2+b2+c2)/2;
are2=sqrt(s*(s-a2)*(s-b2)*(s-c2));
cin>>r;
are3=3.14*r*r;
return 0;
Ques 2 write a program that accept two integer values and then manipulate
these values depending upon the operator(+,*,/,-,%)using switch statement.
Program:-
#include <iostream>
#include<math.h>
int main(){
int ch,a,b,c,c1,c2,c3,c4;
cout<<"1.addtion\n2.subtraction\n3.multiplication\n4.quotient\n5.remainder"
;
cin>>a>>b;
switch(ch) {
case 1:
c=a+b;
break;;
case 2:
c1=a-b;
break;
case 3:
c2= a*b;
break;
case 4 :
c3=a/b;
break;
case 5:
c4=a%b;
sonali
M.Sc. Electronics
1st Semester
cout<<"\n remainder of a and b is =\t "<<c4;
break;
return 0;
Ques 3 write a program to find the greatest and smallest number among the
three numbers (using switch statement)
Program:-
#include <iostream>
#include<math.h>
int main(){
int a,b,c,d,e,d1,e1;
cin>>a>>b>>c;
if (a>b){
d=a;}
sonali
M.Sc. Electronics
1st Semester
else{
d=b;}
if (d>c){
e=d;}
else{
e=c;
if (a>b){
d1=b;}
else{
d1=a;
if (d1>c){
e1=c;}
else{
e1=d1;
return 0;
Ques 4 write a program to find the greatest number among the three
numbers(using function)
Program:-
#include <iostream>
#include<math.h>
int main(){
int a,b,c,ans;
cin>>a>>b>>c;
ans=largest(a,b,c);
return 0;
}
sonali
M.Sc. Electronics
1st Semester
int d,e;
if (a>b){
d=a;}
else{
d=b;
if (d>c){
e=d;}
else{
e=c;
return e;
Program:-
#include <iostream>
int main(){
string s1,s2,result;
sonali
M.Sc. Electronics
1st Semester
cout<<"\n enter string s1=\t";
cin>>s1;
cin>>s2;
result=s1+s2;
return 0;
Program:-
#include <iostream>
#include<math.h>
int main(){
float a,b,c,d,x1,x2,realPart,imaginaryPart;
d=b*b-4*a*c;
if (d == 0){
x1= -b/(2*a);
cout<<"x1=x2="<<x1;
if (d > 0){
x1=(-b-sqrt(d))/(2*a);
x2=(-b+sqrt(d))/(2*a);
cout<<"\nx1="<<x1;
cout<<"\nx2="<<x2;
if (d < 0){
realPart = -b/(2*a);
imaginaryPart =sqrt(-d)/(2*a);
cout << "\nx1 = " << realPart << "+" << imaginaryPart << "i" ;
cout << "\nx2 = " << realPart << "-" << imaginaryPart << "i" ;
return 0;}
sonali
M.Sc. Electronics
1st Semester
1) To create a matrix
2) To add a matrix to another
3) To subtract a matrix to another
4) To multiply a matrix by scalar
5) To divide a matrix by a scalar
6) To transpose a matrix
Program:-
#include <iostream>
using namespace std;
int i1=3,j1=3,i,j,k;
class matrix{
public :
int
a[3][3],b[3][3],c[3][3],mul[3][3],scal[3][3],scall[3][3],transposematrix[3][3
];
void creata();
void creatb();
void add();
void subtract();
void multiplication();
void scalarmul();
void divmul();
sonali
M.Sc. Electronics
1st Semester
void transpose();
};
void matrix::creata(){
cout<<"\n enter the a matrix\t";
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n a["<<i<<"]["<<j<<"]";
cin>>a[i][j];
}
}
}
void matrix::creatb(){
cout<<" \n enter the b matrix\t";
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n b["<<i<<"]["<<j<<"]";
cin>>b[i][j];
}
}
}
void matrix :: add(){
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n addtion matix is
\t"<<"["<<i<<"]["<<j<<"]"<<c[i][j];
}
}
}
sonali
M.Sc. Electronics
1st Semester
void matrix :: subtract(){
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
c[i][j]=a[i][j]- b[i][j];
}
}
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n subtract matix is
\t"<<"["<<i<<"]["<<j<<"]"<<c[i][j];
}
}
}
void matrix :: multiplication(){
int sum;
for(i=0;i<i1;i++){
for(j=0;j<j1;j++)
{ sum=0;
for(k=0;k<j1;k++){
sum=sum+a[i][k]*b[k][j];
mul[i][j]=sum;
}
}
}
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n multiplication matrix is
\t"<<"["<<i<<"]["<<j<<"]"<<mul[i][j];
}
}
}
void matrix :: scalarmul()
{
sonali
M.Sc. Electronics
1st Semester
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
scal[i][j]=3*a[i][j];
}
}
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n scalar multiplication a[3][3]
matix\t"<<"["<<i<<"]["<<j<<"]"<<scal[i][j];
}
}
}
void matrix :: divmul()
{
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
scall[i][j]=3/a[i][j];
}
}
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
cout<<"\n scalar multiplication matix
\t"<<"["<<i<<"]["<<j<<"]"<<scall[i][j];
}
}
}
void matrix :: transpose(){
for(i=0;i<i1;i++){
for(j=0;j<j1;j++){
transposematrix[i][j]=a[j][i];
}
}
for(i=0;i<i1;i++){
sonali
M.Sc. Electronics
1st Semester
for(j=0;j<j1;j++){
cout<<"\n \n transpose matrix is "<<"\t
["<<i<<"][["<<j<<"]"<<transposematrix[i][j];
}
}
}
int main()
{
matrix m;
m.creata();
m.creatb();
m.add();
m.subtract();
m.multiplication();
m.scalarmul();
m.divmul();
m.transpose();
return 0;
}
sonali
M.Sc. Electronics
1st Semester
Ques 8 Create two classes GRADE and STUDENT .the class GRADE has data members
GRADE while STUDENT has data members such as roll no.,name,marks of the students.
Making use of data of both the classes print the roll no.,name,and grade of each student
whose grade is set by the grade class.
Program :
#include<iostream>
#include<string.h>
int n;
class grade
public:
int m[10][10];
void marks();
sonali
M.Sc. Electronics
1st Semester
}g;
class student
public:
string name[10];
int rollno[10];
void getdata();
}s;
int main()
cin>>n;
s.getdata();
g.marks();
return (0);
void grade::marks()
for(int i=0;i<n;i++)
int j=0;
cin>>m[i][j];
sonali
M.Sc. Electronics
1st Semester
j++;
cin>>m[i][j];
for(int i=0;i<n;i++)
int sum=0;
for(int j=0;j<2;j++)
sum=sum+m[i][j];
cout<<s.rollno[i]<<" \t";
cout<<s.name[i]<<"\t\t";
cout<<sum<<"\n";
for(int i=0;i<n;i++)
{
sonali
M.Sc. Electronics
1st Semester
cout<<"enter the roll no\n";
cin>>s.rollno[i];
cin>>s.name[i];
Program
#include <iostream>
class Shape {
protected:
int width;
int height;
public:
void setWidth(int w) {
width = w;
}void setHeight(int h) {
height = h;
} };
// Derived class
public:
int getArea() {
};
int main(void) {
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
sonali
M.Sc. Electronics
1st Semester
// Print the area of the object.
return 0;}
Program:-
#include <iostream>
void display(int);
void display(float);
int main() {
int a = 5;
float b = 5.5;
display(a);
display(b);
display(a, b);
sonali
M.Sc. Electronics
1st Semester
return 0;