Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Loop for ( int i=0;i <10;i++) { cout < < i < < endl; } For ( initialization , Logical test , post-operation )

For Loop

for (int i=0;i<10;i++)

{

cout << i << endl;

}

For ( initialization , Logical test , post-operation )

Initialization: this is typically where loop control variables are assigned (scope will be restricted to loop). Additional variables are separated by commas. Note that method calls or any single statement will compile.

Logical test: while this is true the loop will continue. Like before this could be a method call but it must return a Boolean.

Post-operation: this is typically where the loop control variables are incremented/decremented but other calls could be made. Like with the initialization multiple variables can be modified by adding a comma between.

While Loop

int i=0;

while (i<10)

{

cout << i << endl;

}

Loop until some condition is satisfied. Preferred when you do not need loop control variables like used in the for loop. Also convenient for when you want to loop to some undetermined amount of time (EX. A game looping until the player decides to turn off the game).

Do/While Loop

The difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top.

How is this useful:

  • Initialization could be handled in the do/while, and the compiler would accept its use after the loop.

Graphics, or any other area where you want at least one pass through an algorithm

Below are a list of sequences of numbers. Your job is to program each sequence with any loop of your preference (while, for, do/while). I want the code to output the sequence provided and the next number in the sequence (you can output more but there is 1 sequence that may only have 1 number after). Each sequence is worth 10 points and each additional sequence beyond 10 completed will be worth 5 points (for a total of 115 if you complete them all). Each sequence should be in the same main in one .cpp file. Your submission should be a .cpp file. No credit will be given should the student submit the .sln or project file. Please order and notate each sequence in your output if you skip one for whatever reason, output the series number and leave the rest blank. The output should also be horizontal like that shown below (if you output it vertically it will be -10pts). Each sequence should be programed with only 1 loop and optionally 1 selection statement.

Note that no credit will be given to those who simple cout the entire sequence, you must use loops to step through the sequence.

Series 1:

18, 17, 16, 15, 14, ...

Series 2:

4, 5, 8, 17, 44, ...

Series 3:

2, 3, 5, 8, 12, 17, ...

Series 4:

1, 2, 5, 26, 677, ...

Series 5:

10, 5, 1, -2, -4, -5, -5, -4, -2, ...

Series 6:

1, 8, 27, 64, 125, 216, ...

Series 7:

0, 1, 3, 7, 15, 31, 63, ...

Series 8:

0, 1, 4, 13, 40, 121, ...

Series 9:

15, 29, 56, 108, 208, 400

series 10: (finite)

0, 1, 3, 6, 10, 10, 11, 13, 16, 16, 17, 19, 19, ...

series 11:

7, 9, 14, 20, 27, 33, 42, 52, 63, 73, 86, ...

Series 12:

13, -21, 34, -55, 89 ...

Series 13:

0, 1, 4, 12, 32, 80, 192, ...

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions