Department of Computer Science
Computer Science 101: Mid Term Exam II (60 minutes)
![]()
Name: NetID:
Lab Section: Date: April 3rd, 2008
![]()
No questions
will be answered during this examination.
If you do not understand a question, read it again. If you still do not understand it, make reasonable assumptions and write them
down. (Points will be deducted if unreasonable assumptions are made.)
DO NOT CHEAT: Cheating includes not only copying from another person but
also allowing someone to copy from you.
Anyone who copies or allows someone to copy will receive a score of
zero. So be defensive and protect your
work.
This examination contains 10 pages including this page. Check that your copy is complete, and ask for a replacement if it is not. Do all your work on these pages. For your own protection, in case pages come apart, write your NetID at the TOP of each page before beginning work.
The number of points for a question
is roughly proportional to the amount of time you may need for it. Don’t spend
too much time on any one question.
Do not forget to sign the attendance list. If your exam is
misplaced and you did not sign the attendance list then you will receive a zero
score for the exam.
You may not use any electronic devices, book, notes or other
references during this examination.
Section |
Possible Score |
Deduction |
Grader |
|
6 |
|
|
|
|
2 |
6 |
|
|
|
3 |
6 |
|
|
|
4 |
6 |
|
|
|
5 |
6 |
|
|
|
6 |
5 |
|
|
|
7 |
5 |
|
|
|
8 |
10 |
|
|
|
9 |
8 |
|
|
|
10 |
8 |
|
|
|
11 |
8 |
|
|
|
12 |
9 |
|
|
|
13 |
8 |
|
|
|
14 |
6 |
|
|
|
15 |
5 |
|
|
|
16 |
10 |
|
|
|
17 |
13 |
|
|
|
Total |
125 |
|
|
|
|
|
Exam Scoreà |
|
A
Write a single
Unix command to make "Dir2" your current
directory. This command should work regardless of what the current directory is
at the time you are typing it at the Unix prompt.
_________cd ~/Dir1/Dir2 or cd ~netid/Dir1/Dir2__________________________
________pwd______________________________________________________________
________ls
Sdir______________________________________________________________
(Circle only one choice.)
a)
It can be used to copy
a file without deleting the original version.
b)
It cannot be used to move files from one
directory into another.
c)
It can be used to
rename a file.
d)
It launches a program called "my
voicemail".
#include <stdio.h>
#define LARGE 20
#define SMALL 10
void main(void)
{
int value = 7;
if
(value > LARGE)
printf("large\n");
if
(value > SMALL)
printf("med\n");
else
printf("small\n");
}
__________small______________________________________________________
a)
5 / 3 = ________1_____________
b)
5 / 6 = ________0_____________
c)
5 % 3 = ________2_____________
d)
3 % 5 = ________3_____________
e)
6 + 3 / 2 = ________7_____________

int wow[ _3 or blank_ ]
[ _3 not
blank__ ] = { __{1, 9, 1}, { 2 , 2, 3}, {4, 5, 6}________
};
(inner curly braces not required)
#include <stdio.h>
void main(void)
{
int x;
scanf("%i", &x);
switch
(x/32)
{
case
0:
printf("Too
cold!\n");
break;
case
3:
printf("Too
hot!\n");
break;
case
2:
case 1:
printf("Just
right!\n");
break;
default:
printf("Weird
weather!\n");
break;
}
}
Fill in
the blanks below to re-implement the program using if
statements. After you enter your code below the program should be equivalent to
the program above.
#include <stdio.h>
void main(void)
{
int x;
scanf("%i", &x);
if
(_______x/32 == 0__________________)
printf("Too cold!\n");
else
if (_______x/32 == 3______________________________)
printf("Too hot!\n");
else if (____(x/32 == 2) || (x/32 == 1)__________)
printf("Just
right!\n");
else