You are on page 1of 12

//Program to print the sum of matrices

#include<iostream.h>
#include<process.h>
{
int a[10][10],b[10][10],c[10][10];
int I,j,m,n,p,q;
cout<<”\n Input row & column of matrix-A \n”;
cin>>m>>n;
cout<<”\n Input row & column of matrix – B \n”;
cin>>p>>q;
if((m==p)&&(n==q))
cout<<”Matrices can be added \n”;
else
{
cout<<”Matrices can not be added \n”;
exit(0);
)
cout<<”\n Input matrix – A \n”;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<”\n Input matrix – B \n”;
for(i=0;j<p;j++)
{
for(j=0;j<q;j++)
{
cin>>b[p][q];
}
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
cout<<”\n The sum of two matrices is: \n “;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<” “<<c[i][j];
}
}
}

OUTPUT

Input of row & column of matrix – A


22
Input of row & column of matrix – B
22
Matrix can be added
Input matrix A
12
34
Input matrix B
43
21
The sum of two matrices is :
55
55
/*Program to illustrate the working of function overloading. Calculate interest amount
using function overloading. */

#include<iostream.h>
#include<conio.h>
void amount(float princ,int time,float rate)
{
cout<<”\n Principal Amount:”<<princ;
cout<<”\n Time:”<<time<<”years”;
cout<<”\t Rate:”<<rate;
cout<<”\n Interest Amount:”<<(princ*time*rate)<<”\n”;
}
void amount(float princ,int time)
{
cout<<”\n Principal Amount:”<<princ;
cout<<”\t Time:”<<time<<”years”;
cout<<”\t Rate:0.08”;
cout<<”\n Interest Amount:”<<(princ*time*0.08)<<”\n”;
}
void amount(float princ,float rate)
{cout<<”\n Principal Amount:”<<princ;
cout<<”\t Time: 2 years”;
cout<<”\t Rate:”<<rate;
cout<<”\n Interest Amount:”<<(princ*2*rate)<<”\n”;
}
void amount(float princ)
{
cout<<”\n Principal Amount:”<<princ;
cout<<”\t Time: 2years”;
cout<<”\t Rate:0.08”;
cout<<”\n Interest Amount:”<<(princ*2*0.08)<<”\n;
}
int main()
{
clrscr();
cout<<”case1”;
amount(2000.0F);
cout<<”case2”;
amount(2500.0F,3);
cout<<”case3”;
amount(2300-0F,3,0.11F);
cout<<”case4”;
amount(6,0.07F);
return 0;
}
OUTPUT

Case 1
Principal Amount : 2000 Time : 2years Rate : 0.08
Interest Amount : 320

Case 2
Principal Amount : 2500 Time : 3years Rate : 0.08
Interest Amount : 600

Case 3
Principal Amount : 2300 Time : 3years Rate : 0.11
Interest Amount : 759

Case 4
Principal Amount : 2000 Time : 3years Rate: 0.07
Interest Amount : 840
//Program to read values into a nested structure

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct addr
{
int houseno;
char area[26];
char city[26];
char state[26];
};
struct emp
{
int empno;
char name[26];
char design[26];
addr address;
float basic;
}worker;
void main()
{
clrscr();
cout<<”\n Enter Employee no:”<<”\n”;
cin>>worker,empno;
cout<<”\n”<<”Name”;
gets(worker.name);
cout<<”\n”<<”Designation:”;
gets(worker.desig);
cout<<”\n”<<”Enter address: \n”;
cout<<”House no:”;
cin>>worker.address.houseno;
cout<<”\n”<<”Area:”;
gets(worker.address.area);
cout<<”\n”<<”City:”;
gets(worker.address.city);
cout<<”\n”<<”State”;
gets(worker.address.state);
cout<<”\n”<<”Basic pay:”;
cin>>worker.basic;
getch();
OUTPUT

Enter Employee no:


103
Name: Neel
Designation: Manager
Enter address:
House no: 321
Area:Sadiq Nagar
City: Delhi
State: Delhi
Basic Pay: 9800
//Program to find whether two strings contain equal number of characters

#include<iostream.h>
#include<string.h>
void main()
{
char string1[50],string2[50];
cout<<”Enter strings \n”;
cin.getline(string1.50);
cin.getline(string2.50);
if(strlen(string1)==strlenstring2))
cout<<”\n Both strings contain equal number”<<”of character”<<”\n”;
else
cout<<”\n Both strings contain different number”<<”of character”<<”\n”;
}
OUTPUT

Enter strings
Yohaan
Neelam
Both strings contain equal number of characters
/*Temperature-conversion program that gives the user the option of converting
Fahrenheit to Celsius or Celsius to Fahrenheit and depending upon user’s choice carries
out the conversion*/

#include<iostream.h>
#include<conio.h>
void main()
{
int choice;
float temp,countemp;
cout<<”Temperature conversion menu”<<”\n”;
cout<<”1.Fahrenheit to Celsius”<<”\n”;
cout<<”2.Celsius to Fahrenheit “<<”\n”;
cout<<”Enter your choice:”;
cin>>choice;
if(choice==1)
{
cout<<”\n”<<”Enter temperature in Fahrenheit:”;
cin>>temp;
countemp=(temp-32)/1.8;
cout<<”The temperature in Celsius is:”<<countemp<<”\n”;
}
else
{
cout<<”\n”<<”Enter temperature in celsius:”;
cin>>temp;
countemp=1.8*(temp+32);
cout<<”The temperature in Fahrenheit is :”<<countemp<<”\n”;
}
getch();
}
OUTPUT

Temperature conversion menu


1. Fahrenheit to Celsius
2. celsius to Fahrenheit
Enter your choice: 2
Enter temperature in Celsius is: 37
The temperatre in Fahrenheit is: 98.6
//Program to illustrate the working of a function returning an object

#include<iostream.h>
class distance{int feet,inches
public:
voidgetdata(int f,int i)
{
feet=f;inches=I;
}
voidprintit(void)
{ cout<<feet<<”feet”<<inches<<”inches”<<”\n”;
}
Distance sum(distance d2);
};
Distance Distance::sum(distance d2)
{
Distance d3;
d3.feet=feet+d2.feet+(inches+d2.inches)/12;
d3.inches=(inches+d2.inches)%12;
return(d3);
}
int main()
{
Distance length1,length2,total;
Length1.getdata(17,6);
Length2.getdata(13,8);
Total=length1.sum(length2);
Cout<<”Length 1:”;
Length1.printit();
Cout<<”Length 2:”;
Length2.printit();
Cout<<”total length:”;
Total.printit();
Return 0;
}
OUTPUT

Length 1: 17 feet 6 inches


Length2: 13 feet 8 inches
Total length: 13 feet 2 inches

You might also like