Project 1 - Area of Triangle



Project 1 (15 points) Assigned: Tuesday, October 29, 2013Due: Tuesday, November 5, 2013, Noon120650CS-2301, System Programming for Non-majors, B-term 201300CS-2301, System Programming for Non-majors, B-term 2013Programming Assignment #1 —An Equation Solver AbstractOne of the original uses for computers was to solve equations quickly and accurately. In your science, math, and engineering courses you are introduced to many equations: the volume of a sphere, linear and angular momentum, area under a curve, and so on. Choose 3 distinct formulas from one or more of your courses and write a C program that reads in the parameters for each equation, computes the result of the formula, and prints the results. Each student should choose their own formulas, as long as they have 1 or more parameters to be entered during execution. Your README file, as well as the comments in your code, should explain what each formula does. Outcomes After successfully completing this assignment, you should be able to:–Develop a C program on a Linux platform Read in and print out numbers using formatting stringsDo ordinary calculations using floating point arithmeticBefore Starting Read the sections of your textbook on printf and scanf. An alternative is to execute in a Linux command shell any of the commands:–man printfman scanfinfo printfinfo scanfThe AssignmentWrite a C program called formulas.c to do the following:– Prompt the user for the parameters of equation 1.Calculate and print the results of equation 1.Prompt the user for the parameters of equation 2.Calculate and print the results of equation 2.Prompt the user for the parameters of equation 3.Calculate and print the results of equation 3.MathematicsThe number of parameters will likely vary based on the formula. For example, the volume of a cylinder would require the radius and height of the cylinder, while the area of a triangle would require 3 sets of x-y coordinates.Sample ExecutionThe following illustrates the program output and input for one formula, namely the area of a triangle. The program prompts are shown as non-bold and do not end with a new-line character, while the user responses are shown as bold and do end with a new-line character. All result lines end with the new-line character.Enter the x-coordinate of point A:- 1.05Enter the y-coordinate of point A:- -2.3Enter the x-coordinate of point B:- 1.115e+2Enter the y-coordinate of point B:- 64Enter the x-coordinate of point C:- -5.4Enter the y-coordinate of point C:- -3.14159265358979323846Area is 167.341Things You Need to KnowMost math functions return a single value, usually of type double. The arguments are generally any numerical value (usually type double or float). For some functions, such as sqrt(), if the argument is negative, the function will fail with an error and the result is undefined. (The program may or may not crash.)printf("string in double quotes", arg1, arg2, arg3, …)The string, which is enclosed in double quotes, contains zero or more conversion specifiers. Each conversion specifier begins with a '%' character that specifies how to convert the corresponding argument to printed characters. The ith conversion specifier corresponds to the ith argument following the string. For example, a conversion specifier '%f' says to treat the corresponding argument as a floating point number and print it with the default precision – e.g., 3.14159. The conversion specifier '%6.2f' says to treat the corresponding argument as a floating point number and print it right justified in a field at least six characters wide, including two digits of precision after the decimal point. An introduction to printf() can be found in your textbookscanf("string in double quotes", &arg1, …)The string, which is enclosed in double quotes, contains one or more conversion specifiers. For this assignment, one conversion specifier is sufficient. As with printf(), each conversion specifier begins with a '%' character that specifies how to convert the input characters into a numerical or other value. The ith conversion specifier corresponds to the ith argument following the string, which must be the name of a variable and which must be preceded by a '&' character. (We will learn about the meaning of the '&' operator later in the course.) For example, a conversion specifier '%f' says to treat the input string as a floating point number with optional sign and optional exponent and store it in the variable named by the corresponding argument. The variable must be declared as float. To access both printf() and scanf(), you need to include the header file <stdio.h>. To access any math function (sqrt, cos, exp, …) you need to include <math.h>, and you need to specify –lm on the gcc command line.Assumptions and RestrictionsThere are no restrictions on the input data; that is, the user may enter any real or integer values for the parameters. You should not define any functions in the solution for this program other than the main() function. You should not use any loops or conditional statements (both of which will be introduced in the course later).DeliverablesWrite a short file called README.txt, README.doc , or README.pdf that summarizes your program, how to run it, and any problems that you had. This assignment is named PA1 in the using web-based Turnin system. You can access Turnin from any browser at the following URL:– submitted after Noon on the due date ( REF Due_date \h Tuesday, ) will be tagged as late, and will be subject to the late assignment policy. GradingThis assignment is worth fifteen points. Your program must compile without errors in order to receive any credit. It is suggested that before your submit your program, compile it again one more time to be sure that it does not blow up.Correct compilation without warnings using –Wall — 2 pointsCorrect usage of scanf() to get inputs from user — 4 pointsCorrect usage of printf() to print the various lines of output — 4 points outputsCorrect answers with the TA’s test cases — 2 pointsAdequate documentation and README file --- 3 points ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download