CS2301 - B-term 11

Homework 1
Calculate the Perimeter and Area of a Triangle

Due: Tuesday, November 1 at 5pm

Read the expectations on homework. You will be doing this assignment and all subsequent homework assignments individually.

Outcomes

After successfully completing this assignment, you will be able to...

Before Starting

Read Chapters 1 and 2 of Kernighan & Ritchie. Details about scanf() and printf() can be found in sections 7.2 and 7.4.

The Assignment

Write a C program called triangle.c that does the following:

The formula for determining the length lAB of the line between points (xA, yA) and (xB, yB) is

  _________________
 (xA -xB)2+(yA -yB)2 

If lAB, lBC, and lCA are the lengths of the three sides of a triangle, then the area of the triangle is

  _____________________________
 s * (s - lAB) *(s - lBC) *(s - lCA)  

where s is half the perimeter of the triangle.

Include files

The sqrt() function returns the square root of its argument. The argument may be any non-negative numerical value, and the result returned by sqrt() is of type double. If the argument is negative, sqrt() fails with an error and the result is undefined.

Assumptions and Restrictions

There are no restrictions on the input data; that is, the user may enter any real or integer values for the x- and y-coordinates of each of the three points of the triangle. Do not use loops, conditionals, arrays, user-defined functions (other than main) or any other constructs/statements that haven't yet been covered in class.

Sample Execution

Enter the x-coordinate of point A:  1.05
Enter the y-coordinate of point A:  2
Enter the x-coordinate of point B:  1.115e+2
Enter the y-coordinate of point B:  21.1
Enter the x-coordinate of point C:  -25
Enter the y-coordinate of point C:  -3.14159265358979323846

Length of AB is 112.089
Length of BC is 138.636
Length of CA is 26.553
Perimeter is 277.278
Area is 35.181

Deliverables

Write a short text file called README.txt that summarizes your program, how to run it, and detailing any assumptions and any problems you had. (You can use kwrite to create your README.txt file.) From your Linux account, submit your C source code file and your README.txt file using the following turnin command:

/cs/bin/turnin submit cs2301 PROJECT1 triangle.c README.txt

Programs submitted after 5pm on Nov 1 will be tagged as late, and will be subject to the late homework policy.

Grading

This assignment is worth 15 points. Your program must compile without errors in order to receive any credit. It is suggested that before you submit your program, compile it again one more time to be sure it compiles correctly.