Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increment the variable count by 1.
C++
int count = 5; count[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the decrement operator
-- instead of increment.Using
+= without specifying the amount.✗ Incorrect
The increment operator
++ increases the value of count by 1.2fill in blank
mediumComplete the code to decrement the variable value by 1.
C++
int value = 10; value[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the increment operator
++ instead of decrement.Using
-= without specifying the amount.✗ Incorrect
The decrement operator
-- decreases the value of value by 1.3fill in blank
hardFix the error in the code to correctly increment num.
C++
int num = 7; num = num[1];
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
++ after assignment operator.Using decrement operators instead of increment.
✗ Incorrect
To increment
num by 1 using assignment, you add 1 with + 1.4fill in blank
hardFill both blanks to create a map of numbers to their squares using increment in the loop.
C++
std::map<int, int> squares; for (int i = 1; i [1] 5; i[2]) { squares[i] = i * i; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
i <= 5 causes the loop to run one extra time.Using decrement operator
-- in the loop.✗ Incorrect
The loop runs while
i is less than 5, and i++ increments i by 1 each time.5fill in blank
hardFill all three blanks to create a map of uppercase letters to their ASCII codes, incrementing the letter.
C++
std::map<char, int> ascii_map; for (char ch = 'A'; ch [1] 'Z'; ch[2]) { ascii_map[[3]] = static_cast<int>(ch); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < code < 'Z' > causes 'Z' to be excluded.
Using decrement operator
-- instead of increment.Using wrong variable as map key.
✗ Incorrect
The loop runs while
ch is less than or equal to 'Z', increments ch with ++, and uses ch as the key in the map.