Department of Computer Science
Computer Science 101: Mid Term Exam II (60 minutes)
![]()
Name: NetID:
Lab Section: Date:
![]()
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 12 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, books, notes or
other references during this examination.
Section |
Possible Score |
Score |
Grader |
|
7 |
|
|
|
|
2 |
6 |
|
|
|
3 |
6 |
|
|
|
4 |
6 |
|
|
|
5 |
4 |
|
|
|
6 |
8 |
|
|
|
7 |
10 |
|
|
|
8 |
8 |
|
|
|
9 |
6 |
|
|
|
10 |
8 |
|
|
|
11 |
10 |
|
|
|
12 |
4 |
|
|
|
13 |
4 |
|
|
|
14 |
8 |
|
|
|
15 |
4 |
|
|
|
16 |
6 |
|
|
|
17 |
8 |
|
|
|
18 |
12 |
|
|
|
Total |
125 |
|
|
A
Unix
commands:
a) cp
b) mv
c) cd
d) ls
e) more
f)
rm
g) mkdir
Descriptions:
1.
display the contents of a directory ________d_________
2.
make a new directory ________g________
3.
copy a file or files ________a_________
4.
rename or move a file or directory ________b_________
5.
delete a file or files ________f_________
6.
display the contents of a file ________e_________
7.
change the current directory ________c_________
2.
Write a single
UNIX command that compiles a C program stored in a file named lab99.c , found in your current directory, into an
executable file named lab99. That is, to run this program you will type lab99 and NOT a.out at the UNIX prompt.
_____gcc lab99.c –o lab99___OR gcc
./lab99.c –o lab99______________________

___ls ../../lab10 OR ls ../../lab10/*
OR ls ~/lab10 OR ls
~/lab10/* _________
4.
A “block” in C
programming language is defined by using which of the following pairs of
symbols? Circle only one choice.
a) ( )
b)
{ }
c) [ ]
d) /* */
e) ""
char sport[] = "baseball";
printf(" %i \n", strlen(sport));
_________8______________________________________________________
#include <stdio.h>
#include <string.h>
void main(void)
{
char password[32] ={'k','i','t','t','y','\0','c','a','t','\0'};
char animal[32] =
"dog";
printf("%s
\n", password);
printf("%c
\n",password[1]);
strcpy(password,
"dog");
printf("%s
\n", animal);
if (strcmp( password, animal) > 0)
printf("yes \n");
else
printf("no \n");
}
_____kitty_______________________________________________
_____i_______________________________________________
_____dog_______________________________________________
_____no_______________________________________________
#include <stdio.h>
void main(void)
{
int i, j, total;
int
scores[5][5]={10, 9, 9, 10, 8,
10, 5, 6, 6, 2,
8, 8, 8, 5, 4,
10, 8 , 5, 4, 5,
6, 2, 6, 7, 8};
double average[5];
/* not shown here is
code that may change values in scores array*/
/* fill in the blanks below with the correct C code */
for(i=0; i < 5 ; ___++i OR i++ OR i=i+1__)
{
total =
0;
for(j=0; j <
5 ; _++j OR j++ OR j=j+1_____ )
{
___total += scores[i][j]___________;
}
average[__i____] = ______total/5.0_____;
}
for(i=0; i< 5; ++i)
printf("average[%i] = %lf \n", i, average[i]);
}
8.
The following C program compiles and runs without
errors. Write the output of this program.
#include
<stdio.h>
void main(void)
{
int
a, b = 3, c = 2, d = 4;
a= (c++) + b;
b++;
d /= 2;
printf(" a = %i , b = %i , c = %i , d = %i\n",
a, b, c, d);
}
a = _____5________ , b = ____4_________ , c = ____3_________ , d = _____2_________
9.
The following C program compiles and runs without
errors. Write the output of this program.
#include <stdio.h>
void main(void)
{
int i, j;
for(i = 1; i <= 2; i++)
{
for(j = 1; j < 3; j++)
{
printf("%i ", i * j);
}
}
}
___________1___2___2___4_____________________________________________
a) for(i = 0; i < 6; i++)
{
printf("%i", i);
}
b)
i = 0;
while (1)
{
printf("%i",++i);