Question
// Lab 5 - summation.cpp // This program displays a series of terms and computes its sum. // PUT YOUR NAME HERE. #include #include using
// Lab 5 - summation.cpp // This program displays a series of terms and computes its sum. // PUT YOUR NAME HERE. #include#include using namespace std; int main() { int denom, // Denominator of a particular term finalDenom = 64; // Denominator of the final term double sum = 0.0; // Accumulator that adds up all terms in the series cout << "PUT YOUR NAME HERE. "; // WRITE THE CODE TO START A FOR LOOP THAT LOOPS ONCE FOR EACH TERM. // I.E., FOR TERMS WITH DENOMINATORS FROM 2 TO THE FINAL DENOMINATOR. { // WRITE THE CODE TO PRINT THIS TERM. // IF IT IS NOT THE LAST TERM, FOLLOW IT WITH A +. // IF IT IS THE LAST TERM, FOLLOW IT WITH A =. // WRITE THE CODE TO ADD THE VALUE OF THIS TERM TO THE ACCUMULATOR. } // WRITE A LINE OF CODE TO PRINT THE SUM. return 0; }
LAB 5.6 Complete Program
Step 1: Remove areas2.cpp from the project and add the summation.cpp program in your Lab5 folder to the project. This file contains just a program shell in which you will write the programming statements needed to complete the program described below. Here is a copy of the file.
1 // Lab 5 - summation.cpp 2 // This program displays a series of terms and computes its sum. 3 // PUT YOUR NAME HERE. 4 #include
Step 2: Design and implement the summation.cpp program so that it generates and prints the terms and the sum of the following series: 1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64
Sample Run:
1/2 + 1/4 + 1/8 + 1/16 + 1/32 + 1/64 = .984375
Step 3: Modify the program so that it generates and prints the terms and the sum of this series up through the nth term, where the user enters a value for n between 2 and 10.
For example, if the user enters 5, the program will display the terms and compute and print the summation of the following terms: 1/21 + 1/22 + 1/23 + 1/24 + 1/25
This will require the addition of much more program logic as well as some additional variables.
Sample Run:
This program sums the series 1/2^1 + 1/2^2 + 1/2^3 + . . . + 1/2^n
What should n be in the final term (2 - 10)? 5
1/2 + 1/4 + 1/8 + 1/16 + 1/32 = .96875
Step 4: Once your program is working correctly, add a bottom test loop to the program that asks the user if he or she wishes to compute another series, and which continues to iterate so long as the user enters y or Y. You will need additional program logic and a new variable to do this.
Step 5: Test your program with the following inputs before entering y to quit.:
5
6
8
10
If your program is working correctly, all the sums will be less than 1. If they are not, you have a logic error which you need to find and fix.
Step 6: If your professor asks you to do so, print the final, revised source code and the output created by the inputs shown in step 5.
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