Microsoft Word – AU 2021 CSE2421 Lab2
Autumn 2021 CSE 2421 LAB 2
DUE: Tuesday, September 14th, 2021, 11:30:00 p.m.
10 Bonus Points (i.e.,10% bonus) awarded if correctly submitted by Monday,
September 13th at noon.
Objectives/Skills:
Standard character-based I/O
Arithmetic/bitwise statements
loop statements
ASCII character representation
#ifdef preprocessor statements
Declaring variables of appropriate types to implement the program
using the make command to create 2 programs from one .c file
REMINDERS:
This lab is an individual assignment.
Waiting until the day this lab is due to start working on it would be a very bad idea.
If you don’t read the entire lab description thoroughly, you may miss some important information that
will help you.
Make a point to read the REQUIREMENTS section before writing any code and again, after you have
finished the lab. The second time through the REQUIREMENTS section, verify that each of the
requirements has been adhered to within your code. You’ll get more points that way.
Every lab requires a README file. For this lab, create your file on stdlinux in a text editor and it
should be named LAB2README (exactly this name (case matters), with no
“extensions”; Linux can identify the file as a text file without any “extension,” such as
txt, doc, etc., so do not use these). This file should include the following:
1. Required Header:
BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I HAVE STRICTLY ADHERED
TO THE TENURES OF THE OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY
WITH RESPECT TO THIS ASSIGNMENT.
THIS IS THE README FILE FOR LAB 2.
Student name:
2. Total amount of time in hours (approximate) to complete the entire lab;
3. Short description of any concerns, interesting problems or
discoveries encountered, or comments in general about the
contents of the lab;
4. Run gdb on your convert1 executable. Enter data here that
describes what interim values you looked at to verify that you
were calculating the floating-point value correctly. Specify the
gdb command you used to print the interim values and how the
values were displayed in gdb. For example, what is the value
of floating-point value after you have read and processed the
digits to the left of the decimal point then after you have
processed the value to the right of the decimal point, etc.
5. If you run gdb for any reason on convert2, then describe why
you chose to do so, what you did, what you saw. If you do not
do so, just say so here.
You should aim to always hand assignments in on time. If you are late (even by less than a
minute), you will receive 75% of your earned points for the designated grade as long as the
assignment is submitted by 11:30:00 pm the following day (NOTE: This is not necessarily
the same as the following class day!), based on the due date listed at the top of this
document. If you are more than 24 hours late, you will receive a zero for the assignment and
your assignment will not be graded at all (so you will get no feedback on your work). Start
early, and work steadily on the lab, and you should be able to hand the assignment in on time
without a problem. If you are unable to finish on time, you will need to consider whether it is
better to submit on time and get full credit for what you have done, or if it would be better
to try to finish and submit one day late with the 25% penalty.
Any lab submitted that does not build to an executable using the required gcc
command (see below) and run without crashing or freezing WILL RECEIVE AN
AUTOMATIC GRADE OF ZERO. No exceptions will be made for this rule – to
achieve even a single point on a lab your code must minimally compile (without
errors or warnings) and execute without crashing or freezing.
It is your responsibility to ensure that your program compiles without errors
or warnings and runs on valid input as described without crashing or freezing.
– We will be taking advantage of a feature of Unix/Linux called make to compile
executables and to create the .zip file needed to upload to Carmen.
You are responsible for making sure that your lab submits correctly.
Make yourself aware of the CODING_STYLE_IN_C file posted on Piazza in the General
Resources section.
GRADING CRITERIA
The code and algorithm are well documented, including an explanatory comment for
each function, and comments in the code.
A comment should be included in the main function of the program including
the programmer name(s) as well as explaining the nature of the problem and an overall
method of the solution (what you are doing, not how).
A comment should be included before each function documenting what the
function does (but not details on how it does it).
A short comment should be included for each logical or syntactic block of
statements.
The program should be appropriate to the assignment, well-structured and easy to
understand without complicated and confusing flow of control. We will not usually deduct
points for the efficiency of your code, but if you do something in a way which is clearly
significantly less efficient, we may deduct some points.
There is a description in LAB2README of the gdb results asked for both convert1
and convert2.
The results are correct, verifiable, and well-formatted. The program correctly performs
as assigned with both the given input and one other (unknown) input file designed to
test boundary conditions within your program.
If the grader cannot compile your code using the supplied Makefile with no
error or warning messages, you will receive 0 points for the lab. No exceptions.
LAB DESCRIPTION
PART 1:
If you are not using FastX, use a process like what you did to transfer files between your personal
device and stdlinux in lab1 to get a copy of the file Makefile.Lab2 to your lab2 directory on
stdlinux. You will need to change the name of Makefile.Lab2 to Makefile once you get it to
stdlinux.
If you are using FastX, from a window on stdlinux bring up a web browser and navigate
to the Piazza page for this class. Go to the Resources->Labs link and find a file called
Makefile.Lab2. Click on the filename. A window should pop up that says something
like:
You have chosen to open:
Makefile.Lab2
which is: BIN file (1.0 KB)
from: https://piazza-resuorces.s3.amazonaws.com
Would you like to save this file?
Click the Save File button.
You can now exit out of the web browser.
From your stdlinux window, maneuver to the directory $HOME/cse2421.
1. Create a lab2 directory.
2. Enter the lab2 directory.
3. Execute the following command: cp $HOME/Downloads/Makefile.Lab2 Makefile
4. Use the ls command to verify that you now have a file in your current working directory
called Makefile.
5. Use a text editor or the command cat Makefile to inspect the contents of the file. Do not
Your exact message may vary a little
make any changes/edits to this file. We will talk about the contents of this file and how it
works next week. For the time being, consider it magic.
This file will allow you to create both executables required for this lab and the .zip file
required for this lab. Once you have created a convert.c file, this Makefile will allow you
to create two separate, unique programs convert1 and convert2 using only one .c file.
A. To compile the executable for PART 2, enter the
command make convert1 on the command line.
B. To compile the executable for PART 3, enter the
command make convert2 on the command line.
C. To create the .zip file to submit to Carmen, enter the
command make lab2.zip on the command line.
D. If you want to do all three of these things at the same
time, enter the command make on the command line.
E. If you use the command make clean, all executable files
and the current .zip file will be deleted from your
directory. Your .c files will not be touched.
PART 2 (50%): Mandatory file name: convert.c
Mandatory executable name: convert1
Write a program that implements an algorithm that prints the binary representation for
either a 4-byte integer or a 4-byte floating point value. Each nibble is separated by a
space.
REQUIREMENTS
In this program:
1. You must adhere to the requirements in the file: Doing_Labs_in_this_Class.
2. you must create at least 6 different functions: int main(), int get_int(), float
get_float(), float get_fractional(), void print_bits(int inv_value), and void
print_bits_f(float *float_val_ptr). get_int() reads in the integer value to convert to
binary using ONLY the getchar() library function, then converts it to a single value
similar to what was done in lab1. get_float() does the same for the floating-point
value but must deal with the decimal point and call get_fractional() to compute the
value on the right side of the decimal point. print_bits() prints the bits of the integer
value, while print_bits_f() prints the bits of the floating-point value. The
print_bits_f() function is just a little tricky, so use this as the starting point of the
program:
a. call the program like this print_bits_f(&conv_value);
b. void print_bits_f(float float_val_ptr){
unsigned int print_value;
print_value = *((unsigned int *) float_val_ptr);
Then treat the value the same as you did for the integer value.
3. you must prompt the user whether they plan to input an integer or a floating point
vaue. You must use printf() to send the prompt to the user. You may use scanf() or
getchar() to read the response.
4. You may not use scanf() anywhere else within the program except as detailed in #3.
5. when a ‘\n’ character or EOF is detected, this indicates that the last character read in
(not the ‘\n’) was the last digit of the value to be converted,
6. you must use putchar() to print out each ‘0’ or ‘1’ value to stdout.
7. The format of the output should be in the form
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
where each x is either a ‘1’ or ‘0’.
8. You may not declare any arrays or allocate any dynamic memory.
Sample Output:
[jones.5684@cse-fl1 lab2] convert1
Do you want to convert an integer or a floating-point value?
integer = 1
floating point = 2
1
Enter the value to convert to binary: 5280
0000 0000 0000 0000 0001 0100 1010 0000
[jones.5684@cse-fl1 lab2]$ convert1
Do you want to convert an integer or a floating-point value?
integer = 1
floating point = 2
1
Enter the value to convert to binary: -52
1111 1111 1111 1111 1111 1111 1100 1100
[jones.5684@cse-fl1 lab2]$ convert1
Do you want to convert an integer or a floating-point value?
integer = 1
floating point = 2
2
Enter the value to convert to binary: 3.25
0100 0000 0101 0000 0000 0000 0000 0000
[jones.5684@cse-fl1 lab2]$ convert1
Do you want to convert an integer or a floating-point
value?
integer = 1
floating point = 2
2
Enter the value to convert to binary: -5066.375
1100 0101 1001 1110 0101 0011 0000 0000
[jones.5684@cse-fl1 lab2]$
NOTE!! The input above is not the only input that can be entered in to the program
The 2 floating point binary values
given here are correct. Don’t try to
understand it. If you want to verify
that floating point binary values are
correct, check here: IEEE-754
Floating Point Converter (h-
schmidt.net)
that will be expected to work correctly. It is only an example of input.
9. All source code files (.c files) submitted to Carmen as a part of this program must include the
following at the top of each file:
/* BY SUBMITTING THIS FILE TO CARMEN, I CERTIFY THAT I HAVE STRICTLY ADHERED
** TO THE TENURES OF THE OHIO STATE UNIVERSITY’S ACADEMIC INTEGRITY POLICY
** WITH RESPECT TO THIS ASSIGNMENT.
*/
If you choose not to put the above comment in your file, you will receive no points for this part of
the lab.
10. You must comment your code
11. You must put you name in a comment at the top of the source code file and your Makefile
12. All the code you write must be in the file convert.c.
13. You must correctly use preprocessor directives #ifdef PROMPT and #endif to
complete Part 3.
If you adhere to the requirements above, how you choose to write your program is up to you.
With each Systems 1 lab you will get more and more freedom with respect to your code. Not
using the correct I/O functions as specified above will result in a 50-point deduction.
PART 3. (50%). Mandatory file name: convert.c
Mandatory executable name: convert2
After you get convert1 working, introduce #ifdef PROMPT and #endif preprocessor
statements within your convert.c file that modify your program such that it will print no
output other than the 32-bit binary answer. Input will be coming from a redirected input
source on the command line. . It will help you understand how to do this if you inspect
the Makefile supplied with this lab, look at the comments and observe the options used
in the gcc statements ( such as -D PROMPT). If you chose not to read Chapter 14 of
the Reek book, you may want to reconsider at this point.
Sample output:
[jones.5684@cse-fl1 lab2] convert2 < convert.input 1111 1111 1111 1111 1111 1101 1101 0101 [jones.5684@cse-fl1 lab2]$ In this example, convert.input contains these two lines: 1 -555 LAB SUBMISSION Always be sure your linux prompt reflects the correct directory or folder where all files to be submitted reside. If you are not in the directory with your files, the following will not work correctly. You must submit all your lab assignments electronically to Carmen in .zip file format. The .zip file will be created by using the make command (See PART 1.) Once you execute the command, you should find a file in your lab2 directory called lab2.zip; this is the file that must be uploaded to Carmen. NOTE: • It is YOUR responsibility to make sure your code can compile and run on CSE department server stdlinux.cse.ohio-state.edu, using the specified compiler options without generating any errors or warnings or segmentation faults, etc. Any program that generates errors or warnings when compile or does not run without system errors will receive 0 points. No exceptions! This means you may want to copy the verify command from lab1 to your lab2 directory, modify it so that it will make convert1 and convert2 in the test directory.