$34.99
Submission Instructions:
1. Create a folder named Lab2 LastName FirstInitial (e.g. Lab2 Neal T).
2. In your folder, place a PDF file containing your answers to questions with a ♦.
4. Ensure that all programs have block comments at the very beginning (starting at the first line) in the file containing main() with your name and the program’s description. The block comment’s format should be identical to what’s provided in Figure 2-1.
5. Use single-line comments to describe your code’s functionality as needed.
6. Do not submit anything for questions with a ♣.
7. Zip the folder and submit it via Canvas.
♦ = 5 points each, ♠ = 15 points each
1. ♣ Read Chapter 3: How to make decisions.
2. ♦ Does the following line change or clarify the order of precedence for NOT, AND, and OR operators?
(hungry=="yes" || animal=="predator") && dinner_time==1
3. ♦ What is the output of the following switch statement:
cout << "Humpday" << endl; break;
default: cout << "Nothing important" << endl; break;
}
4. ♣ Read Chapter 4: How to code loops.
5. ♦ Within a while loop, I want to ask the user to input numbers between 1 and 10. If the input is not within this range or of an integer type, I will print out the statement:
Please enter a number between 1 and 10:
and allow the user to try again until a sentinel value of ‘0’ is provided. This value will stop the loop. If invalid input is provided, should I use a break or continue statement, and why?
6. ♠ Create a new folder named lab2 q6. Your folder should contain a program that reads in an arbitrary number of characters from the user. You should store the characters as a single string. At the sentinel value of 0 (zero), print the complete string, capitalizing only vowels (a, e, i, o, u) and making every other character lowercase. You must use a do-while loop (to accept each character) and a switch statement (to process each character). Your program’s output should be formatted as follows:
Enter a character: a
Enter a character: l
Enter a character: v
Enter a character: i
Enter a character: n
Enter a character: 0 Your string: AlvIn
7. ♦ Evaluate the following for the value of output:
late_fee = 85.70;
output = (late_fee >= 50) ? "Pay on time!" : "Pay late!";
Evaluate the following for the value of output:
statement = "justPlayingAround";
output = (statement.length() < 5) ? statement.length() : 100;
8. ♣ Read Chapter 6: How to work with data types, strings, and vectors.
9. ♦ What is the value of output?
string a = "sarah"; string b = "Sarah"; bool output = (a == b);
10. ♦ Open and read dynamically typed languages.pdf (available on Canvas). Answer the following questions:
• What are dynamically and statically typed languages?
• Is C++ a dynamically or statically typed language?
• Will the following lines written in C++ cause a runtime error?
int number = 0; number = "new_number";
• True or False? In the fragment below written in Python, variable data has no type since Python is not a statically typed language. Thus, the following lines are error free.
data = 10; data = "new_data";
• If I want to create a heterogeneous list, which is most convenient - a statically or dynamically typed language - and why?