CPSC 240 Assignment 5: Area of Triangle

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Learning goals

= Gain familiarity with the use of SSE (xmm) register

 

= Validate incoming float numbers

 

= Convert valid strings to IEEE quad numbers

 

 

General statement

 

Make a program that will input three quadword float numbers representing the sides of a triangle.  After confirming that the inputs are in fact valid floats then computer the area of the triangle using Heron’s formula.

 

 

Modular structure of the program

 

 

 

Notes: atof is in a C++ library.  You’ll have to web search to find exactly which library.

 

The function isfloat receives a character array and returns a bool.  Maybe, it already exists or maybe you have to make one.  isfloat is the counter part to isinteger that appeared in Assignment 2.  isfloat should not be very hard to make.

 

 

 

 

Dialogue showing valid inputs

 

 

Welcome to Area of Triangles by Lancaster Marshall

 

This program will compute the area of your triangle.

 

Enter the floating point lengths of the 3 sides of your triangle.

 

Side 1:  3.85

Side 2:  5.177

Side 3:  4.141789588

 

These values were received:  3.8500000   5.1770000   4.14178959

 

The area of this triangle is 12.8532176 square meters

 

The driver received this number 0x402B5A6600000000, and will keep it.

 

Now 0 will be returned to the operating system.  Bye

 

 

 

Dialogue showing invalid inputs

 

Welcome to Area of Triangles by Lancaster Marshall

 

This program will compute the area of your triangle.

 

Enter the floating point lengths of the 3 sides of your triangle.

 

Side 1:  +45.83

Side 2:  32.5CA9

Side 3:  54.6

 

An invalid input was detected.  Please run the program again.

 

The driver received this number 0x0000000000000000, and will keep it.

 

Now 0 will be returned to the operating system.  Bye

Dialogue showing invalid inputs

 

Welcome to Area of Triangles by Lancaster Marshall

 

This program will compute the area of your triangle.

 

Enter the floating point lengths of the 3 sides of your triangle.

 

Side 1:  ++++15.6

Side 2:  31.7

Side 3:  19.85

 

An invalid input was detected.  Please run the program again.

 

The driver received this number 0x0000000000000000, and will keep it.

 

Now 0 will be returned to the operating system.  Bye

 

Another dialogue showing invalid inputs

 

Welcome to Area of Triangles by Lancaster Marshall

 

This program will compute the area of your triangle.

 

Enter the floating point lengths of the 3 sides of your triangle.

 

Side 1:  9.999999

Side 2:  8.55

Side 3:  6BFFF

 

An invalid input was detected.  Please run the program again.

 

The driver received this number 0x0000000000000000, and will keep it.

 

Now 0 will be returned to the operating system.  Bye

 

 

Programmer’s choice

 

The dialogues above show the rejection message after all three inputs have been entered.  You may choose to show the rejection message immediately after the first invalid input.  Why waste the user’s time inputting more numbers if the first input is know to be invalid?  You decide how you want to interact with the user.

 

 

Technology involved

 

Notice how this program is similar to Assignment 2.  In that assignment you validated incoming strings to be true integers using the library function isinteger.  After that the string was converted to an long integer.

 

In assignment 5 you validate incoming strings to be true floats.  If it is a true float they you convert the string to be a real double.

 

 

Tools available

 

In the public library <cstdlib> there is available the function atof, which converts a string to a double.   The name ends in ‘f’, but when I web searched for the use of atof the information provided said that it converts char arrays to 64-bit doubles.  That’s good.

 

In assignment 2 you had the function “isinteger.cpp”   I did a quick search for the corresponding function “isfloat.cpp”, but I can’t find one.  That was a very quick search.  Maybe you can find it.  I think I will ask your classmate Bilal to make one for the public library.  In fact he probably already has one that he will share.

 

 

Summary

 

Assignment 5 is the floating point version of Assignment 3.

 

The professor believes you can all web search for the Heron formula for the area of a triangle.

 

Last day to receive extra credit:   November 30, 2020 before 1:59am.

 

 

 

 

This document is a draft.  Minor upgrades may occur.  Check back later for updates.

 

 

 

 

 

 

 

 

The images in this document were made by Libre Office word processor from www.libreoffice.org and saved in the open source format “.odt”.  Sometimes when odt files are opened in closed source word processors the images do not display correctly.