# How to write this program in C++



## GavinVG (Sep 9, 2011)

ASG207 — Area of a Triangle

The perimeter of a triangle is the sum of the lengths of all three sides. The semi-perimeter is ½ of
the perimeter. Given a triangle, the area of the triangle is as follows, where s is the semiperimeter.



	Write a program that inputs the three sides of a triangle and displays the area of that
triangle. Display the area to three decimal digits. Test the program with these three test runs.

	First test run with:     10 	   15 	      20
	Second test run with: 10 	     7.5 	      12.5
	Third test run with:    25.25 	   18.5 	       21.77





Learning objectives:
Algorithm design – IPO cycle
Use of cmath library
Practice meaningful nomenclature for variables
Interpretation of a complex formula into C++ statements.
Exercise working with formatting tools that C++ provides.
Work on aesthetics of the program output.


// Yea im suppose to do this by tomorrow i suck at this


----------



## mlee49 (Sep 9, 2011)

Well doing your homework isn't what the forums are for. Try talking to your TA or a person who has passed the course already.


----------



## Kreij (Sep 9, 2011)

Gavin said:
			
		

> // Yea im suppose to do this by tomorrow i suck at this



You'll always suck at it is you don't at least try to learn it on your own.
Write some code. We'l help you debug it if its not working.
We won't do your homework assignments for you.


----------



## a111087 (Sep 9, 2011)

Loooool.... This program is soooo easy...
I thought I was lazy, but you have opened my eyes. I now see myself as a hard worker, when compared to you, and for that I thank you. 

I've written long 3D translation programs in a few hours without reading the book or having too much experience with the language that was used.  I just used Google to search for proper operators to do what I wanted and examples of how to use them.  

I'm sorry if C++ is your first programming language.  It's not the easiest of all, but it isn't impossible to learn, so don't hope for us to do your homework.  We might help you if you have questions, but that is it.


----------



## FordGT90Concept (Sep 9, 2011)

Area of a triangle is (length * height) / 2, no?  Anything that involves division needs to be able to handle a floating-point decimal.

So...yeah...get to it.

_If at first you don't succeed, you're running about average._ --M.H. Alderson


----------



## GavinVG (Sep 9, 2011)

*Haha*

Yea i know it was. I really don't care. I got it done in 20 minutes or so. Yeah it was really easy i didn't even look at the program yet.


----------



## Kreij (Sep 9, 2011)

If you want, put up some code so we can see what you did.
I'm always interested in seeing other people's code.


----------



## GavinVG (Sep 15, 2011)

*Finished Product*

//Gavin
//9-7-11    
// Area of a Triangle
#include <iostream> //for cout
#include <iomanip> //for endl
#include <cmath> //power function
using namespace std;

int main()
{
//Declare identifiers

double area; //The Area of the triangle
double semiPerimeter; //Half of the total perimeter of the triangle
double sideOne; // Length of Side one of the triangle
double sideTwo; // Length of Side Two of the triangle
double sideThree; // Length of side Three of the triangle
double sMinusSideOne; // Next 3 lines are the Semi-Perimeter minus each of the sides
double sMinusSideTwo;
double sMinusSideThree;

// format floating-point values

cout<<fixed<<setprecision(3)<<showpoint;            // Set the decimal place to 3 places

//Input
cout <<"Enter Length of side One: ";                // Informs the user to enter the side length of the first side

cin >> sideOne;                // Captures the length of side 1 from the user

cout << "\n\nEnter Length of side Two: ";            // Same for side 2

cin>> sideTwo;                    // captures the length of side 2 from the user

cout << "\n\nEnter the Length of side Three: ";    // Same for side 3

cin >> sideThree;                // captures the length of side 3 from the user


//Process

semiPerimeter = ((sideOne+sideTwo+sideThree)/2);    // Calculates what the semiperimeter is

sMinusSideOne = semiPerimeter-sideOne;                // Calculates the first quantity

sMinusSideTwo = semiPerimeter-sideTwo;                // Calculates the second quantity

sMinusSideThree = semiPerimeter-sideThree;            // Calculates the third quantity

area = sqrt( semiPerimeter * sMinusSideOne * sMinusSideTwo * sMinusSideThree);    //Calculates the are of the triangle
//


//Output

cout<<endl<<endl;

cout<<"Area of the Triangle is: "; //Displayes what the area is

   cout<<area;                // Tells what the area is
   cout<<"units";            // Puts units after the number

   cout<<endl<<endl;



return 0;
}


----------

