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 _________________
2.
make a new directory _________________
3.
copy a file or files _________________
4.
rename or move a file or directory _________________
5.
delete a file or files _________________
6.
display the contents of a file _________________
7.
change the current directory _________________
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.
____________________________________________________________________________

__________________________________________________________________
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));
________________________________________________________________
#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");
}
____________________________________________________
____________________________________________________
____________________________________________________
____________________________________________________
#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 ; _____________________)
{
total = 0;
for(j=0; j < 5 ; ____________________ )
{
______________________________________;
}
average[______] =
__________________________________;
}
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 = _____________ , b = _____________ , c = _____________ , d = ______________
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);
}
}
}
_________________________________________________________________
a) for(i = 0; i < 6; i++)
{
printf("%i", i);
}
b) i = 0;
while (1)
{
printf("%i",++i);
if (i==5)
{
break;
}
}
c) i = 1;
do
{
if (i != 0)
{
printf("%i", i);
}
} while (i < 6);