C basic constructs and C functions
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
CMSC 216 Exercise
1
Objectives
To practice C basic constructs and C functions.
2
Overview
First copy the directory draw_figures under the exercises directory in the grace cluster. In particular, that
folder contains a .submit file that allows you to submit your project. Use the following command to copy the
directory to your 216 directory:
cp -r ~/216public/exercises/draw_figures ~/216
It is important that you develop your code in the draw_figures directory you copied.
For this assignment, you will write a program that draws rectangles and triangles. Before you read the specifi
cations, check the example provided in Section 11, Sample Output. It gives you a clearer picture of what your
program is intended to achieve. The explanatory prompt messages, error messages, and output messages that
are presented in the example, are exactly the ones you are required to use in your program.
3
Piazza
Make sure you are part of Piazza, otherwise you will not receive important information about class assign
ments. Check the first Canvas announcement for the Piazza course sign-up code.
4
Submit Server Time
This exercise is due at 11:00 pm. You will notice that in the submit server the due time is set to 11:01 pm. This
is because a submission that is done exactly at 11:00 pm is considered late by the submit server. I strongly
recommend you do not wait until the last minute to submit.
Before you do anything else, make sure you can submit your project. Information on how to submit assign
ments can be found in Section 8, Submitting Your Assignment.
5
Regarding Which Submission Gets Graded
In this course, the submission we grade is the one that has the highest score (only based on tests) in the submit
server. Please keep this in mind for all class projects / exercises. You should not wait until the programming
assignment is due to edit your code so it satisfies style requirements or any other requirements.
For example, for this exercise, 15 pts are associated with definining functions. The submit server does not
check for the functions, so you can pass all the submit server tests without them. The following scenarios are
possible:
1. Submission that passes some of the tests (test total 50 pts), but does not satisfy the functions requirement.
2. Submission that passes some of the tests (test total 49 pts), and satisfies the functions requirement.
We will grade the first submission, instead of the second. For the first one you will receive a total score of
50 pts; if we were to grade the second, 64 pts. One reason why we grade the first one is that we want you to
implement code (e.g., style and requirements from the beginning). Also, the submit server is limited in terms
of the options we have regarding project grading.
16
Specifications
1. The program will read an integer value representing a request. The possible request values are:
a. 0: Quit the program
b. 1: Draw a rectangle given a character, width, and length.
c. 2: Draw a triangle given a character and size.
d. 3: Other figure.
e. Any other value is considered invalid and the message "Invalid choice." will be printed.
2. The program will keep reading requests until 0 is provided.
3. The program will generate the message "Invalid data provided." if:
a. 0 or a negative value is provided for width, length, or size.
b. The character provided is not *, %, or # (these are the only valid characters).
4. The program will print the message "Bye Bye." before finishing.
5. Reading characters in C can be tricky as the newline character (enter) is considered a character. Use a
space in the scanf format string to ensure that spaces are skipped.
7
Other Requirements
1. Your grade will be based on the results obtained from the submit server. It is your responsibility to verify
that your program generates the expected results in the submit server (login and check).
2. Your program must be named exactly draw_figures.c, otherwise it will not compile in the submit
server.
3. All your C programs in this course should be compiled with gcc, with the options defined at
http://www.cs.umd.edu/~nelson/classes/resources/setting_gcc_alias.shtml
4. Your program should be written using good programming style as defined at
http://www.cs.umd.edu/~nelson/classes/resources/cstyleguide/
5. You must have a function called draw_rectangle that has width, length, and a character as parameters.
The function prints a rectangle based on the provided information. The function will return 0 if any
parameter is invalid (no figure printing will take place in this case). The function will return 1 if printing
took place.
6. You must have one function called draw_triangle that has size and a character as parameters. The
function prints a triangle based on the provided information. The function will return 0 if any parameter
is invalid (no figure printing take place) and 1 otherwise.
7. You must have a function called valid_character that determines whether a character used while draw
ing a rectangle or triangle is valid or not.
8. Do not use arrays for this assignment.
9. In the grace cluster you can verify whether your code is generating the expected results by using input
/ output redirection and the diff command.
210. By mistake you can create a huge file while using output redirection. For example, an infinite loop will
cause such a file. We get a notification when you are using a lot of disk space. Make sure that after using
output redirection, you remove all the result files you have created. Removing this kind of files applies
to all class programming assignments (projects and exercises).
11. You don’t need to implement option 3. We provided this option in case you would like to draw your
own figure. If you draw something nice/cool add the following comment at the top of your program:
/ GRADER OPTION 3 IMPLEMENTED /
This will allow us to identify students implementing option 3. You will not receive extra credit for
implementing this option. Some examples of how to generate colored text in C can be found in the
colors_in_c.c file.
8
Submitting Your Assignment
1. In the assignment directory (draw_figures), execute the command submit. After providing your direc
tory id and password, your code (.c file) will be uploaded to the submit server. (If the submit command
asks for other stuff, you are running an incorrect submit program, probably because your path setup is
not correct.) Notice that some additional files might be uploaded (don’t worry about it).
2. Your assignment must be electronically submitted by the on-time due date and time to avoid losing
credit. See the course syllabus for details.
3. Feel free to add any other functions.