Spring2012.CSCI340Homework1 History

Hide minor edits - Show changes to output

Added lines 57-60:
->'''NOTE:''' You may use the @@[[http://www.cs.cf.ac.uk/Dave/C/node17.html | math.h]]@@ library. If so, you must include the @@-lm@@ argument in the complication command, e.g.,

->@@%gcc hypotenuse.c -lm@@
Added lines 1-134:
'''Assigned Date''': Friday, Jan. 20, 2011\\
'''Due Date''': Monday, Jan. 30, 2011\\
'''Due Time''': 10:50am

Last modified on {$LastModified} (see [[http://www.cs.cofc.edu/~manaris/?n=Spring2012.CSCI340_Homework1?action=diff&source=n&minor=n | updates]])

This is a '''solo''' assignment. You '''must''' work alone. However, you are allowed to ask classmates for her help with Unix commands, and vi commands.

!!Purpose

* Learn and apply the fundamentals of the Unix OS (architecture, file system, editor, basic utilities and shell commands).
* Learn and apply the C programming language for systems development (on Unix environments).

!!Assignment

'''maxMinInt.c''' - Write a program that reads in five integers and then determines and prints the largest and the smallest.

Use the following format precisely (user input in ''italics''):

->Enter five integers: ''3 4 1003 -3 3''
->The smallest is -3 and the largest is 1003.

'''pythagorean.c''' - Write a program that reads in three nonzero integers and determines if they correspond to sides of a right triangle. It keeps looping until the user enters three zero integers.

Use the following format precisely (user input in ''italics''):

->Enter three integers: ''3 4 5''
->Integers 3, 4, and 5 are Pythagorean triples.
->Enter three integers: ''1 2 3''
->Integers 1, 2, and 3 are not Pythagorean triples.
->Enter three integers: ''0 0 0''

'''evenSum.c''' - Write a program that calculates and prints the sum of all even integers from 2 to X (inclusive), where 'X' is an integer value provided as input. It should keep looping until the user enters 0.

Use the following format precisely (user input in ''italics''):

->Enter your max number: ''6''
->The sum of all even numbers from 2 to 6 is 12
->Enter your max number: ''2''
->The sum of all even numbers from 2 to 2 is 2
->Enter your max number: ''0''

'''diamond.c''' - Write a program that outputs the following shape. You may use @@printf@@ statements that print either a single asterisk or a blank. Maximize use of nested @@for@@ loops and minimize use of @@printf@@ statements. Define a constant, @@MAX_WIDTH@@, to make your code easy to maintain - i.e., for the following output, use @@#define MAX_WIDTH 9@@.

*
***
*****
*******
*********
*******
*****
***
*

'''hypotenuse.c''' - Define a function, called @@hypotenuse()@@, which calculates the length of the hypotenuse of a right triangle when the other two sides are given as arguments to the function. Then, use this function in a program that accepts 2 integers as input and outputs the length of the hypotenuse. It should keep looping until the user enters two zero integers.

Use the following format precisely (user input in ''italics''):

->Enter two triangle sides: ''3 4''
->The hypotenuse of the right triangle with sides 3 and 4 is: 5
->Enter two triangle sides: ''0 0''

!!Details

Your programs should perform reasonable error checking.

!!Documentation

Follow the Golden Rule of Style: "A program should be as easy for a human being to read and understand as it is for a computer to execute." [1]

In general, you should comment any variable, obscure statement, block of code, etc. you create.

Also, you should comment '''why''' something is being done, e.g.,

(:source lang=C tabwidth=3 -trim :)
numStudents += 1; /* we have processed one more student */
(:sourcend:)

as opposed to '''how''' it is done, e.g.,

(:source lang=C tabwidth=3 -trim :)
numStudents += 1; /* increment numStudents by one */
(:sourcend:)

Finally, your code should always include opening comments as follows.

(''NOTE:'' Angle brackets signify information that needs to be filled out. '''Remove''' the angle brackets!)

(:source lang=C tabwidth=3 -trim :)
/*
Author: <Your Name(s)>
Email: <Your email address(es)>
Class: CSCI 340, Section 1
Assignment: HMWK1
Due Date: <The assignment's due date>

Certification of Authenticity <remove one of the following>:

I certify that this lab is entirely my own work.

I certify that this lab is my own work, but I received
some assistance from: <Name(s)>

TASK: <Provide a simple, yet complete description of the task being
performed by this program. It may be several sentences long.>

INPUT: <Describe the input to this program. Be thorough.>

OUTPUT: <Describe the output to this program. Be thorough.>

*/
(:sourcend:)

!!Submissions

You will submit your assignment via the stono @@submit@@ command, as follows:

% submit csci340 hmwk1 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c

(''NOTE:'' Make sure you submit '''all''' your files with a single submit command. Otherwise, the latest submitted files will overwrite any previous ones - even if they have different names!)

No other submission mechanism will be accepted (e.g., email).

For more information on the submit command, see the [[http://www.cs.cofc.edu/~manaris/?n=Spring2011.SubmitManPage | submit man page]].

!!Grading

Your assignment will be graded based on the documentation, formatting, and correctness of your source code. Also the completeness / thoroughness of your work, and how well you followed the homework instructions.

!!Reference

# Cooper, D. and Clancy, M. (1985) "Oh! Pascal", 2nd ed., W.W. Norton & Company, New York, p. 42.

[-(This assignment was adapted from Deitel & Deitel, "C - How to Program".)-]