Spring2011.CSCI340Homework2 History

Show minor edits - Show changes to output

Changed lines 142-143 from:
@@% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c @@
to:
% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c
Changed lines 142-145 from:
@@% submit csci340 hmwk2 ''files''@@

where @@''files''@@ are the names of your source files (e.g,
@@maxMinInt.c@@, @@pythagorean.c@@, etc.), as described above.
to:
@@% submit csci340 hmwk2 maxMinInt.c pythagorean.c evenSum.c diamond.c hypotenuse.c prime.c reverse.c @@
Changed lines 89-90 from:
Your programs should perform thorough error checking.
to:
Your programs should perform reasonably thorough error checking.
Changed line 2 from:
'''Due Date''': Friday, Feb. 18, 2011\\
to:
'''Due Date''': Monday, Feb. 21, 2011\\
Changed lines 61-62 from:
Use the following format precisely (user input in ''italics''):
to:
Use the following format precisely (user input in ''italics''):
Added line 70:
Added line 80:
Changed lines 37-38 from:
'''''A few more problems to be added soon...'''''
to:
'''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''

'''prime.c''' - An integer is said to be prime if it's divisible only by 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. Write a function, called @@isPrime()@@, which takes a single integer as argument and determines if it is a prime number (should return either 0 or 1). Then, use this function in a program that takes a single integer as input and outputs if the number is prime. It should keep looping until the user enters a zero integer.

Use the following format precisely (user input in ''italics''):
->Enter a single integer: ''6''
->The number 6 is not prime.
->Enter a single integer: ''11''
->The number 11 is prime.
->Enter a single integer: ''0''

'''reverse.c''' - Write a function that takes a single integer as argument and returns the number with all its digits reversed. Then, use this function in a program that takes a single integer as input and outputs the reverse of the value given. It should keep looping until the user enters zero.

Use the following format precisely (user input in ''italics''):
->Enter a number: ''1234''
->The reverse of 1234 is 4321
->Enter a number: ''8374''
->The reverse of 8374 is 4738
->Enter a number: ''0''
Changed lines 94-97 from:
@@% submit csci340 hmwk2 <files>@@

where @@<files>@@ are the names of your source files (e.g, @@maxMinInt.c@@, @@pythagorean.c@@, etc.), as described above.
to:
@@% submit csci340 hmwk2 ''files''@@

where @@''files''@@ are the names of your source files (e.g, @@maxMinInt.c@@, @@pythagorean.c@@, etc.), as described above.
Changed lines 37-38 from:
...
to:
'''''A few more problems to be added soon...'''''
Changed lines 1-2 from:
'''Assigned Date''': Monday, Jan. 24, 2011\\
'''Due Date''': Wednesday, Feb. 2, 2011\\
to:
'''Assigned Date''': Friday, Feb. 11, 2011\\
'''Due Date''': Friday, Feb. 18, 2011\\
Changed lines 20-21 from:
to:
'''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''

...

!!Details

Your programs should perform thorough error checking.
Changed lines 94-97 from:
@@% submit csci340 hmwk2 hmwk2.c@@

where @@hmwk2.c@@ is the name of your source file, as described above.
to:
@@% submit csci340 hmwk2 <files>@@

where @@<files>@@ are the names of your source files (e.g, @@maxMinInt.c@@, @@pythagorean.c@@, etc.), as described above.

(''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!)
Changed lines 110-112 from:
# Cooper, D. and Clancy, M. (1985) "Oh! Pascal", 2nd ed., W.W. Norton & Company, New York, p. 42.
to:
# 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".)-]
Added lines 1-87:
'''Assigned Date''': Monday, Jan. 24, 2011\\
'''Due Date''': Wednesday, Feb. 2, 2011\\
'''Due Time''': 11:50am

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

This is a '''solo''' assignment. You '''must''' work alone.

!!Purpose

This assignment focuses on familiarizing students with C, and in particular:

* structured program development
* various operators (e.g., arithmetic, relational, logical, etc.)
* control structures (e.g., if, switch, for, while, etc.)
* functions (e.g., prototypes, scope rules, storage classes, etc.)

!!Assignment



!!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: HMWK2
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 hmwk2 hmwk2.c@@

where @@hmwk2.c@@ is the name of your source file, as described above.

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

For more information on the submit command, see the [[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.