CISC 105 sections 010-025
Midterm 2
11/10/04
Name
Please circle your section number:
| 010 | 014 | 018 | 022 |
| 011 | 015 | 019 | 023 |
| 012 | 016 | 020 | 024 |
| 013 | 017 | 021 | 025 |
The programming/short answer questions start with number 23.
x < 0 and x >= 0 instead of using one test and then
else would be considered unnecessary
testing.
Which of the following are the names of the
formal parameters of this function
Each of the questions in this section consists of a short C program.
For each one, either select the answer that matches the output of the
program, or, if the program contains an error that would prevent
you from determining the output, select ``error'' as your answer.
(2 pts) What is the output?
(2 pts) What is the output?
(2 pts) What is the output?
(2 pts) What is the output?
(2 pts) What is the output?
(2 pts) If the variable
(2 pts) If the variable
(2 pts) If you want the variable
All of the questions in this section deal with the following segment of
a complete C program.
(2 pts) Which of the following statements is true about
the section of the C code above that appears before the
line
(2 pts) Which of the following could NOT appear legally later
in this main program?
(2 pts) Which of the following could NOT appear legally later
in this main program?
(2 pts) Which of the following could NOT appear legally later
in this main program?
(4 pts) From Project 1: The following function is supposed to
return true if the number of trips is not different by more than one,
and false otherwise. Select the choice below that replaces
(4 pts) From Project 1: The following function is supposed to
return false if one parameter is more than 60 percent of the sum of
the parameters, and true otherwise. Select the choice below that
replaces both
(4 pts) From Project 1: Now suppose there is only one truck.
The following function returns the number of trips
that truck must take given two parameters: the starting number of tons,
and the capacity of the truck in tons. Select the choice below that
replaces
(20 pts) Write a complete C program that behaves as follows:
Sample script:
(Extra space in case you need it.)
(20 pts) Write a complete program that reads 100 integers from a
file named
All the integers will be in the range 0 - 10
inclusive.
Your program should include a function to find the maximum value in an
array, given the array and the array size as parameters.
Have your
(10 pts) One of the reasons we teach Unix in CISC105 is because the CIS dept and the Electrical and Computer Engineering departments have asked us to.
They want to be able to assume that their students know how to use Unix when they take later courses.
So, assume that in a future semester, having already mastered
CISC105, you go on to take CPEG202.
Your goal is to make a report available at the following URL
(assuming that
Assume the following:
Your assigment is to
Give the entire sequence of Unix commands that you use to accomplish
this task. Note that even though I've listed four steps above, you
might NOT need exactly four commands.
For each command spell out the entire command line (e.g. don't just say ``cp'', say ``cp foo bar''.) You don't have to give the editor commands, but you do need to show the command you use to ``startup'' the editor on your file.
End of Exam. Total Points: 100
This document was generated using the
LaTeX2HTML translator Version 99.2beta8 (1.43)
Copyright © 1993, 1994, 1995, 1996,
Nikos Drakos,
Computer Based Learning Unit, University of Leeds.
The command line arguments were:
The translation was initiated by Phillip T Conrad on 2004-11-20
Multiple Choice
inc1 contained in the program listing of Q5.c shown on the
following page of this exam.
(a) r and s
(b) 3 and 4
(c) &a and b
(d) n and m
(e) none of the above
(a) 3 and 4
(b) &a and b (c) r and s
(d) *r and s
(e) none of the above
inc2(&a,b); represents which of the following:
(a) function definition
(b) function prototype (c) function call
(d) function library
(e) none of the above
void inc1(int n, int m);
represents which of the following:
(a) function definition
(b) function prototype (c) function call
(d) function library
(e) none of the above
/* +++ */ down to the
end of the page, as a group, represent which of the following:
(a) function definition
(b) function prototype (c) function call
(d) function library
(e) none of the above
main1: 3 4
main1: 4 4
main1: 4 5
inc1: 4
inc1: 5
inc2: 3
inc2: 4
main3: 3 4
main3: 4 4
main3: 5 6
/* Q5.c */
void inc1(int n, int m);
void inc2(int a1[], int i);
#include <stdio.h>
int main()
{
int a = 3;
int b = 4;
printf("main1: %d %d\n",a, b);
inc2(&a,b);
printf("main2: %d %d\n",a, b);
inc1(a,b);
printf("main3: %d %d\n",a, b);
return 0;
}
void inc1(int n, int m)
{
n++;
m++;
printf("inc1: %d\n",m);
}
/* +++ */
void inc2(int *r, int s)
{
(*r)++;
s++;
printf("inc2: %d\n",(*r));
}
What is the output? (Multiple choice)
/* Q2.c */
#include <stdio.h>
int main(void)
{
int a[4] = {13, 15, 15, 19};
printf("%d",a[1]);
return 0;
}
(a)
0
(b)
4
(c)
13
(d)
15
(e) error
/* Q3.c */
#include <stdio.h>
int main(void)
{
int a[6] = {13, 15, 15, 19};
printf("%d",a[5]);
return 1;
}
(a)
0
(b)
1
(c)
4
(d)
13
(e)
15
/* Q6.c */
#include <stdio.h>
int main(void)
{
int a[6] = {13, 15, 17, 19, 20, 21};
printf("%d",a[6]);
return 0;
}
(a)
0
(b)
19
(c)
20
(d)
21
(e) error
/* Q4.c */
#include <stdio.h>
int main(void)
{
int a[6] = {1};
printf("%d",a[3]);
return 0;
}
(a)
0
(b)
1
(c)
3
(d)
6
(e) error
/* Q7.c */
#include <stdio.h>
int main(void)
{
int a[6] = {13, 15, 17, 19, 20, 21};
printf("%lf",a[3]);
return 0;
}
(a)
13
(b)
15
(c)
17
(d)
19
(e) error
Addresses and Pointers
x is of type int, which of
the following expressions would determine the address of that variable?
(a)
*x(b)
&x(c)
addr(x)(d)
%x(e) none of the above
p is of type double *, which of
the following expressions would ``dereference'' the variable p?
(a)
*p(b)
&p(c)
deref(p)(d)
%p(e) none of the above
a to contain the
address of an integer, which of the following would be a correct
declaration of a?
(a)
int a;(b)
int &a;(c)
int *a;(d)
int %a;(e) none of the above
Functions (multiple choice)
...
int findMax(int a, int b);
int findLargest(int a[], int n);
double areaOfCircle(double r);
void midPoint(double x1, double y1, double x2, double y2,
double *x, double *y);
#include <stdio.h>
int main(void)
{
int a=2, b=3, c=4;
double d=5.0, e=-6.0, f=7.5;
int scores[4] = {97, 65, 72, 80};
double weights[4] = {0.15, 0.15, 0.2, 0.5};
...
#include <stdio.h> ?
printf("%d\n",findMax(3, 4));
printf("%lf\n",areaOfCircle(d));
midPoint(4.0, 5.0, -2.0, -3.0, &d, &e);
f = midPoint(4.0, 5.0, -2.0, -3.0, &d, &e);
printf("%d\n",findMax(a * 2, b/3));
d = findMax(a, 3);
midPoint(4.0, 5.0, -2.0, -3.0, d, e);
a = findLargest(scores, 4);
midPoint(d, e, 0.0, 0.0, &d, &e);
a = findLargest(scores[0], 4);
e = areaOfCircle(f);
f = areaOfCircle(weights[1]);
Project 1 Related Questions (multiple choice)
???
and makes the function work correctly.
int meetsDiffOneOrLessRule(int tripsA, int tripsB)
{
return ???
}
((tripsA > tripsB) && ((tripsA - tripsB) > 1));
((tripsA >= 1) && (tripsB >= 1));
1 >= abs(tripsA - tripsB);
pow((tripsA - tripsB), 2) < 1;
none of the above
??? and makes the function work correctly.
int meetsSixtyFortyRule(int tripsA, int tripsB)
{
if (tripsA > tripsB)
return tripsA ??? * (tripsA + tripsB);
else
return tripsB ??? * (tripsA + tripsB);
}
<= .60
< .60
> .40
>= .40
??? and makes the function work correctly.
int countTrips(int startTons, int capacity){
int truckCount = 0;
while ( ??? ){
startTons -= capacity;
truckCount++;
}
return truckCount;
}
startTons >= 0
startTons <= capacity
truckCount < capacity/startTons
startTons > 0
C Programming
scanf to get the integers and put the integers into an
array
% a.out
Please enter ten integers:
9 3 2 4 5 6 7 3 8 6
array is: 9 3 2 4 5 6 7 3 8 6
min is: 2
data.txt into an array.
main() call the function and print the result.
Unix Commands (short answer)
userid is your own userid):
http://~userid/cpeg202/reports/myReport.html
~/public_html/cpeg202 in your account. This directory contains a few files, but it currently contains no subdirectories (hint: that is an important point.)
~smith/public_html/cpeg202/ contains
the file sampleReport.html.
sampleReport.html,
myReport.html,
About this document ...
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
latex2html -split 0 E02_F04.tex
Phillip T Conrad
2004-11-20