Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://azeembooks.com/wp-content/uploads/2019/06/Starting-Out-With-Cpp-From-Control-Structures-Through-Objects-8th-Edition.pdf
- 9.23.19
- LO1: Relational Operators
- --------------------------------------------------------------
- >, <, >=, <=, ==, !=
- x > y relational expression, boolean expression, is x greater than y? true or false?
- true is not always 1, and false is not always 0
- // This program displays the values of true and false states.
- #include <iostream>
- using namespace std;
- int main()
- {
- bool trueValue, falseValue;
- int x = 5, y = 10;
- trueValue = x < y;
- falseValue = y == x;
- cout << "True is " << trueValue << endl;
- cout << "False is " << falseValue << endl;
- return 0;
- }
- OUTPUT
- True is 1
- False is 0
- z = x < y z is assigned 0, x is not less than y
- LO2: The if Statement
- --------------------------------------------------------------
- #include <iostream>
- int main() {
- int temp = 0;
- std::cout << "Enter temperature: ";
- std::cin >> temp;
- if (temp <= 60)
- std::cout << "Grab Coat!\n"; //if true display this, if false keep running program
- std::cout << "Eat breakfast\n";
- std::cout << "Grab keys\n";
- std::cout << "Leave House\n";
- return 0;
- }
- Is it cold outside?
- Yes
- Wear a coat. Continue running program -->
- No
- Continue running programm -->
- LO3: Expanding the if Statement
- --------------------------------------------------------------
- #include <iostream>
- int main() {
- int temp = 0;
- std::cout << "Enter temperature: ";
- std::cin >> temp;
- if (temp <= 60) {
- std::cout << "Grab Coat!\n"; //if true display this, if false keep running program
- std::cout << "Not the Dolphins coat!\n"; //also display this
- } //don't forget the braces!!!
- std::cout << "Eat breakfast\n";
- std::cout << "Grab keys\n";
- std::cout << "Leave House\n";
- return 0;
- }
- LO4: The if/else Statement
- --------------------------------------------------------------
- #include <iostream>
- int main() {
- int temp = 0;
- std::cout << "Enter temperature: ";
- std::cin >> temp;
- if (temp <= 60) {
- std::cout << "Grab Coat!\n"; //if true display this, if false keep running program
- std::cout << "Not the Dolphins coat!\n"; //also display this
- } else {
- std::cout << "Put on a regular shirt"; //if above is false, then display this
- }
- std::cout << "Eat breakfast\n";
- std::cout << "Grab keys\n";
- std::cout << "Leave House\n";
- return 0;
- }
- Is it cold outside?
- Yes
- Grab a coat, not the dolphins coat. Continue running program -->
- No
- Put on a regular shirt. Continue running programm -->
- LO5: Nested if Statements
- --------------------------------------------------------------
- #include <iostream>
- int main() {
- int temp = 0;
- std::cout << "Enter temperature: ";
- std::cin >> temp;
- if (temp <= 60) {
- std::cout << "Grab Coat!\n"; //if true display this, if false keep running program
- std::cout << "Not the Dolphins coat!\n"; //also display this
- } else {
- if (temp > 80) {
- std::cout << "Put on a short-sleeved shirt\n"; //if above is false, then display this
- } else {
- std::cout << "Put on a regular shirt\n"; //if above is false, then display this
- }
- }
- std::cout << "Eat breakfast\n";
- std::cout << "Grab keys\n";
- std::cout << "Leave House\n";
- return 0;
- }
- Is it cold outside?
- Yes
- Grab a coat, not the dolphins coat. Continue running program -->
- Is it hot?
- Yes
- Put on a short-sleeved shirt. Continue running programm -->
- No
- Put on a regular shirt. Continue running programm -->
- LO6: The if/else if Statement
- --------------------------------------------------------------
- #include <iostream>
- int main() {
- int temp = 0;
- std::cout << "Enter temperature: ";
- std::cin >> temp;
- if (temp <= 60) {
- std::cout << "Grab Coat!\n"; //if true display this, if false keep running program
- std::cout << "Not the Dolphins coat!\n"; //also display this
- } else if (temp > 80) {
- std::cout << "Put on a short-sleeved shirt\n"; //if above is false, then display this
- } else {
- std::cout << "Put on a regular shirt\n"; //if above is false, then display this
- }
- std::cout << "Eat breakfast\n";
- std::cout << "Grab keys\n";
- std::cout << "Leave House\n";
- return 0;
- }
- LO7: Flags
- --------------------------------------------------------------
- LO8: Logical Operators
- --------------------------------------------------------------
- LO9: Checking Numeric Ranges with Logical Operators
- --------------------------------------------------------------
- LO10: Menus
- --------------------------------------------------------------
- LO11: Focus on Software Engineering: Validating User Input
- --------------------------------------------------------------
- LO12: Comparing Characters and Strings
- --------------------------------------------------------------
- LO13: The Conditional Operator
- --------------------------------------------------------------
- LO14: The switch Statement
- --------------------------------------------------------------
- LO15: More About Blocks and Variable Scope
- --------------------------------------------------------------
- Checkpoint [LO1]
- --------------------------------------------------------------
- 1.
- A) T
- B) T
- C) F
- D) T
- E) T
- F) F
- G) T
- 2.
- A) F
- B) F
- C) T
- 3.
- A) T
- B) F
- C) F
- 4.
- OUTPUT:
- 0
- 0
- 1
- 0
- Checkpoint [LO2]
- --------------------------------------------------------------
- 5.
- if (x == 20)
- y = 0;
- 6.
- if (price > 500)
- discountRate = 0.2;
- 7.
- if (hours > 40)
- payrate *= 1.5;
- 8. TRUE
- 9. FALSE
- if (calls = 20) // assigns value 20 to calls!!!
- rate *=0.5;
- Checkpoint [LO3]
- --------------------------------------------------------------
- 10.
- if (sales > 50000) {
- commissionRate = 0.25;
- bonus = 2.50;
- }
- 11.
- It's missing the braces {}
- Checkpoint [LO4]
- --------------------------------------------------------------
- 12.
- FALSE: cout's should be in the same order in both statements for them to display the same output ase they both are the same, x > y is the same as saying y <= x
- 13.
- if (y == 100) {
- x = 1;
- } else {
- x = 0;
- 14.
- if (sales >= 50000.00) {
- comissionRate = 0.20;
- } else {
- comissionRate = 0.10;
- }
- Checkpoint [LO5]
- --------------------------------------------------------------
- 15. OUTPUT:
- 0: Zero
- 15: Zero
- Ten
- 30: Zero
- Ten
- Twenty
- -1: [nothing, program doesn't finish running, because there's no else statement]
- Checkpoint [LO6]
- --------------------------------------------------------------
- 16.
- if funny is not 1, then funny = 0, serious = 0 [TRUE] [funny = 7]
- else if funny is 2, then funny = 10, serious = 10 [FALSE]
- else funny = 1, serous = 1; [NOT AVAILABLE]
- OUTPUT:
- 0 0
- 17.
- 1 1
- 3 2
- 4 2
- 5 3
- 10 3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement