$30
CS 271 and 462
PA 1 - Programming Assignment 1
See the link "Linux Commands You Need to Know for This Class" in Module M01.
Reminder: Compiling a program that uses the math library requires an extra option.
gcc program1.c -o program1 -lm
"flags" or options for the compiler are preceded by a hyphen -
-o must appear immediately before the name of the executable
-lm (an "el", not a one) means that the math library is needed
Overview of This Assignment
In this assignment, you will create 2 C programs using the Kate editor. You'll upload the programs
to a CS Linux host, then compile and run them on Linux.
Once you have finished and tested the programs, you will upload them to the PA 1 assignment in
Canvas.
C Programming Skills That You Are Practicing in This Assignment
1. Writing a basic C program
2. Using standard C libraries
3. Declaring variables
4. Getting input and displaying output
5. Performing calculations using arithmetic operators and math functions
6. Making decisions with if statements
7. Documenting with comments
8. Debugging syntax errors
Before You Begin
Read the lecture notes from week 1 and review the sample programs that were done in class.
Read the "Style and Documentation Requirements".
As you go...Backup Your Work
Each time you work on an assignment, make a backup of your files. Some techniques for backup:
a. copy the files onto a USB drive
b. email the files to yourself
c. upload the files to cloud storage (OneDrive, GoogleDocs, Dropbox, etc)
The First Program: ramp.c
In this program you will calculate the dimensions of a wheelchair ramp. Here are some things you
need to know:
The maximum allowable slope in any new construction is 1:12. That means for every 1 inch
that the ramp rises vertically, there must be at least 12 inches horizontally.
A ramp that is more than 30 feet long (horizontally) must have a landing.
Your program must:
1) Have header comments. Place them before the #include statements. Example:
// CS 271 - PA 1
// Program name: ramp.c
// Your name
// Date you last worked on the program
2) Have at few inline comments.
3) Display a prompt and input the rise (decimal, inches).
4) Determine whether the ramp requires a landing. If it does, display the message "The ramp
requires a landing."
5) Calculate the horizontal distance that the ramp will cover and the ramp length ( the diagonal
/ hypotenuse).
6) Display the horizontal length (in feet) with a meaningful message. Limit the value to 1 digit
to the right of the decimal point.
7) Display the ramp length (in feet) with a meaningful message. Limit the value to 1 digit to the
right of the decimal point.
Test thoroughly.
The grading rubric is in Canvas. Note: Grading will include a check to see whether your
program correctly used the sqrt function from the math library.
The Second Program: ball.c
In this program you will calculate the volume of rubber needed to produce a rubber ball. Here are
some things you need to know:
The rubber ball is assumed to be a hollow sphere. You will need the formula for volume of a
sphere in order to proceed.
Your program must:
1) Have header comments. Follow the example shown above.
2) Have at few inline comments.
3) Display a prompt and input the exterior diameter (decimal, inches).
4) Display a prompt and input the interior diameter (decimal, inches).
5) Determine whether the diameter values that were input are reasonable (exterior diameter
must be larger than the interior diameter). If the values are not reasonable, display the
message "Exterior diameter must be larger than interior diameter."
6) Calculate the volume of rubber (cubic inches) needed to produce a rubber ball with the
given dimensions.
7) Display the volume of rubber needed with a meaningful message. Limit the value to 2 digits
to the right of the decimal point.
Test thoroughly.
The grading rubric is in Canvas. Note: Grading will include a check to see whether your
program correctly used the pow function from the math library.
Submit two files: ramp.c and ball.c
Make sure that you select the correct files and that both programs are uploaded
before you submit.
From the syllabus: "It is your responsibility to upload the correct files and to ensure that the uploaded files
contain the work that you want to have graded."