Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a structure named Person.
C++
struct [1] {
int age;
float height;
}; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or unrelated names for the structure.
✗ Incorrect
The structure name should be Person to match the definition.
2fill in blank
mediumComplete the code to create a variable of type Person.
C++
Person [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the structure name as the variable name.
✗ Incorrect
We create a variable named person1 of type Person.
3fill in blank
hardFix the error in accessing the age member of person1.
C++
person1.[1] = 25;
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization for member names.
✗ Incorrect
Member names are case-sensitive. The correct member is age.
4fill in blank
hardFill both blanks to define and initialize a Person variable.
C++
Person [1] = { [2], 5.9f };
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using existing variable names or wrong age values.
✗ Incorrect
We define person2 with age 30 and height 5.9.
5fill in blank
hardFill all three blanks to create a structure and print a member.
C++
#include <iostream> struct [1] { int age; float height; }; int main() { [2] p = { [3], 6.1f }; std::cout << p.age << std::endl; return 0; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatched names or wrong initialization values.
✗ Incorrect
The structure is named Person, variable person, age initialized to 28.