Sunday, December 7, 2014

Write a C++ program to find area of triangle, circle,and rectangle using function overloading

#include<iostream>
using namespace std;

const float pi=3.14;
float area(float n,float b,float h)
float area(float x,float y,float z)
{
float ar;
ar=x*y*z;
cout<<"The area of Triangle : "<<ar<<endl<<endl;
}
float area(float n)
{
float ar;
ar=pi*n*n;
cout<<"The area of Circle : "<<ar<<endl<<endl;
}
float area(float l,float w)
{
float ar;
ar=m*w;
cout<<"The area of Rectangle :"<<ar<<endl;
}
int main()
{
float y,z,n,l,w;

cout<<"Enter the Base & Hieght of Triangle : ";
cin>>y>>z;
area(0.5,y,z);

cout<<"Enter the radius of circle :";
cin>>n;
area(n);


cout<<"Enter the Lenght & width of Rectangle: ";
cin>>l>>w;
area(l,w);
return 0;
}

Write a C++ program using class to calculate simple interest amount use default value for rate.

# include
# include
class bank
{
private:
float p;
float r;
float t;
float si;
float amount;
public:
void read ( )
{
cout <<" Principle Amount : ";
cin>>p ;
cout<<" Rate of Interest : ";
cin>>r;
cout <<" Number of years : ";
cin>>t;
si= (p *r*t) /100;
amount = si + p;
}
void show( )
{
cout<<"\n Principle Amount: "<<p;
cout <<"\n Rate of Interest: "<<r;
cout <<"\n Number of years: "<<t;
cout <<"\n Interest : "<<si;
cout <<"\n Total Amount : "<<amount;
}
};
void main ( )
{
clrscr ( );
bank b ;
b.read ( );
b.show ( );
getch();
}

write a program calculate square and cube of given number using inline function

#include
#include
class line
{
public:
inline float multi(float a,float b)
{
return(a*b);
}
inline float cube(float a)
{
return(a*a*a);
}
};
void main()
{
line obj;
float a1,b1;
clrscr();
cout<<"\n Enter Two Value ";
cin>>a1>>b1;
cout<<" Multiplication is :"<<obj.multi(a1,b1)<<endl;
cout<<" Cube of val1 is :"<<obj.cube(a1)<<endl;
cout<<" Cube of val2 is :"<<obj.cube(b1)<<endl;
getch();
}

Write a program performing as calculator which allows all Arithmetic Operators with operands as input

#include<iostream>
using namespace std;
main ()
{
int a,b,result;
string arithmatic;
cout<<"the first value:";
cin>>a;
cout<<"the second value:";
cin>>b;
cout<<"apply some artimatic operations /, *, + or - :";
cin>>arithmatic;
if (arithmatic="/" )
result=a/b;
cout<<"a / b ="<<result;
if (arithmatic = "*")
result=a*b;
cout<<"a * b ="<<result;
if (arithmatic = "+")
result = a + b;
cout<<"a+b ="<<result;
if (arithmatic = "-")
result = a-b;
cout<<"a-b ="<<result;
else
cout<<"how is that? enter the value use arithmatic operations!";

return 0;
}

WELLCOME

Welcome to my blog.