Question: in c++ Class Inheritance part 1. For this lab, you will create several sum classes (you can re-use parts of some of your homework assignments),

in c++ Class Inheritance

part 1.

For this lab, you will create several sum classes (you can re-use parts of some of your homework assignments), then a main class which will inherit all of the others (using multiple inheritance) and an instance of the main class will be used in your main source file to execute all of the functions.

Create a header file (ex. sums.h), and a main source file (main.cpp).

1. Create a class called sum1. Within this class create a public function called sum that takes a positive integer input n and sums up the numbers from 1 to n and stores the result as a protected variable.

2. Create a class called sum2. Within this class create a function called sumsq that takes a positive integer input n and sums up the squares of the numbers from 1 to n and stores the result as a protected variable.

3. Create a class called sum3. Within this class create a function called sumcube that takes a positive integer input n and sums up the cubes of the numbers from 1 to n and stores the result as a protected variable.

4. Create a class called sumsum. Within this class create a function called sumsums that takes a positive integer input n and sums up the sums of numbers from 1 to 1, 1 to 2, 1 to 3, 1 to 4,,1 to n (and stores the result as a protected variable). ex. for n=4: sumsums(4)= 1 + (1+2) + (1+2+3) + (1+2+3+4). You could potentially inherit the sum1 class and use that function.

5. Create a class called sumfull that inherits all of the other classes (sum1, sum2, sum3, sumsum). Within this class create a function called allsums that takes a positive integer input then uses the functions from all of the inherited classes to execute each sum and then prints all of the results.

6. In your main source file, create an instance of the class sumfull and execute the function allsums to carry out the calculations and print the results. Make sure to ask the user for a positive integer first.

Part 2.

For this assignment you will be extending the program you wrote for the class inheritance lab (the sums lab). . Add the following classes to your header file from part 1: ]

1. Create a class called sumeven. Within this class create a public function called sumeven that takes a positive integer input n and sums up the even numbers between 1 and n and stores the result as a protected variable.

2. Create a class called sumodd. Within this class create a public function called sumodd that takes a positive integer input n and sums up the odd numbers between 1 and n and stores the result as a protected variable.

3. Create a class called sumgeometric. Within this class create a public function called sumgeom that takes as inputs a positive integer n and a positive double a. The function should compute the geometric sum with base a up to the power n and stores the result as a protected variable. That is, the sum is: 1 + + 2 + 3 + 4 + +

4. Create a class called productsum. Within this class create a public function called prodsum that takes as input a positive integer n and computes the following productsum mix: 1 * (1+2) * (1+2+3) * (1+2+3+4)**(1+2+3++n) and stores the result as a protected variable.

5. Add (inherit) all of the new classes to the existing sumfull that inherits all of the other classes. Make sure to add all of the functions to the allsums function in sumfull. Update allsums so it will take a double along with an int as input (double needed for geometric sum).

6. This should already be set up so you should not have to change much. In your main source file, create an instance of the class sumfull and execute the function allsums to carry out the calculations and print the results. Make sure to ask the user for a positive integer and a double (to be used for the geometric sum).

Bonus (2 points) Create a class called exptowers. Within this class create a public function called exptower that takes as input a positive integer n and computes the following: 2 3 4 5 6 And stores the result as a protected variable. Make sure to inherit this class in sumfull and add the function to allsums. Note: the computation is NOT the same as 2^3^4^5^^n (unless you correctly use parentheses). Be careful how you compute it.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!