Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// 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 5 #include 6 using namespace std; 7 8 int main() 9 { 10 int denom, // Denominator of a particular term 11 finalDenom = 64; // Denominator of the final term 12 double sum = 0.0; // Accumulator that adds up all terms in the series 13 14 cout << "PUT YOUR NAME HERE. "; 15 16 // WRITE THE CODE TO START A FOR LOOP THAT LOOPS ONCE FOR EACH TERM. 17 // I.E., FOR TERMS WITH DENOMINATORS FROM 2 TO THE FINAL DENOMINATOR. 18 { 19 // WRITE THE CODE TO PRINT THIS TERM. 20 // IF IT IS NOT THE LAST TERM, FOLLOW IT WITH A +. 21 // IF IT IS THE LAST TERM, FOLLOW IT WITH A =. 22 23 // WRITE THE CODE TO ADD THE VALUE OF THIS TERM TO THE ACCUMULATOR. 24 } 25 26 // WRITE A LINE OF CODE TO PRINT THE SUM. 27 28 return 0; 29 }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions