Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: TurboC
make a function that will compute the area of a rectangle, square ang circle. help me pls.
Posted 10-Mar-11 0:34am
Edited 10-Mar-11 15:11pm
v2
Comments
Amit Kumar Tiwari at 10-Mar-11 5:38am
   
Homework :D lol
I used to do this in 5th standard.
SAKryukov at 10-Mar-11 5:40am
   
This is beyond the evil and the good...
You're probably at the wrong forum.
--SA
Ryan Zahra at 10-Mar-11 5:43am
   
Before starting any code, you should learn to use google first. Good luck :)
AlbinAbel at 10-Mar-11 7:09am
   
Area of a square and rectangle don't have different formula. That's what my teacher taught me at 5th standard. Why you want it separate
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

have tries google
then also seen below
Program to calculate area of geometric figures.
#include<iostream.h>
#include<math.h>
void main()
{
               char character;
               double area;
               cout<<"circle(c)
";
               cout<<"square(s)
";
               cout<<"rectangle(r)
";
               cout<<"triangle(t)
";
               cout<<"Select c,s,r or t:";
loop:
               cin>>character;
               if((character=='c')||(character=='C'))
               {
                                double r;
                                const double pi=3.142;
                                cout<<"Enter radius:";
                                cin>>r;
                                area=pi*pow(r,2);
               }
               else if((character=='s')||(character=='S'))
               {
                                double l;
                                cout<<"Enter length:";
                                cin>>l;
                                area=pow(l,2);
               }
               else if((character=='r')||(character=='R'))
               {
                                double l,w;
                                cout<<"Enter length:";
                                cin>>l;
                                cout<<"Enter width:";
                                cin>>w;
                                area=l*w;
               }
               else if((character=='t')||(character=='T'))
               {
                                double b,h;
                                cout<<"Enter base:";
                                cin>>b;
                                cout<<"Enter height:";
                                cin>>h;
                                area=h*b/2;
               }
               else
               {
                                cout<<"Select only c,s,r or t:";
                                goto loop;
               }
               cout<<"Area:"<<area<<endl;
}
  Permalink  
Comments
Amit Kumar Tiwari at 10-Mar-11 5:43am
   
Outstanding my 5+ :)
santosh dhanawade at 10-Mar-11 6:03am
   
Thanks you so much
AlbinAbel at 10-Mar-11 7:10am
   
are the area of a square and rectangles have different formulae? Though the properties are different. New to me.
William Winner at 10-Mar-11 12:21pm
   
Are you asking if you can calculate the area of a square differently than a rectangle? Of course you can. And of course, you can use the same equation as for a rectangle. A square is a rectangle with the same width and height, so instead of asking for width and height and multiplying them, you can just ask for one dimension and square it...as the author did here.
William Winner at 10-Mar-11 12:20pm
   
Generally, we don't write people's homework for them. It would have been better to give them hints in the proper direction and/or asking more specific questions about what problems they are having.
 
Have you heard the phrase, "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime."
 
While it was very kind of you to provide the full code, you aren't really helping him by doing so.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Well your solution is here - http://www.blurtit.com/q6427049.html[^]
  Permalink  
Comments
princessdiane at 10-Mar-11 20:08pm
   
do you have a C?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Square = l^2
Rectangle = l*w
Circle = πr^2
 
What more do you need?
 
Just define the variables and apply the formulae.
 
Simples.
  Permalink  
Comments
princessdiane at 10-Mar-11 20:29pm
   
can you check if i have a mistake here. the answers are all zero
 
#include
 
int l,wd,r,s;
double pi=3.14;
 
double Rectangle()
{
double rec;
rec=l*wd;
return(rec);
}
 
double Square()
{
double squ;
squ=s*s;
return(squ);
}
 
double Circle()
{
double cir;
cir=pi*(r*r);
return(cir);
}
 
void entry()
{
printf("Enter length\t: ");
scanf("%d",&l);
printf("Enter width\t: ");
scanf("%d",&wd);
printf("Enter radius\t: ");
scanf("%d",&r);
printf("Enter side\t: ");
scanf("%d",&s);
}
 
main()
{
double area;
clrscr();
entry();
printf("\n");
area=Rectangle();
printf("The area of Rectangle is : %g\n",area);
area=Square();
printf("The area of Square is\t : %g\n",area);
area=Circle();
printf("The area of Circle is\t : %g\n",area);
getch();
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 230
3 Aajmot Sk 191
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100