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

COSC 1337 - Programming Fundamentals II

Chapter 8 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

1. Write a value-returning function that calculates and returns the sum of the elements in a one-dimensional array of float values. The array and the array length should be parameters to the function.

2. Using the following Item struct definition:

    struct Item
    {
       int itemNo;
       string desc;
       float price;
    };

Write the declaration for an array of 150 Item structs called inventory. Then write code to set the item number of the first Item in inventory to 10, it's description to "Granny Smith Apples", and it's price to 1.89.

3. Using the Item struct from question 2 above, write a function that prints the descriptions of all the elements in array inventory where the price is 2.0 or over. You can assume that the array is full.

4. Using the Item struct from question 2 above, write a function that returns a count of the number of elements in array inventory that have a price of 2.0 or greater.

5. Using the following Item class definition:

    class Item
    {
    private:
       int itemNo;
       string desc;
       float price;
    public:
       Item();
       void set( int newItemNo, string newDesc, float newPrice );
       int getItemNo();
       string getDesc();
       float getPrice();
    };
    Item::Item()
    {
       set( 0, "", 0.0 );
    }
    void Item::set( int newItemNo, string newDesc, float newPrice )
    {
       if ( newItemNo >= 0 )
          itemNo = newItemNo;
       else
          itemNo = 0;
       desc = newDesc;
       if ( newPrice >= 0.0)
          price = newPrice;
       else
          price = 0;
    }
    int Item::getItemNo()
    {
       return itemNo;
    }
    string Item::getDesc()
    {
       return desc;
    }
    float Item::getPrice()
    {
       return price;
    }

Write client code to declare an array of 150 Item objects called inventory. Then write code to set the item number of the first Item in inventory to 10, it's description to "Granny Smith Apples", and it's price to 1.89.

6. Using the Item class from question 5 above, write a function that prints the descriptions of all the elements in array inventory where the price is 2.0 or over. You can assume that the array is full.

7. Using the Item class from question 5 above, write a function that returns a count of the number of elements in array inventory that have a price of 2.0 or greater.

8. Write a value-returning function that calculates and returns the sum of the elements in a two-dimensional array of int values. Assume that global constant NUM_COLS contains the number of columns in the array. The array and the number of rows in array should be parameters to the function.

9. Write a function that sets all values in a two-dimensional array of double values to 1.0. Assume that global constant NUM_COLS contains the number of columns in the array. The array and the number of rows in array should be parameters to the function.

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 12, 2013