Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
make a function that will compute the area of a rectangle, square ang circle. help me pls.
Posted
Updated 10-Mar-11 14:11pm
v2
Comments
Wild-Programmer 10-Mar-11 5:38am    
Homework :D lol
I used to do this in 5th standard.
Sergey Alexandrovich Kryukov 10-Mar-11 5:40am    
This is beyond the evil and the good...
You're probably at the wrong forum.
--SA
Ryan Zahra 10-Mar-11 5:43am    
Before starting any code, you should learn to use google first. Good luck :)
Albin Abel 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

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;
}
 
Share this answer
 
Comments
Wild-Programmer 10-Mar-11 5:43am    
Outstanding my 5+ :)
[no name] 10-Mar-11 6:03am    
Thanks you so much
Albin Abel 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 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 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.
Well your solution is here - http://www.blurtit.com/q6427049.html[^]
 
Share this answer
 
Comments
princessdiane 10-Mar-11 20:08pm    
do you have a C?
Square = l^2
Rectangle = l*w
Circle = πr^2

What more do you need?

Just define the variables and apply the formulae.

Simples.
 
Share this answer
 
Comments
princessdiane 10-Mar-11 20:29pm    
can you check if i have a mistake here. the answers are all zero

#include<stdio.h>

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900