Trace Class
For each of the follwing, what will be printed when it is run. If it produces a compile or runtime error, just put error. If prints something, but it can’t be predicted, put unknown.
class Point { private: int x, y; public: Point(); }; Point::Point() { this->x = 0; this->y = 0; int main() { Point point; std::cout << point.x << " " << point.y << std::endl; return 0; }
class Point { private: int x, y; public: Point(); int get_x() const; int get_y() const; friend void print(const Point& point); }; Point::Point() { this->x = 0; this->y = 0; } int Point::get_x() const { return this->x; } int Point::get_y() const { return this->y; } void print(const Point& point) { std::cout << point.x << " " << point.y << std::endl; } int main() { Point point; std::cout << point.get_x() << " " << point.get_y() << std::endl; print(point); return 0; }
class Point { private: int x; int y; public: Point(); Point(const Point& point); ~Point(); Point& operator=(const Point& point); }; Point::Point() { std::cout << "default constructor" << std::endl; } Point::Point(const Point& point) { std::cout << "copy constructor" << std::endl; } Point::~Point() { std::cout << "destructor" << std::endl; } Point& Point::operator=(const Point& point) { std::cout << "assignment operator" << std::endl; return *this; } Point func(Point p) { return p; } int main() { Point p; Point q(p); Point r; r = p; Point s = func(q); return 0; }
Circular Array Class Pseudocode
On paper, create Pseudocode for the circular array class. The pseudocode should list the names and types of all of the instance variables. It should also list all of the functions including the return type and the names and types of all function the parameters. For each function in the class, include a description, in plain English, of what the function will do.
Circular Array Test Cases
In Emacs, create a C++ program that will test the circular array class. For each test case print what the expected output will be. Be sure to create test cases for edge cases like when the array is filled, when the start or end wraps around to the beginning of the array, and when the array is emptied.