Lab 2
Lab 2
Program
#include<iostream>
#include<cstdlib>
using namespace std;
float area(float r)
{
return(3.14 * r * r);
}
float area(float b,float h)
{
return(0.5 * b * h);
}
float area(float l,float b)
{
return (l * b);
}
int main()
{
float b,h,r,l;
int ch;
do
{
cout<<"\n\n *****Menu***** \n";
cout<<"\n 1. Area of Circle";
cout<<"\n 2. Area of Triangle";
cout<<"\n 3. Area of Rectangle";
cout<<"\n 4. Exit";
cout<<"\n\n Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1:
{
cout<<"\n Enter the Radius of Circle : ";
cin>>r;
cout<<"\n Area of Circle : "<<area(r);
break;
}
case 2:
{
cout<<"\n Enter the Base & Height of Triangle : ";
cin>>b>>h;
cout<<"\n Area of Triangle : "<<area(b,h);
break;
}
case 3:
{
cout<<"\n Enter the Length & Bredth of Rectangle : ";
cin>>l>>b;
cout<<"\n Area of Rectangle : "<<area(l,b);
break;
}
case 4:
exit(0);
default:
cout<<"\n Invalid Choice... ";
}
}while(ch!=4);
return 0;
}
2. Program 2
/**
* C program to find square and cube of a number using macro
*/
#include <stdio.h>
int main()
{
int num;
return 0;
}
3. PROGRAM 3
#include<i
ostream>
#include<conio.h>
int main(){
float p,t,r;
cout<<"Principle = ";cin>>p;
cout<<"Time = ";cin>>t;
cout<<"Rate = ";cin>>r;
cout<<"Simple Interest = "<<interest(p,t,r);
getch();
return(0);
}
4. Program 4
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void intrest(int p, int t, float ra=9.25);
int main()
{
char na[100];
int p,t,r,age;
clrscr();
cout<<endl<<"ENTER A NAME OF CUSTOMER:";
cin>>na;
if(age<60)
{
cout <<endl<< "Enter Principal Amount: ";
cin >> p;
cout <<endl<< "Enter Time in Years: ";
cin >> t;
intrest(p,t);
}
else
{
cout <<endl<< "Enter Principal Amount: ";
cin >> p;
cout <<endl<< "Enter Time in Years: ";
cin >> t;
cout <<endl<< "Enter intrest rate: ";
cin >> r;
intrest(p,t,r);
}
getch();
return 0;
}
void intrest(int p, int t, float ra)
{
float si;
si= p * t * ra / 100;
Program 5
#include<iostream.h>
#include<conio.h>
void main() {
int x, y;