Study Guide for CS 111 Final

The final will be on Wednesday, June 10th. It will last 2 hours, from 10 until 12.

What you are responsible for:

You should know the material presented in lecture and in the assigned readings. You are responsible for everything up to and including the material covered on Thursday, June 27. The main topics we covered were: arithmetic expressions, assignment statements, flow of control, functions, arrays, strings and classes.

    I would pay most attention to what we covered in class and to the reading directly related or dealing with those topics.

    I will not try to pick some small detail out of the reading and test you on it.

Format of the Test:

The test will consist of the following kinds of questions: Good luck!
  • Here are a few sample questions of each type above. You can find others in the short answer exercises at the end of the chapters.

    1. What are the values of the following C++ expressions?

    -4+2.15*3

    (4 > 24/6 || 5!= 1+4) &&(6-8 >= 8-6 || 16%7 < 2)

    2. Write a C++ expression which is true if the value of the integer variable num is not between 1 and 99.

    Determine the output of the following code when x is 9 and y is 11.

    3..

    if (x < 10)

    if (y > 10)

    cout << "1 ";

    else

    cout <<"2";;

    cout << "3";

    4.

    if (x < 10) {

    if (y > 10)

    cout << "1 ";}

    else

    {cout <<"2";;

    cout << "3"; )

    5. Consider the following class.

    class Point {

    public:

    Point(int, int);

    void move(int, int );

    int get_x() const;

    int get_y() const;

    private:

    int x;

    int y; };

    Point::Point()

    { x = 0;

    y = 0; }

    Point::Point(int xval, int yval)

    { x = xval;

    y = yval; }

    void Point::move(int dx, int dy)

    x += dx;

    y += dy; }

    int Point::get_x() const

    {

    return x; }

    int Point::get_y() const

    { return y; }

    int main()

    { Point p1;

    cout<< "The x value for p1 is " << p1.get_x() << endl;

    int x, y;

    cout << "\nPlease enter x and y value for p2: ";

    cin >> x >> y;

    Point p2(x, y);

    p2.move(3, 5);

    cout<< "\nThe new y value for p2 is " << p2.get_y() << endl;

    return 0; }

    a. Assume that in the cin statement the inputs are 8 and 6. What is output by main ??

    b. Write a statement that would declare a new point p3 and give it a value (1, 15).

    6. Write a function print for the point class which would print out the value of both coordinates of a point.

    7. What is output ?

    #include 
       void g(int *a , int b);
    
    void main(void)
       { int x = 10, b = 5;
    
         g(&x,b);
         cout << x+b <<  x%b << endl ;}
    
       void g(int *a , int b)
       { *a = 2;
         b=6;
         cout << 4+5/2-3%2 <<  *a-b/2 << *a = 7<<  endl; }
    
    

    8. In #6 what are the parameters passed using call by value or call by reference ? What is the difference ?