CS250 Some Final Review Questions


Chapter 5 – Pointers and Strings

For question 1, use array notation and then pointer notation in your solution.

  1. The function atoi accepts a string and returns the string converted to an integer. The prototype is:
    int atoi (char s[]);

  2. The function itoa accepts an integer and returns the integer converted to a string. Return a pointer to the newly created string. Dynamically allocate the string memory.

Chapter 6 – Classes and Data Abstraction

  1. Declare a class called MyString that contains space for up to 256 characters including the null character and an integer size that contains the length of the string. Your class is to have two different constructors: a) accepts nothing and initializes the string to empty and b) accepts a character string initializing the string and size appropriately.

  2. How would you use a default arguments with the constructor to initialize the string to empty?
  3. Add methods setString, getString, and concatString to your class.

Chapter 7 – Classes Part II

  1. Rework questions 1-3 above using dynamic memory allocation

  2. A destructor was not necessary in your previous solution. Why?
  3. Add a destructor to the dynamic version you just implemented.

Chapter 8 – Operator Overloading

  1. For the class implemented above, overload the operators >>, <<, ==, and !=.

Chapter 9 – Inheritance

  1. Write the header file for a base class Student.

  2. Using inheritance write the header file for a derived class GradStudent and UndergradStudent. You decide what goes into the making of each class.
  3. Create an array that is capable of storing up to 100 graduate or undergraduate students.
  4. Implement a static data member that maintains a count of the number of employees.

Chapter 10 – Polymorphism

  1. What is the purpose of an abstract class?

  2. Give a reason for using a pure virtual function as opposed to a virtual function.
  3. What is polymorphism?
  4. Discuss the term “dynamic binding.”
  5. How might polymorphism be used in the Chapter 9 example?

Chapter 11 – Templates

  1. Work p. 11.3 on p. 735.

Note1: These are just some sample review questions for the final if you are looking for additional study problems.

Note2: I will not have time to provide answers to these questions.