Title: Chapter 7 Review
Course: Programming Fundamentals II (TEMPLATE)

COSC 1337 - Programming Fundamentals II

Chapter 7 Review Exercises

I recommend that you review the chapter by doing these exercises. I will NOT grade these exercises.

Consider reviewing the Checkpoint questions from this chapter.
Answers to Checkpoint questions are in Appendix P (on the CD that came with your textbook).

Review Questions and Exercises: 1, 3, 7, 17, 23, 25, 29, 31, 33, 37, 39.
Answers to Review Questions and Exercises are in Appendix Q (on the CD that came with your textbook).

Other Questions

Note: Structs will not be covered on Exam 1.

1. Create a simple class called Item (to represent an inventory item) with private data members:

- item number (an integer)
- description (a string)
- price (a floating-point value)

In the class definition include prototypes for public member functions:

- a constructor that sets item number and price to zero and description to the empty string
- a set function that checks for valid values for all data members (item number and price should not be negative)
- separate get functions that return the values of each data member

After the class definition, write the definitions for the member functions (do not put the function code inside the class definition).

2. Write client code to create an Item object called myItem. Then write code to set it's item number to 10, it's description to "Granny Smith Apples", and it's price to 1.89.

3. Creating an Item object and setting it's data members to values specified by the client programmer takes 2 statements with the Item class code written so far. Add a second constructor to the class so that the client programmer can declare an Item object and specify initial values for it's data members in a single statement.

4. Write a declaration for an Item object that calls your constructor from the previous problem.

Answers to Other Questions are here.

© Austin Community College 2016. The content on this page is licensed under a
Creative Commons Attribution 4.0 International License.
Last updated: July 9, 2013