This exam is open book. You may use your notes from the course, Stroustrup text, and Jossuttis text. If you use any print or electronic source(s) (e.g., other textbooks, and Internet resources) other than those specifically noted above to generate a solution, you must properly cite the source (see links on class WWW page). You may not communicate with any person, except the instructor, about any aspect of the exam until after the hand-in deadline, even if you have already completed your exam. Moreover, you may not use notes or problem solutions from other times this course has been taught or contact any person from a previous semester about this exam.
When preparing to submit your exam, strictly follow these instructions.
Exams are due July 30, 2007 at Noon, Eastern daylight time. Late exams will not be accepted and a grade of zero will be assigned for the exam unless express consent has been received from Mr. Boon prior to distribution of the exam.
Should you need to reach Mr. Boon outside of office hours, you may phone (301) 606-4115 cell number and leave a message. Email sent to John E. Boon, Jr. will be answered only in the evenings during the exam period
Boolean type (keep in
mind all of the C++ syntax and semantic implications such as
including scope, naming, and conversion when providing your
answer) (10 pts):
#define TRUE 1
#define FALSE 0
#define Boolean int
enum Boolean { false, true };
class Boolean {
. . .
public:
//various member functions
//including overloading ! && || == !=
};
this pointer to be
modifiable. One use was to have user-controlled storage management
by assigning directly to the this pointer. The
assignment of zero meant that the associated memory could be
returned to free store. Explain why this was a bad idea. (10
pts)class Empty so that the C++ compiler does
not automatically generate any methods. Use the most efficient
code you can and write the least amount of code you can in
solving this problem. (20 pts)
class Base {
public:
~Base();
};
class Empty: Base {};
int main() {
Empty e1;
Empty e2 = e1;
e2 = e1;
Empty *pe2 = &e2;
const Empty *pe1 = &e1;
}
Employee and
Manager culminating in examples in section 12.2.6.
class
Person that would serve as a parent for
Employee. (10 pts)class Customer that is derived from
class Person, and ensure that (10 pts)
class Customer can marry
objects of class Employee or class
Manager (define the operator + to mean
marriage).class Employee and
class Manager cannot marry one another;
"company" policy prohibits such marriages
//Incorrect bubble sort
#include <iostream>
void swap (int a, int b)
{
int temp = a;
a = b;
b = temp;
};
void bubble (int a[], int size)
{
int i, j;
for(i = 0; i != size; ++i)
for(j = i; j != size; ++j)
if(a[j] < a[j + 1])
swap (a[j], a[j + 1]);
};
int main()
{
int t[10] = {9, 4, 6, 4, 5, 9, -3, 1, 0, 12};
bubble(t, 10);
for (int i = 0; i < 10; ++i)
std::cout << t[i] << '\t';
std::cout << "\nsorted? " << endl;
return 0;
}
class base {
. . .
public:
virtual void iam() { cout << "base\n"; }
. . .
};
class base, and for each define iam()
to write out the name of the class. (5 pts)
iam() from them. (5 pts)
iam() through the pointers. (5 pts)
virtual keyword from the base class member function, run your
code in the previous three steps again, and compare the results obtained with the previous
three results obtained. (5 pts)
#include <iostream>
int f() {
int input;
std::cin >> input;
return input;
}
int i = f();
int main() {
std::cout << "The value of i is " << i << std::endl;
}
Copyright © 2007 John E. Boon, Jr.