skip to main
|
skip to sidebar
C++ Programs
Based on cusat cs 3rd sem 2009 lab cycle
Monday, May 17, 2010
Function overloading.
11. Write a program to find the area of different shaped polygons like triangle, rectangle, square and circle using function overloading.
#include<iostream.h> #include<conio.h> #include<process.h> #include<math.h> void area(int); void area(float); void area(int,int); void area(int,int,int); void main() { int ch,a,b,c; float r; clrscr(); while(1) { cout<<"\n1.Circle\n2.Rectangle\n3.Triangle\n4.Square\n5.Exit"; cout<<"\nEnter the choice "; cin>>ch; switch(ch) { case 1: cout<<"\nEnter the radius "; cin>>r; area(r); break; case 2: cout<<"\nEnter the length and breadth "; cin>>a>>b; area(a,b); break; case 3: cout<<"\nEnter the three sides "; cin>>a>>b>>c; area(a,b,c); break; case 4: cout<<"\nEnter the side "; cin>>a; area(a); break; case 5: exit(0); default: cout<<"\nInvalid choice "; } cout<<"\n\nPress any key 2 continue "; getch(); clrscr(); } } void area(float a) { float area; area=3.14*a*a; cout<<"\n Area of circle "<<area; } void area(int a,int b) { cout<<"\n Area of rectangle "<<a*b; } void area(int a) { cout<<"\n Area of square "<<a*a; } void area(int a,int b,int c) { float s,area; if((a+b)>c&&(a+c)>b&&(b+c)>a) { s=(a+b+c)/2.0; area=sqrt(s*(s-a)*(s-b)*(s-c)); cout<<"\n Area of triangle "<<area; } else cout<<"\n Invalid sides "; }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
Home
8085 programming
Datastructure
Graphics programming
8086 Programming
LEX, YACC and parsers
Operating System
Programzz!
Add two date using operator overloading
Add two date using class
Decrement time by one using operator overloading(E...
Add two time using operator overloading(External q...
Compare two string. use operator overloading(Exter...
Matrix multiplcation(External Questn-2009)
Difference between two dates
Generic programming
File manipulation
Pure Virtual Function
Virtual Function
Multipath Inheritance
Hybrid Inheritance
Hierarchical inheritance
Addition of two distances using friend function
Class to class conversion
Basic to class and class to basic conversion
Operator functions as friend functions
Function overloading.
Static & Constant function
User defined string functions
Complex numbers using operator overloading.
Inline function
Add two time
Differnt temprature scale(Farenheit/celsius/kelvin).
Students details- using class
Students details- using structure
Check whether a date is valid or not
pass by value, pass by address, pass by refrence
Followers
Blog Archive
▼
2010
(29)
►
December
(2)
►
October
(4)
►
July
(1)
▼
May
(22)
Generic programming
File manipulation
Pure Virtual Function
Virtual Function
Multipath Inheritance
Hybrid Inheritance
Hierarchical inheritance
Addition of two distances using friend function
Class to class conversion
Basic to class and class to basic conversion
Operator functions as friend functions
Function overloading.
Static & Constant function
User defined string functions
Complex numbers using operator overloading.
Inline function
Add two time
Differnt temprature scale(Farenheit/celsius/kelvin).
Students details- using class
Students details- using structure
Check whether a date is valid or not
pass by value, pass by address, pass by refrence
About Me
Arun Ramesh
View my complete profile
No comments:
Post a Comment