Complete the code to print a message about C++ usage.
#include <iostream> int main() { std::cout << "C++ is widely used because it is [1]." << std::endl; return 0; }
C++ is known for its speed and efficiency, which makes it widely used.
Complete the code to declare a variable showing C++'s feature.
#include <iostream> int main() { bool isObjectOriented = [1]; std::cout << "C++ supports object-oriented programming: " << isObjectOriented << std::endl; return 0; }
C++ supports object-oriented programming, so the boolean variable should be true.
Fix the error in the code to correctly define a function that returns C++'s main advantage.
#include <string> std::string mainAdvantage() { return [1]; }
The function returns a string, so the return value must be a string literal in quotes.
Fill both blanks to create a map of C++ features and their descriptions.
#include <iostream> #include <map> #include <string> int main() { std::map<std::string, std::string> features = { {"[1]", "Supports low-level memory manipulation"}, {"[2]", "Supports object-oriented programming"} }; for (const auto& [key, value] : features) { std::cout << key << ": " << value << std::endl; } return 0; }
Pointers allow low-level memory manipulation, and inheritance is a key object-oriented feature in C++.
Fill all three blanks to create a function that returns a feature description based on input.
#include <string> std::string featureDescription(const std::string& feature) { if (feature == "[1]") { return "Allows code reuse and polymorphism."; } else if (feature == "[2]") { return "Enables generic programming."; } else if (feature == "[3]") { return "Provides control over system resources."; } else { return "Unknown feature."; } }
Inheritance allows polymorphism, templates enable generic programming, and pointers provide control over system resources.