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

  Design and implement a library system that does the

design and implement a library system that does the following ? takes details of a studentlibrary users first name last

  Write a program in which the program print out the input

use (switch statement) to write a program in which the program print out the input (single character) if the character is not '2','t', or 'w'. Use 'default' and 'break' wisely.

  The factorial of a positive integer n, denoted by n!

Write a program that computes the sequence of factorial values: 1! = 1, 2! = 2, 3! = 6, 4! = 24, 5! = 120, 6! = 720, ....

  Write a program that reads a collection of positive numbers

Write a program that reads a collection of positive and negative numbers and multiplies only the positive integers. Loop exit should occur when three consecutive negative values are read.

  The funtion should take as parameters

Write a function in c ++ that multiplies two functions. the funtion should take as parameters two fraction structures. Then, the function should multiply the two fractions and return the solution as a fraction structure.

  Using an abstract class with only pure virtual functions

Using an abstract class with only pure virtual functions, create three small classes unrelated by inheritance---clases Building, Car and Bicycle. Give each class some uique appropriate attributes and behaviors that it does not have in common with oth..

  Repeat these questions by writing functions

Repeat these questions by writing functions that receive the arrays as constant reference parameters and return the appropriate values through the function name (via return statement). The function header could look like:

  Write c program to accept inputs from user

Write down simple c program which accepts following inputs from user that is username and password, it must ask user what he will like to learn today and also ask user to enter char m=math , e= English.

  Assume that a text file named text1txt contains text

Assume that a text file named text1.txt already contains some text written into it, write a function named vowelwords(), that reads the file text1.txt and create a new file named text2.txt,

  A file (complex.txt) which has a number of complex numbers

Read in a file (complex.txt) which has a number of complex numbers in the form of a+bi (e.g. 3+5i  2-3i etc).

  Returns a count of the steps through the sort

Please write a c++ implimentation that returns a count of the steps through the sort. (do not worry about updating count, I will rewrite that segemnt. I need help with writing the shell sort.

  Functions to make a main program

write the required functions to make a main program that is already written

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