Question

1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<cmath>
using namespace std;

float sfun(float a, float b, float c) {
return (a+b+c)/2;
}

float areafun(float s, float a, float b, float c) {
return (sqrt(s*(s-a)*(s-b)*(s-c)));
}

int main()
{
   float a,b,c,s,Area;
   int tri, i=0;
   cout<<"\nEnter how many triangle values you want to calculate: ";
   cin>>tri;
   for(i=0; i<tri; i++) {
   cout<<"\nEnter three sides of triangle : ";
   cin>>a>>b>>c;
   s = sfun(a, b, c);
   Area= areafun(s, a, b, c);
   cout<<"Area of triangle "<<i+1<< " is : "<<Area;
   }
  
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program that reads unknown number of schools infymation (school name, number of teachers,...

    Write a C++ program that reads unknown number of schools infymation (school name, number of teachers, number of students) from a file called schools.txt and then displays a summary statistic of the information. Your program shall implement the following functions: double GetRatio (int Tn, int Sn): The function receives the number of teachers (Tn) and the number of students (Sn) on a school and it returns the ratio of the number of the students to the number of teachers (Sn/Tn)....

  • Write a C++ program that reads the values from a data file til the end of...

    Write a C++ program that reads the values from a data file til the end of the data file is reached. It displays the values read, and computes and displays the largest, smallest, and the average of these values

  • /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using...

    /4 Question An area of square, drea ofa rectangle and triangle can be calculated by using the given formula: sqareaa (renww value from the functioi area is reciabgle-(retrn valwe from the function is area int) ceouatre -D-(return value fromtheneion e s double t and s s formula must be use when the values for the sides of the triangle are whether you want to calculate the area of square or a. b and c are the sides of the triangle...

  • write a program that reads the three edges of a triangle (a, b, and c) and...

    write a program that reads the three edges of a triangle (a, b, and c) and displays the area and perimeter if the input is valid. Otherwise, display that the input is invalid. The input is valid if the sum of every pair of two edges is greater than the remaining edge. Note that area = √s(s-a)(s-b)(s-c), where s = ( a+b+c)/2

  • in c++ please. Write a program that reads the contents of a text file. The program...

    in c++ please. Write a program that reads the contents of a text file. The program should create a map in which the keys are the individual words found in the file and the values are the number of times each word appears. For example, if the word "the" appears 128 times, the map would contain an element with "the" as the key and 128 as the value. The program should either display the frequency of each word or create...

  • C++ Write a program that reads from the external file input.txt, counts the letters in every...

    C++ Write a program that reads from the external file input.txt, counts the letters in every word, replaces the word by that number, and then writes the numbers to an external file output.txt (Note: Do not forget to copy the blanks. You may wish to use infile.get and outfile.put in your program.) Also you may wish to use the strlen( ) function. Output: After the program generates output.txt, the code should display the contents of the file on the screen...

  • 1 // This program will input the value of two sides of a right triangle and...

    1 // This program will input the value of two sides of a right triangle and then 2 // determine the size of the hypotenuse. 3 4 // PLACE YOUR NAME HERE 5 6 #include <iostream> 7 #include <cmath> Il needed for math functions like sqrt() 8 using namespace std; 9 10 int main() 11 { 12 float a, b; // the smaller two sides of the triangle 13 float hyp; // the hypotenuse calculated by the program 14 15...

  • Write a program to compute the area of a triangle using side-angle-side method and reports the...

    Write a program to compute the area of a triangle using side-angle-side method and reports the area of that triangle (rounded to 2 decimal places). Side-angle-side formula: ???? = 1/ 2 ?? sin(?), where a and b are two sides of the triangle, and C is the included angle. Your program must meet the following criteria to receive full marks: • Randomly generate two values between 5 and 10 (inclusive) for two sides a and b of the triangle, respectively....

  • In C++, write a program that reads a postfix expression from an input file. Then, the...

    In C++, write a program that reads a postfix expression from an input file. Then, the program should evaluate the postfix format and display the results. Use these concepts for the program: 1) Struct Node 2) Enqueue and Dequeue 3) Push and Pop 4) DO NOT USE classes 5) Possibly Stack Precondition: The expression will be read from a file (input.txt) that contains a single line. There will be no spaces between the operands and the operators. The following operators...

  • Program in C++ with sample shots. Thank You. (55 pts) Write a class Triangle that provides...

    Program in C++ with sample shots. Thank You. (55 pts) Write a class Triangle that provides getSides, which returns the lengths of the three sides, and getAngles, which returns the degrees of the three internal angles. Then write a main function that randomly generates an array of triangles and finds the largest triangles first on the basis of area and then on the basis of perimeter

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT