Lab 1 - Chapter 2
Lab 1 - Chapter 2
Purpose: To familiarize yourself with variables and arithmetic and the process of completing and
submitting a lab assignment.
Directions: Convert the following problems below to c++ equivalent code. The first one will be done for
you by the instructor (and is available in eCampus as an example). Each problem should be done within
the same file and all within the same main function. After each step is performed the user should be
shown the updated value that was changed (in other words, display the newly updated value after every
numbered step see problem 0 as an example). Turn in the finished c++ (.cpp) file for problem 1-8 as well
as your submission page. Remember to reset or use unique variables for each problem (you cannot
declare a variable by the same name twice). In each problem the user will enter a number(s) on the first
step only – do not hard code values for the input to any of the problems. If you have questions, ask your
instructor: by email or during live sessions I will be glad to help you.
Cheating: This is an individual assignment. You may use materials from your coursebook, notes, or video
lectures but not from others and not from websites like coursehero.com or chegg.com. These and
others like it are websites where students can post assignments and have others solve them for you.
However, if you are copying the solution from there then other students are doing it as well making it
look as though you cheated off the other student (plus it is usually obvious the difference between a
professional from one of sites doing the lab versus a student). If you resort to downloading your code or
otherwise copying your program from someone else, you will receive a zero on the assignment. Instead,
ask me. I will be happy to help with any of your problems on this or any of the other assignments. Send
me an email, [email protected], include your code and your question and I will be happy to help you
fix or work through any of your problems.
Problem 0:
(This is named problem zero because it is done for you, see eCampus for the code and an example of
how to complete the rest of the problems.)
1. Take as input any number that the user enters (cin >> varname)
2. Multiply the number by 2
3. Add 10 to the number
4. Divide the number by 2
5. Subtract 5 from the number
6. The result should be the original number (if not then we did something wrong)
Problem 1:
1. Take any number the user enters
2. Add 3 to the number
3. Multiply the number by 2
4. Subtract 6 from the number
5. Divide by 2
6. The result should be the original number
Problem 2:
1. Enter a random number
2. Store the input number for later use (as another variable)
3. Multiply the number by 5
4. Add 45 to the number
5. Multiply the number by 2
6. Divide the number by 10
7. Subtract the original number from your previous answer
8. The result should be 9
Problem 3:
1. Take any 2 digit number from 10 to 82. (You do not have to check the numbers just assume the
user will enter a valid number so long as you tell them to).
2. Store an extra copy of this number for later (as you did in problem 2)
3. Add 116 to the number.
4. Remove the hundreds place from your number (by modulus operation)
5. Subtract 1 from the number.
6. Subtract this from your original number (stored in step 2).
7. What is your result?
Problem 4:
1. Select two, single digit, numbers, the first being in the range 2 to 6 and the second being in the
range 1 to 9.
2. Multiply the first number by five.
3. Add three to that number.
4. Double the number.
5. Add the second number to your previous step.
6. Subtract 6 from the new total and:
The tens place should be the first number given and the ones place should be the second.
Problem 5:
1. Take a random number from the user
2. Multiply the number by 4
3. Add 1 to the number
4. Multiply by the original number that the user input
5. Subtract the original number away
6. Take the square root of the number (you can use cmath’s sqrt function)
7. Divide the number by 2
8. The result should be the original number
Problem 6:
1. Take a whole number from the user that is larger than 1
2. Store a copy of the number for later
3. Add 2 to the number
4. Multiply the number by itself (not the stored copy, but the current value)
5. Divide the number by 4
6. Subtract away the stored value from step 2
7. Multiply the number by 4
8. Take the square root of the number (you can use cmath’s sqrt function)
9. The result should be the same for any value specified
Problem 7:
1. Get a random number from the user
2. Remember the original number
3. Add 3 to the number
4. Double the number
5. and then multiply by 5.
6. Knock off the last digit (remove the 1’s place)
7. Finally remove the original number
8. What is the result?
Problem 8:
1: Have the person write down any three digits number with decreasing digits (432 or 875).
2: Reverse the number you wrote in #1.
3: Subtract the number obtained in #2 from the number you wrote in #1 (#1 - #2)
4: Reverse the number obtained in #3
5: Add the numbers found in #3 and #4