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...

  • 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....

  • this program is in C. Write a program that computes the number of elements in an...

    this program is in C. Write a program that computes the number of elements in an array divisible by a user specified number. Declare an integer array of size 7 and read the array elements from the user. Then, read a number k from the user and compute the number of elements in the array divisible by k. Consider the following example. 3 elements in this array are divisible by 2 ({2,2,4}). Sample execution of the program for this array...

  • 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

  • Write a C++ program that reads text from a file and encrypts the file by adding...

    Write a C++ program that reads text from a file and encrypts the file by adding 6 to the ASCII value of each character. See section 5.11 in Starting out with C++ for information on reading and writing to text files. Your program should: 1. Read the provided plain.txt file one line at a time. Because this file has spaces, use getline (see section 3.8). 2. Change each character of the string by adding 6 to it. 3. Write the...

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
ADVERTISEMENT