I have no clue where to start with my code or the format for doing so...
The following Chapter 4 Lab questions ask you to predict the outcome of several code segments, then test them in a small C++ program. You are also asked to build an if/else if structure, and a switch structure that performs the same logic. As you complete these activities, build one single C++ program that contains all of the requested tests and code segments (you can just comment out the test segments that you don't need as you progress through the questions, but leave the code there for me to look at). Include your predictions as comments in your source code.
When you have finished all of the required activities attach your cpp file in this submission area for my review.
1) Compare the following two segments of c++ code. Predict what will be the output of each segment for various grade values. Then, use a small test program to confirm or correct your answer. Describe whether you were correct or not. If you were not correct, describe what you learned from this comparison.
Make sure you include your predictions, the values you tested, and the results of your tests in your response to this question.
2) Compare the following two segments of C++ code. Predict what will be the result of each segment for various grade values. Then, use a small test program to confirm or correct your answer (you can add another segment of code to your existing test program - just comment out the code you used for the 1st question). Describe whether you were correct or not. If you were not correct, describe what you learned from this comparison.
if (grade = 100) if (grade == 100)
cout << “Congratulations!” << endl; cout << “Congratulations!” << endl;
Make sure you include your predictions, the values you tested, and the results of your tests in your response to this question.
3) Compare the following two segments of C++ code. Predict what will be the result of each segment for various test values of x. Add another section of code to your test program to confirm or correct your answer. Describe whether you were correct or not. If you were not correct, describe what you learned from this comparison
if (x > 0 && x < 10) if (x > 0 || x < 10)
cout << “Item is range 1 to 9” << endl; cout << “Item is range 1 to 9” << endl;
Make sure you include your predictions, your test values, and the results of your tests in your response to this question.
4) In your C++ test program, add another segment of code that will help you decipher the day of the week codes used in the college schedule. Your program should ask the user to enter a single character representing the day of the week, either M, T, W, R, or F. Your program should accept the single character, and display the full day name as output. Accept both upper and lower case letters. Display an error if a character other than MTWRF is entered. You must use an if/else structure in your program. When this code works, use this question response to identify any difficulties or errors you made when writing this code segment. How did you correct these errors?
Once your code for question #4 works, add another segment of code to it that will print the day of the week again, this time using a switch structure. Your program should work as it did before, except that you’ll see the results twice. Again, once you've gotten this code to work, use this question to identify any errors you had when adding this section of code, and explain how you corrected them.