CSAS 1111: Practice Exam 1

This exam contains questions that may appear in similar form in the actual exam. However, this does not imply that only questions of the type mentioned here will be part of the actual exam, or that the actual exam will include questions from this practice test. Also, this practice exam contains more questions that the actual exam.

1. Explain each of the following terms:
Source code, machine code, compiling, linking, double, int, char, CPU, RAM, secondary memory, bit, byte, smallest/largest integer, passing by reference, passing by value

2. Write some C++ program segments that solves the indicated tasks (you do not have to write a complete program, a small code segment will be sufficient).
A program to decide whether a number is positive, negative, or zero
A program to print all integers from 1 to 50 on the screen
A program to print all odd integers from 1 to 50 on the screen
A program to output a small menu that looks like this
Startreck Simulation Program

   A    to fire phasers
   B    to fire photon torpedos

   X	to exit

Enter your choice:
A program to reads a real number as input and adds it to a running total until the user enters the number -99. At that time the program should print out the final sum (not including, of course, the number -99).

3. Please find out what is wrong with the if statement listed below, and rewrite it to fix that logical error. (Hint: what if someone earns $1000 ?). Your new if statement should contain nested if-else-if statements.
if ((Balance >= 2000) && (Balance <= 3000)) { cout << "Your balance is between $2000 and $3000"; cout << "Your interested rate will be 3.5%"; } else { cout << "Your balance is larger than $3000."; cout << "Your interest rate will be 4.5%"; } 

4. Write a complete program that contains a main function and at least two additional functions to compute the area and circumference of a circle.
the main functions should contain the appropriate variable declarations
Input/output could be done in the main function, or in seperate functions that are used in the main function
the user should be asked to enter the radius of the circle, either inside the main function, or with the help of an additional function
the computations of area and circumference must be handled in additional functions that the main function uses
the output of the area and the circumference could be handled inside the main function, or with the help of additional function(s)
all functions must appear in the proper order so that your entire program would compile, link, and run without errors.
note that the value of Pi is not known to C++, and must therefore be defined as a constant at the correct position of the program.

5. Please answer the following questions:
When writing a C++ program, which function do you always write first ?
What are the three pieces usually necessary when using a while loop in C++ programming ?
When writing a C++ program, where does the definition of a new function go ?
In C++ programming, where does the declaration of a new variable belong ?
In C++ programming, what does the data type void stand for ?
In C++ programming, what is the difference between = and == ?
In C++ programming, what is the difference between a declaration and an assignment ?
What are the advantages and disadvantages of the data types int and double ?
What type do you always get when dividing or multiplying two integers ? How about if one of the factors, or the numerator or denominator, is a double ?

6. Consider the following function:
void Unknown(double x, double& y, int I, int& J)
{
   x = x + y;
   y = x + y;
   I = I + J;
   J = I + J;
}
Which parameters are value parameters, which are reference parameters ?
What is the output when the function Unknown is used as in the code segment below:
double X = 1.0;
double Y = 2.0;
int I = 3;
int J = 4;
Unknown(X,Y,I,J);
cout << X << Y << I << J;
X = 1.0;
Y = 2.0;
I = 3;
J = 4;
Unknown(Y,X,J,I);
cout << X << Y << I << J;

7. Write a function called Swap that take as input two double numbers that as output will swap the input values. In other words, if the value of X is 1.0 and Y is 2.0, then a call to Swap(X,Y) will result in X having value 2.0 and Y having value 1.0.

8. Please list the output of the program below. In other words, every time there is a cout statement, list the values that will appear on the screen.
#include <iostream.h>

int main(void)
{
   for (int i = 0; i < 5; i+=3)
     cout << "i=" << i << endl;
   
   for (int i = 1; i <= 2; i++)
     for (int j = 1; j < 5; j+=2)
       cout << " i * j=" << i*j << endl;

   double xx = 32;
   while (xx > 1.0)
     xx /= 2;
   cout << " xx=" << xx << endl;

   int i = 10;
   int j = 4;
   int k = i / j;
   double x = i / j;
   double y = ( (double)i / (double)j );
   cout << " k=" << k << " , x=" << x << " , y=" << y << endl;
   
   return 0;
}

</PRE>

</DL>

</BLOCKQUOTE>
</BODY>
</HTML>
">