Presentation is loading. Please wait.

Presentation is loading. Please wait.

Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009.

Similar presentations


Presentation on theme: "Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009."— Presentation transcript:

1 Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009

2 Part I: Hand-Written Exercises 1. Answer these questions about destructors. (a) What is a destructor and what must the name of a destructor be? (b) When is a destructor called? (c) What does a destructor actually do? (d) What should a destructor do?

3 2. You know that an overloaded assignment operator and a copy constructor are not inherited. Does this mean that if you do not define an overloaded assignment operator or a copy constructor for a derived class, then that derived class will have no assignment operator and no copy constructor? Please explain your reasons.

4 Part II: Programming Exercises 3. Write a program that accepts a C-string input from the user and reverse the contents of the string. Your program should work by using two pointers. The “head” pointer should be set to the address of the first character in the string, and the “tail” pointer should be set to the address of the last character in the string. The program should swap the characters referenced by these pointers, increment “head” and decrement “tail” until all characters have been swapped and the entire string reversed.

5 4. Create a class for a simple blog. The owner of the blog should be able to (a) post a new message, (b) numerically list and display all messages, and (c) select a specific message and delete it. Viewers of the blog should only be able to numerically list and display all posted messages. Create a class Viewer and a class Owner that uses inheritance to help implement the blog functionality. Store the messages using any format you like (a vector of type string may be easiest). A menu function should be implemented for each class that outputs the legal choices for the type of user. To test your classes, the main function of the program should allow the user to invoke the menus from the Viewer and Owner objects.

6 Homework Submission Due: 2 weeks (June 19, 2009) Hand-written exercises –Please write your names and answers on A4 papers. Programs –Forum: http://140.124.183.11/oop/ –Submission site: http://140.124.183.11/hw/


Download ppt "Homework #5: Pointers, Dynamic Arrays and Inheritance By J. H. Wang Jun. 5, 2009."

Similar presentations


Ads by Google