/*
    Name:Assignment 1
    Author: muguangde
    Date: 07/16/2014-11.57.AM
    Description: This is the code used to calculate area and hypotenuse of
    a triangle,with the input of length of two sides. Result is written into
    a file named result1.txt
*/

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <fstream>

using namespace std;

/**********************************************************/

//Print the prompt for the user
void promptUser()
{
    cout<<"Please enter the length of two sides for the triangle:"<<endl;
    cout<<"Enter two zeros to stop."<<endl;
}


int main()
{
    float side1,side2,hypotenuse,area,sumOfS;
    void promptUser(void);


    ofstream outfile;
    outfile.open("result2.txt");

    promptUser();
    cin>>side1>>side2;
    //Loop begin
    while(side1>0)
    {
        hypotenuse=pow((pow(side1,2)+pow(side2,2)),0.5);
        sumOfS=(side1+side2+hypotenuse)/2.0;
        area=pow(sumOfS*(sumOfS-side1)*(sumOfS-side2)*(sumOfS-hypotenuse),0.5);

        outfile.setf(ios::fixed,ios::floatfield);
        //To print the output in a file
        outfile.precision(2);
        outfile <<"\nWhen side one is " <<side1<<" and side two is "
        <<side2<<" the hypotenuse is "<<hypotenuse<<" and the area is "
        <<<area<<endl;
        
        promptUser();
        cin>>side1>>side2;
    }//end of the loop

    outfile.close();
    system("PAUSE");
    return 0;
}

  
回到主页 回到目录