0
0
C++programming~10 mins

Why operators are needed in C++ - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add two integers and print the result.

C++
#include <iostream>
int main() {
    int a = 5, b = 3;
    int sum = a [1] b;
    std::cout << sum << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction - instead of addition.
Using multiplication * or division / by mistake.
2fill in blank
medium

Complete the code to compare if two numbers are equal.

C++
#include <iostream>
int main() {
    int x = 10, y = 10;
    if (x [1] y) {
        std::cout << "Equal" << std::endl;
    } else {
        std::cout << "Not equal" << std::endl;
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
A==
B<
C>
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using assignment = instead of comparison ==.
Using inequality != by mistake.
3fill in blank
hard

Fix the error in the code to multiply two numbers correctly.

C++
#include <iostream>
int main() {
    int a = 4, b = 5;
    int product = a [1] b;
    std::cout << product << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using addition + or subtraction - instead of multiplication.
Using division / by mistake.
4fill in blank
hard

Fill both blanks to create a dictionary-like structure using a map and check if a key exists.

C++
#include <iostream>
#include <string>
#include <map>
int main() {
    std::map<std::string, int> scores;
    scores["Alice"] = 90;
    if (scores.[1]("Alice") [2] scores.end()) {
        std::cout << "Alice's score is " << scores["Alice"] << std::endl;
    }
    return 0;
}
Drag options to blanks, or click blank then click option'
Afind
B==
C!=
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using count method incorrectly here.
Using equality == instead of not equal !=.
5fill in blank
hard

Fill all three blanks to create a conditional expression that checks if a number is positive, negative, or zero.

C++
#include <iostream>
#include <string>
int main() {
    int num = -5;
    std::string result = (num [1] 0) ? "Positive" : ((num [2] 0) ? "Negative" : (num [3] 0 ? "Zero" : "Error"));
    std::cout << result << std::endl;
    return 0;
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up greater than and less than operators.
Using not equal != instead of equal == for zero check.