Lab 4 - for loops and logical operators
Lab 4_1 - 10 points
- Project name: yourname4_1
- cpp file name: yourname4_1
- Use the "for loop" example code from the programming web site
- Compile and run the program and watch what happens
- Print your .cpp file and hand write an explanation of what is happening
Lab 4_2 - 10 points
- Project name: yourname4_2
- cpp file name: yourname4_2
- Create a program that loops 5 times using the variable j (go from 1 to 5)
- Use the style for (x=1; x<=5;x++)
- Inside the loop, take the current value of your variable j and multiple
it by 2
- Display the result of j * 2 to the screen
Lab 4_3 - 10 points
- Project name: yourname4_3
- cpp file name: yourname4_3
- Create a program like the one above, but instead of using the increment
expression ++, count DOWN from 10 to 1 in your loop (start with x = 10, and
count down to 1). You will need to use the decrement expression --.
Lab 4_4 - 10 points
- Project name: yourname4_4
- cpp file name: yourname4_4
- Write a loop that will run three times
- Inside the loop, ask the user to input an integer value
- Test whether the number is greater than, less than, or equal to 100
- Output a message that tells the user the answer to your "test"
Lab 4-5 Logical Operators
- Create a program that asks the user to input a whole number between 1 and
100.
- Test whether the number is between 1 and 10, or 11 and 20, or 21 and 30,
etc.
- Display a message to the user that "Your number is between 51 and 60!
- Make the program run three times
Lab 4-6 - User-Controlled loops
- Ask the user for a number between 1 and 10
- Based on the user's response, create a simple for loop that will run that
number of times. For example, if the user enters 3, the loop will run three
times. If the user enters 7, the loop will run seven times.
- The contents of the loop can be very simple: For example: cout << "hello,
world!\n"
Enrichment #1
Project name: yournameEC4
- cpp file name: yournameEC4
- Let the user input an integer between 1 and 10. This is how many times your
loop will run
- Inside the loop, calculate and display:
- the integer itself
- the integer * 2
- the integer squared (integer * integer)
- the integer "flipped" (1 / integer)
Enrichment #2
Project Name: yournameEC4b
- A nested loop is a loop within a loop
- Create an equilaterial triangle (Ask Mrs. Sanchez for an example if you
need one)
- Let the user pick the symbol for drawing the triangle, and how many lines
are in the triangle
- You need to use nested for loops to solve this problem
Enrichment #3
Write a program that prompts the user to input the elapsed time for an event
in seconds. The program then outputs the elapsed time in hours, minutes, and
seconds. For example, if the elapsed time is 9630 seconds, then t he output
is 2:40:30.
Enrichment #4
see p. 93 in textbook, problem 14.