CS 241L – Data Organization Spring 2021
Project 1
Total points: 20
Due
on Monday, 2/1/21 In this project, you will work in the Linux command
line and Emacs to write your first C programs. Follow the steps
outlined below to complete your project and be sure to use the Grading
Rubric provided at the end of this file as a guide for completing the
assignment.
Part 1: Redirecting output from stdout to a file
1. Connect to a CS machine (moons.cs.unm.edu or b146 lab machines) using
ssh with PuTTY, NoMachine, or the Terminal (Mac or Linux). 2. When you
login, type pwd. You should be in your home directory which has the
same name as your CS account username. 3. Create a directory called
project1 in your home directory. 4. Go to the project1 directory using
cd. 5. List contents of project1 using ls. It should have no files
and no subdirectories. 6. Open a new file called shapes.c with Emacs
7. shapes.c will contain the source code of a C program that prints the
shapes below:
______________ **** +
: : **** **** / \
: : **** **** / \
: : **** **** / \
: : **** **** / \
: : **** **** / \
: : **** **** / \
-------------- **** /_____________\ These shapes are in the file shapes.out provided to you.
Hint: Modify our “Hello, World” program to print these shapes. 8. Use the command:
gcc -Wall -pedantic -ansi shapes.c
to compile and create an executable called a.out. It should compile
without warnings or errors. If there are warnings or errors, edit your
source file. 9. Look into the contents of project1 with ls. Which files
are there now? 10. Now use ls with an option to list both details
(such as permissions, owner and group), and hidden files. What are these
options? (Hint: use a dash and two letters after ls. Which letters are
these?) 11. ls shows the contents of project1 on the terminal screen.
This is called the standard output stream, or stdout. You can redirect
this output to a file if you would like to save it using the symbol
>. Run the command:
ls > ls.out
12. Now type ls and
look at the list of files in stdout. You should see ls.out listed now.
13. Open ls.out with Emacs. What are its contents? They should list the
contents of running ls. Notice that ls.out is also included. You may
also notice a shapes.c~ file. This is a backup file created by Emacs.
14. Now run the executable typing in the prompt:
./a.out
15.
You should see on the screen the output of the shapes.c program. If you
do not see the shapes as displayed above, edit your source file. 16.
Redirect output of C program. Combine the steps in (11) and (14) above
to redirect the output of the shapes program to a file called
myshapes.out. What do you observe on the terminal screen? 17. Type ls
in the command prompt. Which files are there now? Update the ls.out file
using redirection (>) again.
Part 2: ASCII and data types
1. The characters printed in Part 1 are ASCII characters with given
values (see table from our lecture slides). The 7 characters printed in
shapes.out are
- _ / \ : + * What are their decimal values? 2.
Create a copy of your C program shapes.c with cp and name it
newshapes.c. 3. Modify newshapes.c so that it prints the same image as
in shapes.out but uses different characters. The ASCII decimal values of
the new characters are the decimal values of the original characters
(listed above in 1) minus 9. For instance, - has a 45 value in ASCII, so
the new character would be the one whose value is 36. This new
character will be printed where all - are placed originally in
shapes.out. Hints: - Make -9 a constant in your program called SHIFT
using
#define or const - Keep your program clear and concise by
declaring new variables when needed. 4. Compile newshapes.c with the
-Wall -pedantic -ansi options. 5. Run your new a.out executable and
redirect its output to a file called
mynewshapes.out. Note that an output file is not provided to you for comparison.
What to submit: The files:
ls.out
shapes.c
myshapes.out
newshapes.c
mynewshapes.out Note: Submit each file separately on Learn, do not combine them in a single zip file.
Grading
Rubric: + 1 pt: Your C programs start with a comment on top of the
file with your name and description of the programs + 2 pts: Your C
programs follow the class coding standards
+ 2 pts: You have
submitted the required files separately (you did not combine them into a
single zip file). + 5 pts: Your C programs compile with the -ansi
-pedantic -Wall options without errors or warnings. + 5 pts: Your output
file myshapes.out passes a diff test when compared with the output file
shapes.out that was provided to you. + 3 pts: Your output file
mynewshapes.out passes a diff test when compared with an output file
that only the TA has access to. + 2 pts: Your program newshapes.c
produces the correct output when the grader changes the value of SHIFT
to a different number where it is declared or defined.
学霸联盟