Write a recursive function

Assignment Help C/C++ Programming
Reference no: EM13509762

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.

Reference no: EM13509762

Questions Cloud

What is the disks new angular speed : A bug (2 grams) crawls from the center to the edge of a disk that is freely turning at 20 rpm. What is the disk's new angular speed
Write definitions of the functions to overload the operators : Write the definitions of the functions to overload the operators defined in parts a to c and write  a  test  program  that  tests  various  operations  on  the class rectangleType.
Evaluate and discuss the comparative forms : Evaluate and discuss the comparative forms of doing business and discuss the pros and cons of each, explaining your rationale in detail. Which form would you use? Why?
Amount relates to the factory : 75% of this amount relates to the factory.
Write a recursive function : Write a recursive function, vowels, that returns the number of vowels in a string and write the definitions of the functions to overload the operators defined in parts a to c.
Explain lamar performed legal services for e. garr : Lamar performed legal services for E. Garr. Due to a cash shortage, an agreement was reached whereby E. Garr. would pay S. Lamar a legal fee of approximately $8,000 by issuing 2,000 shares of its common stock (par $1).
Find the minimum diameter of an given brass wire : Find the minimum diameter of an l = 18.9 m long brass wire that will stretch no more than 9.38 mm when a mass of 312 kg is hung on the lower end
Complete a new performance report for the quarter : Complete a new performance report for the quarter
Calculate the kinetic energy of the bowling ball : A bowling ball, which can be treated as a solid sphere with a diameter of 21.6 cm and a weight of 33 kg, The kinetic energy of the bowling ball is

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Grab the tokens from the token vector and find single quot

There is segmentation fault in this code and I don't know where or how to fix it. The purpose of this code right here is to grab the tokens from the token vecctor and find single quotes.

  Create a text adventure game that uses pointers

Create a text adventure game that uses pointers. You have a rich, eccentric Uncle Billy who is soon to be deceased.

  Optimization is to add a sorting algorithm

The second optimization is to add a sorting algorithm. Each time you add an item to the array (from disk or from keyboard), you call a function called SortMyArray(), which use the bubble sorting algorithm to sort the array in the ascending order, ..

  Program that read in from the key board a string

Write a complete C++ program that read in from the key board a string and convert all letters in the string to upper cases. You are not allowed to use toupper function.

  The stack parameters will not be const reference

In this second case, the stack parameters will not be const reference parameters because they are temporarily changed before being restored. As an alternative, the parameters could be value parameters (so that changing them does not affect the act..

  Loops in what ways are the initialization repetition test

in what ways are the initialization repetition test and update steps alike for a sentinel-controlled loop and an

  Lexicographically preceding permutation

Output a single line containing a space separated list of integers which is the lexicographically preceding permutation of the input permutation.

  Write a recursive function that takes a string as parameter

Write a recursive function that takes a string as a parameter and prints its reversal in the same function in c++

  Write program to declare the array of type float

Write down the c++ program which declares the array of 50 components of type float. Initialize array so that first 25 components are equal to square of the index variable.

  Implement a function to recursively

Implement a function to recursively determine if a word is a palindrome. A palindrome is a word, phrase, number, or other sequence of symbols or elements, whose meaning may be interpreted the same way in either forward or reverse direction.

  Child process to take the role of the number guesser

Write a program in C that takes a number between 1 and 1024 as input on the command line, and then forks a child process to take the role of the number guesser

  Calculate the trajectory of a soccer ball

Write a program to calculate the trajectory (flight path) of a soccer ball

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd