(General math) a. Design, write, compile, and run a C++
b. Manually check the values computed by your program. After verifying that your program is working correctly, modify it to determine the area of a two-dimensional triangle with a base of 3.5 in and a height of 1.45 in.
(a)
Program plan:
In the coding window, write the necessary code:
- To Declarethree float variable base=1, height=1.5 and area.
- To calculate the area of triangle.
- To display the calculated area of triangleto user.
Program description:
The main purpose of the program is to calculate the area of triangle with the given height and radius.In the main method,calculating the area of triangle with the given base and height and finally, displaying the output of area of triangle to user.
Explanation of Solution
Given information:
Program:
Program code to calculate the area of triangle:
//importing essential header files #include<iostream> //using namespace standards usingnamespace std; //main method int main() { //declaring variables float base=1; float height=1.5; float area; //calculating area area=height*base/2; //displaying area to user cout<<"area of triangle with base "<<base<<" inch and height "<<height <<" inch is "<<area<<"sq. inch"; return0; }
Explanation:
In the main method, three float variable base=1, height=1.5 and area are declared. After that the area of triangle is calculated by using the below given formula:
And the finally, calculated results are displayed to user.
Output:
Output of the above given program code:
(b)
To verify the results produced by above program and then use the above program to calculate area of two-dimensional triangle whose base in 3.5in and height 1.5 in.
Explanation of Solution
Given information:
Explanation:
Firstly, verifying the results calculate by the above program.
Putting the given values in the above formula,
Thus, the calculated results are correct.
Now, modifying the program code to calculate the area of triangle with the given height =1.45 inch and base =3.5 inch.
Program code:
//importing essential header files #include<iostream> //using namespace standards usingnamespace std; //main method int main() { //declaring variables float base=3.5; float height=1.45; float area; //calculating area area=height*base/2; //displaying area to user cout<<"area of triangle with base "<<base<<" inch and height "<<height <<" inch is "<<area<<"sq. inch"; return0; }
Explanation:
In this program, in the main method, three float variable base=3.5, height=1.45 and area are declared. After that the area of triangle is calculated by using the below given formula:
And the finally, calculated results are displayed to user.
Output:
Want to see more full solutions like this?
Chapter 2 Solutions
C++ for Engineers and Scientists
- (C++ Programming) Question 1: Write a program which the user is asked to enter two integers. Then, the sum of these two integers and displayedon the screen. Question 2: Design a program using “For Loop” that will output the “seven” times table as follow:7 x 1 = 77 x 2 = 147 x 3 = 21:7 x 10 = 70arrow_forward(C++ CODE) A new video store in your neighborhood is about to open. However, it doesnot have a program to keep track of its videos and customers. The storemanagers want someone to write a program for their system so that thevideo store can operate.The program will require you to design 2 ADTs as described below: (C++)arrow_forward(C++) Write a function definition called quotient that takes as its parameters two decimal values, numer and denom, to divide. Remember that division by 0 is not allowed. If division by 0 occurs, display the message "NaN" to the console, otherwise display the result of the division and its remainder.arrow_forward
- (C PROGRAMMING ONLY) 1. Dealing With Monthsby CodeChum Admin We're done dealing with days. It's time to step up and now deal with months! Instructions: In the code editor, you are provided with a code in the main() which has 12 printf's. Each printf prints a month with its corresponding value. For this program, January is 1, February is 2, March is 3, and so on. When you run the initial code, you will encounter errors because these month names that have been printed don't exist yet.Your task is to create an enum data type which contains these month names as values so that when we run the code, there will be no more error.Do not edit anything in the main(). Output January = 1February = 2March = 3April = 4May = 5June = 6July = 7August = 8September = 9October = 10November = 11December = 12arrow_forward(Mathematical functions) a model of worldwide population, in billions of people, is given by this formula. Population = 6.0e0.02t Where t is the time in years (t=0 represents january 2000 and t = 1 represents january 2001). Using this formula, write a c++ program that displays a yearly population table for the years january 2005 through January 2010.arrow_forward(USING C++)A new video store in your neighborhood is about to open. However, it does not have a program to keep trackof its videos and customers. The store managers want someone to write a program for their system so thatthe video store can operate.arrow_forward
- (C++)Write a program that will allow a student to compute for his equivalent semestral grade. The program should ask the user should input his/her first name, last name, middle initial, and student number. After, inputting everything above, the output will clear the current screen and a new screen should open. A sample program that would clear a screen is included below for your reference. On the new screen, the user will then be greeted "Welcome, <firstname>! (i.e. Welcome, Louie!)" The program will then ask for the prelim grade, midterm grade and final grade of the student. The program should only accept grades 100 and below. After getting the three grades, the program should compute for the semestral grade. The computation of the semestral grade is as follows: 30%*PrelimGrade + 30%*midtermgrade + 40%finalgrade After inputting all the grades, the screen should clear again and will proceed to another screen. The new screen should output should output the following (this is…arrow_forward12. (Data processing) Write, run, and verify a C++ program that accepts three numbers as input, and then sorts the three numbers and displays them in ascending order, from lowest to highest. For example, if the input values are 7 5 1, the program should display them in the numerical macorder 1 5 7.arrow_forward( C++ ) Write a program in C++ to print the college name, location and area code (Higher College of Technology – Al Khuwair – 33) using symbolic constants COLLEGE, AREA, CODEarrow_forward
- (numerical analysis matlab) 3) It is requested to solve the X₁, X2,X3 unknowns in the given equation system by using Gauss-Jordan method. Find the result by writing a program. X1 X2 + x3 = 0 X2 + x3 = 0 3x12x2 + 3x3 = 0 -X1 X3 = 0 -arrow_forward(C PROGRAMMING ONLY) Make a code with the string function of strcat (with user input) THE REQUIRED OUTPUT IS INDICATED IN THE PICTURE. (THE OUTPUT SHOULD BE EXACTLY LIKE IN THE PICTURE)arrow_forwardNeed help, has to be done with <stdio.h> and <math.h>arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education