CPSC 240-1 Midterm Programming Test #2 solved

$35.00

Category: You will receive a download link of the .ZIP file upon Payment

Description

5/5 - (1 vote)

Find the area of a triangle using Huron’s formula.
Somebody named Huron found a formula for computing the area of any triangle if only the
lengths of the three sides are known.
Huron’s formula is known in dozens of places on the web. For example, you can see it here:
https://en.wikipedia.org/wiki/Heron’s_formula
Your program will input 3 float numbers representing the lengths of three sides of one triangle.
Then it uses Huron’s formula to obtain the area.
For educational purpose we want to know that you know how to validate incoming numbers
as true float numbers. Therefore, validate the first inputted number. You may omit validating
the other two numbers. [If you can validate one input we assume you could validate all three.]
Program design
output_area receives one parameter of type double
output_error-message says “The inputted numbers do not form a triangle”.
triangle
C or C++
huron.asm
X84
r.sh
output_area
C or C++
output_error_message
C or C++
rg.sh
atof isfloat
Dialog with out errors
Welcome to Triangle Areas by Esther Mendoza
We find any area
Please enter the length of the first side: 3.0
Please enter the length of the second side: 4.0
Please enter the length of the third side: 5.0
The three sides are 3.00000 4.00000 5.00000
The semi-perimeter is 6.000000
The area of the triangle is 6.00000000 Have a nice day.
The area will be returned to the driver.
The main program received this number 6.0000 and will keep it.
I hope you enjoyed this triangle program. A zero will be sent to the OS. Bye.
Color codes
Yellow: Main driver function “triangle”
Blue: huron.asm
Green: output_area.c or output_area.cpp or output_error_message.cpp
Obviously replace Ester’s name with your own name.
Dialog with error in the first coefficient
Welcome to Triangle Areas by Esther Mendoza
We find any area
Please enter the length of the first side: 3.9W45
Please enter the length of the first side: 5.6.24
Please enter the length of the first side: 8.44$
Please enter the length of the first side: 8.5
Please enter the length of the second side: 4.0
Please enter the length of the third side: 5.0
The area of the triangle is 9.9999999 Have a nice day.
The area will be returned to the driver.
The main program received this number 9.99999 and will keep it.
I hope you enjoyed this triangle program. A zero will be sent to the OS. Bye.
Input validation is applied only to the first side of the triangle.
////The number 9.9999999 is a place holder. I did not have time to compute a correct number.
Dialog with error in the size of the triangle
Welcome to Triangle Areas by Esther Mendoza
We find any area
Please enter the length of the first side: 1.0
Please enter the length of the second side: 42.0
Please enter the length of the third side: 5.0
The three sides are 1.00000 2.00000 5.00000
The semi-perimeter is 7.000000
The inputted numbers do not form a triangle. The area is set to zero.
The area will be returned to the driver.
The main program received this number 0.0000 and will keep it.
I hope you enjoyed this triangle program. A zero will be sent to the OS. Bye.
Conclusion
Send me one file for each box in the diagram of page 2 except for atof. There is no file for
that function.
Send me two bash files. The second bash file is the gdb enabled bash file. I am going to use
the gdb enabled file to test run your program.
You do not need to include any gdb commands. Only send me rg.sh as a gdb enabled bash
file. Don’t send any gdb commands.
Send all these files as attachments to the usual place: holliday@fullerton.edu
See you later
Next week there are no class meetings. Have a feast. Enjoy the food.
After the Thanksgiving vacation week there are very few assembly subjects remaining. We
will probably study subnormal numbers and review the use of arrays. For the most part there
is nothing more to present in lectures. See you later.