Posts

Showing posts from December, 2011

Program for calculating Simple Interest using the concept of Default Arguments

//Program for Interest calculation using the concept of default arguments #include<iostream.h> #include<conio.h> void main() { float amount, principal; int time; float interest(float p, int n, float r=0.15); cout<<"Program for simple interest calculation"<<endl; cout<<"Please enter principal amount:"; cin>>principal; cout<<"Please enter Time: "; cin>>time; amount=interest(principal, time); cout<<"\nThe amount is:"<<amount; cout<<"\nPress any key to continue..."; getch(); } float interest(float p, int n,float r) { return (p+((p*r*n)/100.0)); }

Menu Driven Program for Area of various figures in C++

#include<iostream.h> #include<conio.h> #include<process.h> #include<math.h> float area(float); float area(float,float); float area(float,float,float); void main() { float a,b,c,s,ar; int ch; clrscr(); while(1) { cout<<"\nYou can chose from the following options:"<<endl; cout<<"Press 1: Area of Square"<<endl; cout<<"Press 2: Area of Rectangle"<<endl; cout<<"Preaa 3: Area of Triangle"<<endl; cout<<"Press 4: Exit"<<endl; cout<<"Please Enter Your choice(1-4):"; cin>>ch; switch (ch) { case 1: cout<<"Please Enter the Side of the Square:"; cin>>a; ar=area(a); break; case 2: cout<<"Please enter the Length and Breadth of the Rectangle:"; cin>>a>>b; ar=area(a,b); break; case 3: cout<<"Please enter three sides of the Triangle:"; cin>>a>

Program for Area calculation in C++

#include<iostream.h> #include<conio.h> class shape { float circle; float rect; public: shape() { circle=0; rect=0; } void area(float r) { circle=(3.14*r*r); cout<<circle; } void area(float h, float l) { rect=h*l; cout<<"\nThe area of rectangle is:"<<rect; } }; void main() { shape s1; int ch; float he,le,re; clrscr(); cout<<"****************************************************\n"; do { cout<<"\nTo calculate area of rectangle press    1 : \nTo calculate area of circle press     2 : \nTo exit from program please press     3 :\n"; cout<<"\nPlease Enter Your Choice:"; cin>>ch; switch(ch) { case 1: cout<<"Enter Hieght and length to calculate are of rectangle :\n"; cin>>he>>le; s1.area(he,le); break; case 2: cout<<"\nEnter radious to calculate are of circle :\n"; cin>>re; s1.area(re); break; } } while(c

Program for Checking whether the given number is Palindrome or not

Palindrome means a number which remains same if positions of its digits is reversed i.e., 1221 #include<stdio.h> #include<conio.h> void main() { int n,digit,rev=0,num; printf("enter the number"); scanf("%d",&num); n=num; do { digit=num%10; rev=rev*10+digit; num/=10; }while(num!=0); printf("reverse number is=%d\n",rev); if(n==rev) { printf("number is palindrome"); } else { printf("number is not palindrome") ; } getch(); }