Docsity

Study Guide for Final Exam - Programming in C++ | CS 201, Exams of Computer Science

Toggle sidebar
bg1
CS 201 – The Cold Cold Final
1) Consider the class ‘snow’ above. Assuming each int
is four bytes, how many bytes is a ‘snow’?
a) Four
b) Eight
c) Twelve
d) Some other number.
2) (Yes/No) Does the class ‘sleet’ have a variable named
‘density’?
3) I am using my friend’s ‘string’ class. He tells me that it can store any number of
characters per string, and that it can store any character in each string with no restrictions.
I observe that the string ‘hello’ takes 9 bytes of RAM. I run this test on Tuesday while
it’s snowing outside. I’m using a Mac which I bought because of their Swith™
campaign. My friend is a very nice person but he doesn’t like Monty Python so I’m
thinking about dumping him. He says the string class was easy to write. The string ‘hi’
takes 6 bytes. How is this string class likely implemented?
a) Array of chars with a null byte at the end.
b) Array of chars with a length field.
c) Using a binary tree.
d) As a set of letters.
4) (Yes/No) Is there an example of operator overloading in the line of code below?
cout << “hi”;
5) List every function invoked by the code below. Every variable is of type ‘Snowman’.
A = b+3-c;
6) Assume that s is an ‘ice’ as shown above. Which is correct?
s->temp = 12; s.temp = 12;
7) What type is the following expression? The variable ‘p’ is a pointer to float.
*(p+3)
class sleet: protected snow {
float wetness;
};
class snow: public ice {
protected:
int density;
};
class ice {
public:
int temp;
private:
int thickness;
};
pf3
pf4

Partial preview of the text

Download Study Guide for Final Exam - Programming in C++ | CS 201 and more Exams Computer Science in PDF only on Docsity!

CS 201 – The Cold Cold Final

  1. Consider the class ‘snow’ above. Assuming each int is four bytes, how many bytes is a ‘snow’? a) Four b) Eight c) Twelve d) Some other number.
  2. (Yes/No) Does the class ‘sleet’ have a variable named ‘density’?
  3. I am using my friend’s ‘string’ class. He tells me that it can store any number of characters per string, and that it can store any character in each string with no restrictions. I observe that the string ‘hello’ takes 9 bytes of RAM. I run this test on Tuesday while it’s snowing outside. I’m using a Mac which I bought because of their Swith™ campaign. My friend is a very nice person but he doesn’t like Monty Python so I’m thinking about dumping him. He says the string class was easy to write. The string ‘hi’ takes 6 bytes. How is this string class likely implemented? a) Array of chars with a null byte at the end. b) Array of chars with a length field. c) Using a binary tree. d) As a set of letters.
  4. (Yes/No) Is there an example of operator overloading in the line of code below? cout << “hi”;
  5. List every function invoked by the code below. Every variable is of type ‘Snowman’. A = b+3-c;
  6. Assume that s is an ‘ice’ as shown above. Which is correct? s->temp = 12; s.temp = 12;
  7. What type is the following expression? The variable ‘p’ is a pointer to float. *(p+3) class sleet: protected snow { float wetness; }; class snow: public ice { protected: int density; }; class ice { public: int temp; private: int thickness; };
  1. Suppose that doubles on my computer require 8 bytes and pointers require 4 bytes. What is the value of q? double *q = (double *)1000; q++;
  2. Suppose you open a file that had 1,000 bytes in it. Then you run the code below. How many bytes are in the file? ofstream out; out.open("junk.txt"); for(int i = 0; i < 2000; i++) out << "a";
  3. Consider the code above. Suppose you are working off a read-only CD-ROM. Which line will generate an error?
  4. What does the code below print out? int *a, b, *c, d; a = &b; *a = 12; cout << a;
  5. When we write methods like “void clear(Snow &s)” what does this “&” mean? a) This is an example of operator overloading. b) This can only be done on variables that have already been initialized. c) This is a static method, applicable to all instances of the class ‘Snow’. d) The variable ‘s’ should be the actual argument to the method, not a copy of the method’s argument.
  6. When are destructors to a method called? List two times.
  7. Show me an example of using the assert command. I just need one line of code.

HAVE A MERRY CHRISTMAS!!!