CISC 181 sections 010-015 (Conrad)
Midterm I
October 4, 2004
Name
Section (circle one, (2 pts)):
| 010 | 011 | 012 |
| 013 | 014 | 015 |
Circle one:
| Freshman | Sophomore | Junior | Senior | Other |
Problem Statement: Ask the user of the program to input
two positive integers. Then print a message indicating whether
the larger is a multiple of the smaller one, or not. If the two
numbers are the same, indicate that.
Examples:
Your program should provide appropriate prompts to the user,
and should also label the output appropriately and neatly.
Your program should also check for an error condition:
if either of the numbers input is negative or zero, then
print an error message, and terminate the program immediately.
Extra space in case you need it
Complete the function
The function should draw a picture on standard output
in the shape of the letter L of the given height and width, followed
by a blank line.
If either height or width is
less than 2, the function simply draws nothing (no error
message is produced, and no blank line is printed.
The complete program appears below (with the body of function
Extra space in case you need it
unit=18pt
(If you circle the wrong thing accidentally and want to change your answer,
just find some other way to indicate clearly what the unary operators are.)
unit=18pt
unit=18pt
(2 pts) Which of the following Unix commands creates a new directory:
Circle one:
(2 pts) Which of the following is the directory where a web page
accessed via
Circle one:
(2 pts) Which of the following would be used to change the file
access permissions (e.g. to make a web directory readable by others)?
Circle one:
(1 pts) What symbol is used for the stream insertion operator in C++?
(2 pts) In the C++ statement
(2 pts) In the C++ statement
(1 pts) Which of the following tests whether x is equal to 10?
(1 pts) Which of the following assigns the value of 2 times y to x?
(1 pts) In the expression
, which part is the mantissa?
(1 pts) The C++ statement
Suppose you have a C++ program in a file named
Total Points: 100
This document was generated using the
LaTeX2HTML translator Version 2002-2 (1.70)
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 Conrad on 2004-10-09
Pay attention to the point values.
When there are 10 minutes left, skim through and be sure you have at least
written something for the questions that are worth many points.
input
output
9 3
9 is a multiple of 3
7 8
8 is not a multiple of 7
7 49
49 is a multiple of 7
5 5
Both numbers input were 5
drawL in the program listed below.
drawL omitted), with sample output on the following page.
You may fill in the function in the space provided, or rewrite the complete function in the blank space on the next page (below the sample output.)
// e02.cc Exam question for CISC181
// P. Conrad, 10/04/04
#include <iostream>
using namespace std;
void drawL(int height, int width, char c)
{
}
int main(void)
{
drawL(2,2,'s');
drawL(3,2,'y');
drawL(4,3,'x');
drawL(2,1,'a');
drawL(3,5,'z');
return 0;
}
Output:
> g++ e02.cc
> ./a.out
s
ss
y
y
yy
x
x
x
xxx
z
z
zzzzz
>
1100 0001 1000 0001 0010 1111 1010 1011
// e01.cc Exam question for CISC181
// P. Conrad, 10/04/04
#include <iostream>
using namespace std;
int mysteryFunc(int x, int y)
{
x = -y + x * 5;
y--;
cout << "x= " << x << endl;
return y;
}
int main(void)
{
int a, b, c;
a = 3;
b = 5;
c = 7;
cout << "a= " << a << endl;
a = mysteryFunc(b,c);
cout << "a= " << a ;
cout << " b= " << b << endl;
cout << " c= " << c << endl;
}
// e03.cc Exam question for CISC181
// P. Conrad, 10/04/04
#include <iostream>
using namespace std;
int main(void)
{
int x;
cout << "Enter x: ";
cin >> x;
int i=1;
while (i < x)
{
cout << "*";
i *=2;
}
cout << endl;
}
Unix Commands
(a)
chmod(b)
pwd(c)
cd(d)
mkdirhttp://udel.edu/~jsmith/cisc181 would be stored on strauss?
(a) ~jsmith/public_html
(b) ~jsmith/cisc181
(c) ~jsmith/cisc181/index.html
(d) ~jsmith/public_html/cisc181
(a)
chmod(b)
pwd(c)
cd(d)
mkdir
Short Answer
a = b + 7 * 4;
what is the left operand of the assignment operator?
a = b + 7 * 4;
what is the right operand of the addition operator?
Multiple Choice
(a)
if (x == 10)(b)
if (x = 10)
(a)
x == 2 * x;(b)
2 * y = x; (c) x = 2 x y; (d) x = 2 * y;
(a)
(b)
(c) (d)
x = x / 2; is equivalent to which of the following statements?
(a)
x /= 2;(b)
x += 2;(c)
x = 2; (d) x = 2 / x ;
Working with C++ programs
lab03.cpp
What Unix command do you enter to perform each of the following
operations?
lab03b.cpp.
About this document ...
Copyright © 1997, 1998, 1999,
Ross Moore,
Mathematics Department, Macquarie University, Sydney.
latex2html -split 0 E01_181F04.tex
Phillip Conrad
2004-10-09