The CS 201 Test of Joy
0) Is your name on the test?
NO, I want a zero.
Yes, I want a grade
Yes, but I fear #3 is a trick question.
1) Why do we like Joy?
Because it makes us happy
Because it makes me sad
For the music
2) What does this code print?
float f = 1/2+3;
cout << f;
3) Please declare me a variable named 'happy' that is a pointer to a
double?
4) Assume the class smile has overloaded the '*'', '+', and '='
operators and that 'x' and 'y' and 'z' are all of class smile.
Which operator is the first to be called on the code below?
z = x + y * z;
5) Assume that both classes overload the '+' and '=' operator.
Which class's '+' operator will be called below.
clown c;
giggle g;
c = g + c;
6) Write me a do-while loop that prints the numbers 19,16,13,10,7, and
4.
7) What does this code print?
int a = 1, b = 2, *c, *d;
c = &a;
d = &b;
*c = 3;
*d = 4;
cout << a;
8) What does this code print?
char *c = "I am always happy and never sad.
People like me";
cout << c+3;
9) What does this code print?
char *c = "Life is good and the world is sweet";
cout << *(c+2);
10) How many bytes are needed to store the string "joy"?
three
some other number
You may get up to 10 points total on these programs. You may not
get more than 10 points.
You get an extra point above the total listed below for the first of
your programs that uses an assert command.
(10 points) Write a program that reads a words and decides if it is the
same forwards and backwards. It says "yes" to 'abba' and no to
'laugh'. It must use pointers and not array indexing.
(9 points) Write a program that reads an integer, adds one to it, and
prints the result backwards.
(7 points) Write a program that reads a words and decides if it is the
same forwards and backwards. It says "yes" to 'abba' and no to
'laugh'.
(6 points) Write a program that reads a word and prints the number of
vowels. It must use pointers and not array indexing.
(6 points) Add operator+= with a Set as an argument to
http://euclid.nmu.edu/~randy/Classes/CS201CodeExamples/bitSet.cc.
(4 points) Add operator+ with a float argument to
http://euclid.nmu.edu/~randy/Classes/CS201CodeExamples/bitSet.cc.
(4 points) Write a program that reads a word and prints the number of
vowels.
(3 points) Write a program that uses the sizeof operator to print the
number of bytes needed to store an int, and float, a double and a long.
(3 points) Write me a program that reads a word and prints it
backwards. It must use pointers.
(2 points) Write a program that computes and prints the sum of the
numbers 1 .... 1000.
(2 points) Write me a program that reads a word and prints it
backwards. It must use pointers.