Group 3 Exercises

Programming Exercises. These exercises are used to apply the concepts learned in this session. Please do attempt them in small groups if possible. 

You are invited to ask questions during the seminar time.


Exercise 1:

Create a function template to define a maximum function that will determine the maximum of three values. Create a testing program for the function. You should test your program with integers, doubles, and characters. The output of the test program should be similar to the following:

Input three integer values: 1 2 3 
The maximum integer value is: 3
Input three double values: 3.3 2.2 1.1
The maximum double value is: 3.3
Input three characters: A C B
The maximum character value is: C


Exercise 2:

Write a simple function template for predicate function isEqualTo that compares its two arguments of the same type with the equality operator (==) and returns true if they are equal and false otherwise. 

Use this function template in a program that calls isEqualTo only with a variety of fundamental types. 

Now write a separate version of the program that calls isEqualTo with a user-defined class type, but does not overload the equality operator. What happens when you attempt to run this program? 

Now overload the equality operator (with the operator function) operator==. Now what happens when you attempt to run this program?



Last modified: Tuesday, 11 December 2018, 6:27 AM