Part 1
1. This chapter uses the class rectangleType to illustate how to overload the operators +, *, ==, !=, >>, and <<. In this exercise, first redefine the class rectangleType by declaring the instance variables as protected and then overload additional operators as defined in parts a to c.
a. Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. (Note that after decrementing the length and width, they must be postive.)
b. Overload the binary operator - to subtract the dimensions of one rectangle from the corresponding dimensions of another rectangle. If the resulting dimensions are not positive, output an appropriate message and do not perform the operation.
c. The operators == and != are overloaded by considering the lengths and widths of rectangles. Redefine the functions to overload the relational operator by considering the areas of rectangles as follows: Two rectangles are the same, if they have the same area; otherwise, the rectangles are not the same. Similary, rectangle yard1 is greater than rectangle yard2 if the area of yard1 is greater than the area of yard2. Overload the remaining relational operators using similar definitions.
d. Write the definitions of the functions to overload the operators defined in parts a to c.
e. Write a test program that tests various operations on the class rectangleType.
Part 2
a. Rewrite the definition of the class complexType so that the arith-metic and relational operators are overloaded as nonmember functions.
b. Write the definitions of the member functions of the class complexType as designed in part a.
c. Write a test program that tests various operations on the class complexType as designed in parts a and b. Format your answer with two decimal places.
Part 3
Write a program that prompts the user to enter time in 12-hour notation. The program then outputs the time in 24-hour notation. Your program must contain three exception classes: invalidHr, invalidMin, and invalidSec. If the user enters an invalid value for hours, then the program should throw and catch an invalidHr object. Similar conventions for the invalid values of minutes and seconds.
Part 4
Write a program that prompts the user to enter a person's date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Similar conventions for the invalid values of month and year. (Note that your program must handle a leap year.)
Part 5
Write a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, then the pattern generated is:
****
***
**
*
*
**
***
****
Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the above pattern.
Part 6
Write a recursive function, vowels, that returns the number of vowels in a string. Also, write a program to test your function.