Ans:-
Syntax:-
for(initialization;condition;flow statement)
{
}
Code:-
for(j = -7; j<=7 ; j++)//no of iterations = 15
{-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7}
Total1++;
This loop runs from j =-7 to j = 7 insteps of increment of 1 of j
and Total1 increment by 1 in each iteration
Total1 = number of iteration = 15
| j value while condition | Total1 |
| -7 | 0->1 |
| -6 | 1->2 |
| -5 | 2->3 |
| -4 | 3->4 |
| -3 | 4->5 |
| -2 | 5->6 |
| -1 | 6->7 |
| 0 | 7->8 |
| 1 | 8->9 |
| 2 | 9->10 |
| 3 | 10->11 |
| 4 | 11->12 |
| 5 | 12->13 |
| 6 | 13->14 |
| 7 | 14->15 |
| 8(exit while) |
Total1 = 15
Code:-
for(j = 11; j>-11 ; j-=3)// no of iteration = 8
{11,8,5,2,-1,-4,-7,-10}
Total2+=2;
in each iteration Total2 increment by 2
Total2 = 2 x no of iteration = 2 x 8 =16
| j | Total2 |
| 11->8 | 0->2 |
| 8->5 | 2->4 |
| 5->2 | 4->6 |
| 2->-1 | 6->8 |
| -1->-4 | 8->10 |
| -4->-7 | 10->12 |
| -7->-10 | 12->14 |
| -10->-13 | 14->16 |
| -13!>-11 exit while |
Total2 = 16
Code:-
for(j = 1; j<=100 ; j*=3) // no of iteration =5
{1,3,9,27,81}
Total3+=j;
| j | Total3 |
| 1->3 | 0->1 |
| 3->9 | 1->4 |
| 9->27 | 4->13 |
| 27->81 | 13->40 |
| 81->243 | 40->121 |
| 243!<=100 exit while |
Total3 = 121
Code:-
for(k = 1; k<=5 ; k++)// no of iterations = 5 {1, 2, 3, 4,
5}
for(j=1;j<=k; j++)// no of iterations = k
Total4++;
in Nested for loop,
total iteration = 1+2+3+4+5
total iteration = 15
in each iteration , Total4 increment by one.
Total4 = 15
| k value | 1->2 | 2->3 | 3->4 | 4->5 | 5->6 | 6!<=5(exit while) |
| iteration of inner loop | 1 | 1->2 | 1->2->3 | 1->2->3->4 | 1->2->3->4->5 | |
| Total4 value | 0->1 | 1->2->3 |
3->4->5->6 |
6->7->8->9->10 | 10->11->12->13->14->15 |
Total4 = 15
Code:-
for(k = 1; k<=8 ; k+=2)//no of iteration = 4 {1, 3 , 5 ,
7}
for(j=9;j>0;j+=-2) )//no of iteration = 5 {9, 7 , 5 ,
4, 2}
for(m = 4 ;m<=12 ;m += 4) //no of iteration = 3 {4, 8
,12}
Total5++;
If number of iterations are fixed for each loop,
Total iteration = Iteration of first loop x Iteration of second loop x Iteration of third loop
Total iterations = 4 x 5 x 3 = 60
In each iteration Total5 increment by 1
Total5 = number of iterations = 60
Total1 = 15
Total2 = 16
Total3 = 121
Total4 = 15
Total5 = 60
Please appreciate the work by giving a thumbs up.
If any doubt, ask in comments.
Stay safe and keep HomeworkLibing.
File:EORI Nore This is just ample, the below. This best shows the pres best may lost...
Debugging: The code below has six errors. The errors may be syntax errors or logic errors, and there may be more than one per line; examine the code carefully to find them. Indicate each of the errors you find by writing the line number and correction in the space provided below. This program is designed to take a constant number of scores (3 in this case) and store them into an array. Then the array is passed to a function...
Bucket Management – In this programming exercise you will create a simple bucket management program according to the following customer specifications: Write the definition of a class Bucket, to implement the properties and functions of a bucket. The bucket must be Cylinder shaped of any dimension. (20%) The class should have the instant variables to store the height (in feet), radius (in feet), amount (in cubic feet) of water in the bucket, the rate (in gallons / minute), at which...
C++ For this assignment you will be building on the Original Fraction class you began last week. You'll be making four major changes to the class. [15 points] Delete your set() function. Add two constructors, a default constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Since Fractions cannot have...
First create the two text file given below. Then complete the
main that is given. There are comments to help you. An output is
also given You can assume that the file has numbers in it
Create this text file: data.txt (remember blank line at end)
Mickey 90
Minnie 85
Goofy 70
Pluto 75
Daisy 63
Donald 80
Create this text file: data0.txt (remember blank line at
end)
PeterPan 18
Wendy 32
Michael 28
John 21
Nana 12
Main
#include...
This is my Final Multiple Choice section of my Final Exam Please answer ABCD and neatly please and thank you and all questions are with microsoft visual studio c++. MULTIPLE CHOICE. Choose ONLY ONE alternative that best completes the statement or answers the question. 1) Which of the following statements are correct? 1) _______ A) char charArray[2][] = {{'a', 'b'}, {'c', 'd'}}; B) char charArray[2][2] = {{'a', 'b'}, {'c', 'd'}}; C) char charArray[][] = {{'a', 'b'}, {'c', 'd'}};D) char charArray[][]...
C++ assignment help! The instructions are below, i included the main driver, i just need help with calling the functions in the main function This assignment will access your skills using C++ strings and dynamic arrays. After completing this assignment you will be able to do the following: (1) allocate memory dynamically, (2) implement a default constructor, (3) insert and remove an item from an unsorted dynamic array of strings, (4) use the string class member functions, (5) implement a...
C++ Inheritance Problem Step a: Suppose you are creating a fantasy role-playing game. In this game we have four different types of Creatures: Humans, Cyberdemons, Balrogs, and elves. To represent one of these Creatures we might define a Creature class as follows: class Creature { private: int type; // 0 Human, 1 Cyberdemon, 2 Balrog, 3 elf int strength; // how much damage this Creature inflicts int hitpoints; // how much damage this Creature can sustain string getSpecies() const; //...
You will implement 2 games, the Prisoner's Dilemma, The Stag Hunt and compare their results for your report. After you finish implementing everything else, you will only need to change one function to make it a prisoner's dilemma or a stag hunt game 1) main.cpp: This is the driver program that sets up the game and plays it. This is where you will call functions to print the statistics. The required statistics is percentage of players using strategy 1 (cooperate...
Can someone please help me with the following: Implement a Binary Search Tree that can be used to store data values that are strings. The data values will be stored in nodes in a binary search tree. Each node will have a unique integer key. Provide functions to add, get and remove elements to/from the tree. Also provide functions to print the elements (both the key and the data values) in forward (dump) and reverse (dump_rev) order. To help in...
Use the following information to answer the questions below: Heat Power is a utility company that would like to predict the monthly heating bill for a household in a particular region during the month of January. A random sample of 18 households in the region were selected and their January heating bill recorded. The data is shown in the table below along with the square footage of the house (SF), the age of the heating system in years (Age), and...