CSCI 216 Fall 2013 Exam
#2
Instructions:
The usual…this test is closed book, closed notes, closed computer,
closed neighbor, calculator, cell phone, etc.
Write your answers in the space provided. If you need more space, use the back of one
of the pages and indicate where I can find your answer. Write legibly, since if I can’t read it, it’s
wrong. Not counting the bonus there are
100 points on the test. Good luck and
have fun.
(4 points each)
1.
What
is the decimal value of the binary number 1010 0101?
2.
What
is the decimal value of the hexadecimal number 0x125E?
3.
What
is the value of 54 ^ 87?
4.
What
is the binary value of 54 & 87?
5.
What
is one advantage of using a linked list instead of an array?
6.
What
is one advantage of using an array instead of a linked list?
7.
What
is the C++ code that you write to include your linked list declaration file,
list.h, in the file containing your main program?
8.
What
are the two main sections of a class declaration?
(5 points each)
For the
following questions, assume that we have class called list that is a singly linked list of nodes that store integers, with a pointer called head that points to the first element
of the list, and that if the list is empty, head contains the NULL
pointer.
9.
Write
C++ code to insert a new integer at the front of the list.
10.
Write
C++ code to count the number of elements in the list and to store that value in
the variable cnt.
11.
Write
the function prototype for the default constructor of the list class as it is contained in the class declaration (the “dot h”
file).
12.
What
is the C++ code that you put at the start and the end of every include file so
that the actual C++ code is only included once in any one file?
(6 points each)
13.
Write
the function prototype for member function add of the fraction class that takes
two fractions and returns a fraction as their sum.
14.
Write
the function prototype for an overloaded operator member function + that takes
two fractions and returns a fraction as their sum.
15.
Write
the function prototype for an overloaded operator member function + that takes
two complex numbers, or a complex number and another number of any type, and returns
their sum as a complex number.
16.
Write
the function prototype for an overloaded operator member function that takes a
complex number and prints it out to the screen or a file.
For the
following problems, consider a doubly linked list, where every node contains next and prev pointers,
and an integer variable named data. The list has two pointers, head and tail, that point to the first and last elements of the list. For the first element in the list, prev is the NULL pointer, and similarly for the next pointer in the last element of the list. If the list is empty, both next and prev are the NULL
pointer. The member functions you write
should be just like you would write them in the “dot cpp” file for the list
member functions. (6 points each)
17.
Write
a member function named empty that
returns true if the list is empty
and false otherwise.
18.
Write
a member function named insertBack
that takes an integer and inserts it at the end of the list.
19.
Write
a member function named removeFront
that removes and returns an integer from the front of the list, freeing up the
memory used to hold the integer.
20.
Write
a member function named search that
takes an integer and returns true if
the integer is in the list and false otherwise.
BONUS: (5 points) The usual Sudoku…fill in the blanks
so that each row, column, and highlighted 3x3 box contains each of the integers
1 through 9 exactly once.
|
5 |
|
|
3 |
|
6 |
|
9 |
|
|
|
|
4 |
2 |
7 |
5 |
|
|
|
3 |
9 |
|
|
|
2 |
8 |
|
|
6 |
1 |
|
5 |
|
|
|
|
3 |
|
|
|
|
|
6 |
|
|
|
|
4 |
|
3 |
2 |
|
|
6 |
7 |
|
|
|
4 |
3 |
|
|
|
4 |
8 |
3 |
2 |
|
|
|
|
3 |
|
5 |
|
8 |
|
|
4 |
|