The C++ code is as follows:
#include<bits/stdc++.h>
using namespace std;
double area(double a); // function signatures with different
parameter decalrations for each
double area(double a,double b);
double area(double a,double b, double c);
int main()
{
cout << "You want area of square(s) or rectangle(r) or
triangle(t)?" << endl; // taking the input
char c;
cin >> c;
if(c == 's') // if the user inputted s
{
cout << "Enter the length of side of the square" <<
endl;
double l;
cin >> l;
double size = area(l); // calling the function
cout << "The area of the square is " << size <<
endl;
}
if(c == 'r') // if the user inputted r
{
cout << "Enter the two sides of the rectangle" <<
endl;
double l,b;
cin >> l >> b;
double size = area(l,b); // calling the function
cout << "The area of the rectangle is " << size
<< endl;
}
if(c == 't') // if the user inputted t
{
cout << "Enter the three sides of the triangle" <<
endl;
double l,b,r;
cin >> l >> b >> r;
double size = area(l,b,r); // calling the function
cout << "The area of the triangle is " << size <<
endl;
}
return 0;
}
double area(double a) // for the square
{
return a*a;
}
double area(double a, double b) // for the rectangle
{
return a*b;
}
double area(double a, double b, double c) // for the triangle
{
double s = 0.5*(a+b+c);
double size = sqrt(s*(s-a)*(s-b)*(s-c));
return size;
}
Output ;
You want area of square(s) or rectangle(r) or triangle(t)?
s
Enter the length of side of the square
3
The area of the square is 9
You want area of square(s) or rectangle(r) or triangle(t)?
r
Enter the two sides of the rectangle
2
3.2
The area of the rectangle is 6.4
You want area of square(s) or rectangle(r) or triangle(t)?
t
Enter the three sides of the triangle
2.1
3.2
4.3
The area of the triangle is 3.21994
/4 Question An area of square, drea ofa rectangle and triangle can be calculated by using...
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 total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...
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....
(JAVA) Implement a Triangle class. Any triangle can be represented by its THREE sides. Therefore, your class will have THREE private member variables → side1, side2 and side3. Use the double data type to represent the triangle sides. In addition, please provide public methods that perform the following FIVE tasks: ▪ An input method that obtains the appropriate values for the three sides from the user. While entering the values of the three sides, please remember the triangle property that...
Problem a (PA4a.java) Write a program to evaluate the area of a triangle given the lengths of its sides using Heron's Formula. Here is an outline: Get the three side lengths from the user (which might have decimal values): a, b, c. Check to ensure that the sides are valid for a triangle. Importantly, the sum of the lengths of any two sides must be larger than the length of the third side (you must check all three sides this...
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...
) 8. Suppose a triangle is constructed where two sides have fixed length a and b, but the third side has variable length x You can imagine there is a pivot point where the sides of fixed length a and b meet, forming an angle of θ. By changing the angle θ, the opposite side will either stretch or contract (a) Let K(x)- Vs(s - a)(s -b)(s - x), where s is the semiperimeter of the triangle. Accord ing to...
I wrote a program which computes the area and perimeter of a square, circle, or rectangle. As you will see in my main function, there is a for loop in which the user is supposed to be able repeat the program until they enter "q" to quit. However, my program runs through one time, the prompt appears again, but then it terminates before the user is allowed to respond to the prompt again. I'm not able to debug why this...
Please can someone help me to finish this program? It is a C programming not a C++, when programming the program in linux I keep getting expected expression before || token, also please check if everything else is fine, maybe there is something else worng in my program and may ask me later to fix it, I am concern about the sin and cosine. The program is supposed to do all this: 1.Display a welcome message. 2.Prompt for the height...
what's the solution for the c++ project? PART1 Answer the following question in a Word document named as SP2019LAB7 PART1 YourlastName.docx Question1: What is the output of the following program? #include <iostream> using namespace std; int main() int count; int alpha(51: alpha[0] -4; for (count 1; count <5; count++) alpha[count] = 4 * count + 1 alpha(count 1] alpha[counk] -8; LAB7 cout << List elements: "; for (count = 0; count < 5; count++) cout <s alphalcount]<<"" cout<s endl; return...