Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Read three sides (S1, S2 and S3) of a triangle from input file \"Data.txt\" to c

ID: 3818679 • Letter: R

Question

Read three sides (S1, S2 and S3) of a triangle from input file "Data.txt" to check if the triangle is an equal triangle or not. There will be three cases according sides values: Equal triangle if all sides are equal. Then compute the perimeter (P) and area (A) of triangle. P = S1 + S2 + S3 A = Squareroot (P/2)(P/2 - S1)(P/2 - S2)(P/2 - S3) Not equal triangle if sides are not equal. Then compute the perimeter and area of triangle as shown above. Not triangle if one side or more, is less than or equal zero. Then skip the iteration to read next triangle sides. Write boolean function isEqTri which returns either true if the triangle is equal or false if not. The three sides should be passed by values to the function. Write void function calTri to calculate the area and perimeter of triangle. This function will have five parameters: three sides by values and, area and perimeter by reference. main function should call above functions and use input file to produce an output file as shown below. The program should ask the user for the name of output file. Your solution must: i. Contain all necessary comments (including your ID and name on the top; -5% if not included) ii. Use proper naming style and line indentation iii. The output must be properly aligned as in the sample output (use 2 decimal place for all floating numbers) iv. Submit to Moodle the C++ program (named LT2A_99999.cpp)

Explanation / Answer

//Area of triangle.. code here...

#include <iostream>

#include <fstream>

#include<math.h>

void p_area(float s1, float s2, float s3);

bool isEqTri (float s1, float s2, float s3);

using namespace std;

int main(){

float data[10][10];

ifstream file("D:/program/data.txt");

if (file.is_open())

{

for (int i = 0; i < 7; ++i) {

for (int j = 0; j < 3; ++j) {

file >> data[i][j];

}

}

file.close();

}

else cout << "Unable to open file";

//file.close(); */

cout<< "s1"<<' '<<"s2"<<' '<<"s3"<<' '<<"Area"<<' '<<"Perimeter"<<' '<<' '<<"comments";

for (int i = 0; i < 7; ++i) {

cout<<' ';

for (int j = 0; j < 3; ++j) {

cout << data[i][j] << ' ';

}

p_area(data[i][0], data[i][1],data[i][2]);

}

}

void p_area(float s1, float s2, float s3){

if(s1>0&&s2>0&&s3>0){

float p=s1+s2+s3;

float p1= (s1+s2+s3)/2;

float a=p1*(p1-s1)*(p1-s2)*(p1-s3);

cout<<sqrt(a)<<' ';

cout<<p<<' ';

if(isEqTri(s1,s2,s3)) cout<<"Equal Triangle";

else cout<<"Not Equal Triangle";

}

else {

cout<<"****"<<' ';

cout<<"****"<<' ';

cout<<"Not accepted sides,try again..";

}

}

bool isEqTri (float s1, float s2, float s3){

if(s1==s2&&s2==s3)

return true;

else return false;

}

output:

s1 s2 s3 Area Perimeter comments

4.5 5.5 6.555 12.2309 16.555 Not Equal Triangle

0 4.56 2.9 **** **** Not accepted sides,try again..

6.982 7.53 6.4 20.7627 20.912 Not Equal Triangle

2.5 2.5 2.5 2.70633 7.5 Equal Triangle

-3 5.678 5.01 **** **** Not accepted sides,try again..

6 6 6 15.5885 18 Equal Triangle

9.3 10.032 -6.0213 **** **** Not accepted sides,try again..