Name Bryan Ferreira 1) Copy the following program from the blackboard “content “ area or type it into Visual C++ and get it running in Visual C++. // program to demonstrate loops and output...


Name Bryan Ferreira


1) Copy the following program from the blackboard “content “ area or type it into Visual C++ and get it running in Visual C++.


// program to demonstrate loops and output manipulation on display screen.


#include


#include


using namespace std;



int main()


{



int x, m;



x = 1;



m = 1;



while (x //start loop and check condition



{



cout x "*" m "=" m * x endl;



x++;



}




cin >> x;



return 0;



}


a) Copy the output created by this program by using the snipping tool and paste it below. Explain how the program operates in terms of creating the output you copied below.


This program which involves two integers m, and x; is a simple program which creates a multiplication table with the x integer increasing by one increment every line. This table is produce by a loop that when x is under 5, the loop will continue to multiply m and x with x increasing every time until it reaches 5, and since the statement does not have an equal to sign, it does not show the multiplication of x being 5


B) Comment out the increment line as follows // x++; Then rebuild and re-run the program. Explain below why this creates the output you see.



The loop continuously multiplies m and x but at the end of the loop, x is not increased so the loop continues to add the two integers at their starting value of 1, and never ends because the statement will never be false.




C) Remove the comment lines from step b) and change the comparison statement from (x 5). Rebuild the program and run it. Explain why you get the output you see?


Since the statement is change to where x is greater than 5, the loop never begins because the statement is not met from the beginning so the program skips over the loop and produces no output.




D) Keeping the change in step c and change the assignment of the x value to



X= 6;. Again, rebuild and run the program. What happens and why?


The loop runs infinitely because since x starts with the value of 6, and the statement reads when x is greater than 5, the loop will continuously add 1 to five which makes the statement always true because x will continue to be grater than 5.









E) Change the loop program to create the following results. There are ten blanks between each character using the setw() command. That is




` 1 * 1 = 1



















































Explain below what you changed and why to create the output in step e.


To create the output shown above, I simply added a setw(10) after each character in the cout command in the loop. This created ten spaces in comparison to the character before them crating the output shown above.













2) A little more of a challenge, change the program to create the following output



Explain what you changed and why?















3) Stepping up the challenge, try altering the program to create the following. Hint, note what is happening to x and you need to use nested loops.



4) Now let’s introduce the clear screen command. The system("cls"); sequence will clear the screen. Get the program to display one set at a time, like the following.










Etc.






5) Now change the “while loops” in the previous program to “for” loops. Get the program running and copy your program to the area below . Upload your results of this lab to Blackboard.





6) Copy in the program for the temperature conversion. Get the program running and now add in using elseif the conversion of Kelvin to F, Conversion of F to Kelvin as well Once you program is running copy and paste below.



Mar 03, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here