2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 1/15
Midterm A (Remotely Proctored)
Due No due date Points 100 Questions 20
Available until Oct 14, 2020 at 1:15pm Time Limit 60 Minutes
Instructions
If you are taking this exam during one of my class hours or at a time agreed upon, you may use Zoom to
professor Kirby’s office hours to ask questions.
Office hours link (https://osu.zoom.us/j/98869880108?pwd=NXNCUmNuVlI2OWV5NTIzUVg0K29OQT09)
You can ask questions in Zoom using chat sent only to Professor Kirby and not to everyone
The test is closed book, closed notes, no other assistance
1 optional blank on both sides sheet of scrap paper is allowed. Show both sides to your camera when you
start and when you finish. Hope that it doesn’t set off Proctorio.
Aside from adaptive aids and SLDS accommodations, anything else is misconduct.
https://osu.zoom.us/j/98869880108?pwd=NXNCUmNuVlI2OWV5NTIzUVg0K29OQT09
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 2/15
This quiz is no longer available as the course has been concluded.
Attempt History
Attempt Time Score
LATEST Attempt 1 60 minutes 55 out of 100
Correct answers are no longer available.
Score for this quiz: 55 out of 100
Submitted Oct 14, 2020 at 11:21am
This attempt took 60 minutes.
0 / 2 ptsQuestion 1IncorrectIncorrect
C is pass by value, except when we pass a pointer.
True
False
2 / 4 ptsQuestion 2PartialPartial
Given the following at the linux command line
$lab4 infile outfile dndfile
Select the best value for each item on the left from the list on the right
argc
4
https://osu.instructure.com/courses/89321/quizzes/426285/history?version=1
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 3/15
argv[0]
“lab4”
argv[argc]
none of the other answ
argv
“lab4”
4 / 4 ptsQuestion 3
Given the following code:
char a[20] = “Now is the time!”
char *p = “When in the course of human events.”
Can you change the value of:
a
No
a[4]
Yes
p
Yes
*p
No
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 4/15
4 / 4 ptsQuestion 4
Your Answer:
What is the value of an assignment expression in C?
The value of an assignment expression in C is rvalue
4 / 4 ptsQuestion 5
Pick the best answer for each stage of the build process. Think about what
each stage generates.
generates executables
linker
generates object files
assembler
generates assembler files
compiler
generates intermediate files
preprocessor
3 / 4 ptsQuestion 6
Describe how a definition for a function or a variable differs from a declaration
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 5/15
Your Answer:
The difference is when a variable or a function was declared, it just indicated
that the function or variable is exists, and no space or concrete implentation is
claimed. Space is only applied when variable is defined. It implemented when
the function is defined.
3 / 4 ptsQuestion 7PartialPartial
Given:
int *x;
int (*fp[3])(int *ip);
What is the type of each of the following expressions?
x
pointer to an int
*x
int
fp[2]
a pointer to a function t
fp[2](x)
a function that takes an
2 / 2 ptsQuestion 8
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 6/15
What keyword do we use with switch / case and loops to terminate execution of
the control structure?
break
2 / 2 ptsQuestion 9
What keyword do we use with loops to force the inner-most loop to attempt the
next iteration?
continue
0 / 1 ptsQuestion 10IncorrectIncorrect
Consider the following line of code in a .c file
#define DEBUG = 1;
What will happen if DEBUG is used later in the file? If you don’t see enough
information to be sure, pick the most likely outcome.
The compiler will generate an error on the #define
The compiler will generate an error where DEBUG is used
This works just fine
The pre-processor will generate an error on the #define
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 7/15
0 / 3 ptsQuestion 11
Answer 1:
Answer 2:
Answer 3:
IncorrectIncorrect
What are the three fields / parts of a makefile entry called?
open file : read and write file
close file
open file
read and write file
close file
2 / 2 ptsQuestion 12
Given
unsigned int u = 5;
short s = -2;
if( u > s)
Does the conditional expression evaluate true or false?
NOTE: Think about what has to happen before the comparison takes place.
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 8/15
True
False
1 / 3 ptsQuestion 13PartialPartial
Given the following code:
static Node *getNode()
{
static int allocated = 0;
/* do not worry about code that would normally be
here */
}
For getNode, what are the:
lnkage
internal
scope
block
storage class
static
3 / 4 ptsQuestion 14PartialPartial
How big are the following, in bytes? In other words, what number – just the
number, no units – does sizeof return for each of these?
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 9/15
Answer 1:
Answer 2:
Answer 3:
Answer 4:
char are 1 bytes long
double are 8 bytes long
pointer types are 4 bytes long
int are 4 bytes long
1
8
4
4
3 / 4 ptsQuestion 15
Your Answer:
Assume the code fragment below is valid. Assume “part” is a member of a
structure of type “struct Collection”
(*thing)->part
Give a correct declaration for the variable “thing.”
struct collection *thing
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 10/15
4 / 4 ptsQuestion 16
Your Answer:
Given:
arr[3] = 4;
Write one line of C code that does the exactly the same thing. DO not use [] in
your one line of code.
*(arr+3) = 4
0 / 4 ptsQuestion 17
Your Answer:
UnansweredUnanswered
Given:
int sec, ET = 126;
Write one line of C code that sets the variable sec equal to the number of
seconds you would have if you removed all of the whole minutes from the
amount of seconds held in the variable ET. In this case the computation would
assign 6 to sec since 60 + 60 + 6 = 126. Your code should work for any non-
negative number in ET, not just 126. If ET held 16, your code would assign 16. If
ET held 61, your code would assign 1.
Instructions for programming questions
Do not do more than the question asks you to do.
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 11/15
None of the code needs to be very long.
You are not required to have comments. I will read your comments and use
them to interpret your code. If the comments make bad code clear it gets
more points than bad code alone
If you need to use a library function that you are pretty sure exists, make
your best guess at the function name and provide a comment about what
the function does. If you could not recall the “sqrt” function name, using
“square_root” would not cause a deduction.
If you are not sure of the exact syntax of a library function, adding a
comment explaining what is going on could improve your score. For square
root, it would be “takes a double and returns a double.” For functions with 2
or more parameters, you could tell what the different parameters meant.
Perfection is required for full points, but after the first syntax error, no other
points will be deducted for simple syntax errors.
These are not labs, there is a ton of partial credit in the scoring here.
4 / 20 ptsQuestion 18
Write the function “copy_new” that gets passed a string and returns an entirely
new copy of that string. If copy_new can’t create the new string, it prints an
error message. The copy_new function must always return a sensible return
value of the appropriate type. The code below should work just fine with your
function.
/* Assume that new_string and old_string are appropriatel
y
* declared. Assume that old_string is properly initialize
d.
* The following code should work.
*/
if( new_string = copy_new(old_string))
{
/* assume we do something useful with new_string
here */
}
Checklist for full points:
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 12/15
Your Answer:
Get the parameter and return types right
Correctly deal with the ramifications of “entirely new”
Figure out when you need to print the error message and print it
Always return a value
Mae sure that the copy happens
char* copynew (char*oldstring){
return
}
+4 for correct header
14 / 25 ptsQuestion 19
Your answer to this question will have two related parts:
1. Write the function move.
2. Write the line of code that correctly calls the function move, based on the
data given and the parameters for the function.
Imagine a game that has rooms. The player can attempt to move in the four
directions of the compass, but there might not be a room in that direction.
We will model the room using the following structure:
struct Room {
int room_number;
char *description;
/* any of these could be NULL */
struct Room *neighbors[4];
};
We will represent directions with the numbers 0-3. Numbers in that range can
be used as subscripts to access the neighbors array of the current Room.
Numbers outside that range should be ignored. If there is no room for a
particular valid direction, the neighbors array will have a NULL for that element
of the array.
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 13/15
Here is the “one purpose” statement for move:
Given a current location and a direction number, the function move will
attempt to update the location to the corresponding neighbor.
If the direction is less than zero or the direction is more than 3 or the
corresponding neighbor is NULL, then move does nothing to the location and
returns a false value.
If the direction is in the range of 0-3 and the corresponding neighbor is not
NULL, then move updates the location to equal that neighbor and returns a true
value.
Consider the following code:
struct Room *location;
int direction;
/* assume code here sets location to a good value; everyt
hing to do with
** location is properly initialized.*/
/* assume code here set direction to an arbitrary intege
r value. */
/* remember that only values from 0 to 3 are valid */
if( move( /*rewrite this line with good parameters */ )
)
{
/* assume code here prints out the room descripti
on */
}
Any comment with “assume” means that real code would normally go here and
do the thing mentioned by the comment. Do not write code to replace the
comments marked “assume.” You will need to rewrite the line with the call to
move.
Your job is to do the 2 things mentioned at the beginning of the question:
1. Write the function move
2. Rewrite the line with the call to move
Do not write any #includes or other statements besides the function and the
call.
Checklist for full points:
2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 – Sys 1: Comput Org (9862)
https://osu.instructure.com/courses/89321/quizzes/426285 14/15
Your Answer:
“C is …?” – the class cheer has a large impact on this question.
Have great care with the parameter types
The types of the values passed need to match the function parameter types
Be careful about accessing members of a struct
Be careful about type and about pointers
Be careful about how pointers and structs interact
Don’t forget return values and the return type
The code is actually quite short.
move(location, direction)
bool move(Room* location, int direction){
if(direction > 3 || direction <0) return FALSE; else return TRUE; } -3 Call by value – have to pass &location to change location -1 C does not have a Boolean type -2 missing one of the three error checks -5 no assignment to change location 0 / 0 ptsQuestion 20 The goal of the exam is demonstrate that you have mastery of the material. This space is provided to be the equivalent of the margin on a paper exam where you tell me that a problem is broken or where you justify your answer when you think that you know it but expect your answer to be marked wrong. 2021/9/8 下午9:56 Midterm A (Remotely Proctored): AU20 CSE 2421 - Sys 1: Comput Org (9862) https://osu.instructure.com/courses/89321/quizzes/426285 15/15 Your Answer: If you have any issues with a non-essay problem, write those issues here. (Essay problems have plenty of room for that in the answer space). If you think a problem might be answered in different ways given different interpretations, make your case for points here. Do not spend excessive time here. Be sure to properly identify the question you want to argue about so I know where to apply your comments. If you have time - and only if you have time - this is where commentary on the test itself goes. Null Quiz Score: 55 out of 100