Question
This is C++ Programming 1. Implement a program that lets the user enter a positive number and then prints the result calculated by the following
This is C++ Programming
1. Implement a program that lets the user enter a positive number and then prints the result calculated by the following function. Validate the input until a positive integer is entered. Write a recursive function that computes n * n/3 * n/9* n/27 * n/81...where n is a non negative integer, n/x is integer division and the quotient is always a multiple of 3 from the previous quotient. The sequence repeats as long as n/x > 0. For example:
27: 27 * 9 * 3 * 1 = 729
8: 8 * 2 = 16
100: 100 * 33 * 11 * 3 * 1 = 108900
The function prototype should be: int recursive (int n) ;
Example:
Input: 27
Result: 729
2. Design a class named Lunch Box. The class should have the member variables width, size, color, and food. Declare all member variables as private. Add a default constructor and a constructor that expects values for all member variables as parameters and assigns each value to the corresponding member variable. Also, add a getter function for each member variable. Add a setter function for the food member variable only. Declare all constructors and functions as public.
In the main, create one object of the Lunch Box class. Create a second instance as a pointer to an object. Set the values for all member variables of each object. Library: Dont forget to include
3. Design a class that determines the monthly home mortgage payment. The monthly payment with interest compounded monthly is calculated as follows:
payment = loan x (rate/12) x term where term = (1 + rate/12)^ 12 x years
Note:
payment= the monthly required payment
loan= the dollar amount of the loan
rate= the interest rate
years= the number of years of the loan
The class should have member functions for setting the loan amount, interest rate, and number of years of the loan. It should also have member functions for returning the monthly payment amount and the total amount paid to the bank at the end of the loan period. It should have a function named calculate, that calculates the monthly payment and stores the result in a member variable. Declare all member variables private and the constructor, getter and setter functions public.
In the main, prompt for the required input values (do not accept negative values), create an object of the home mortgage class, set the values, and output the calculated monthly payment and total amount paid to the bank.
Library: You may use the pow function from include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started