0
0
C++programming~10 mins

Why structures 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 define a structure named Person.

C++
struct [1] {
    int age;
    float height;
};
Drag options to blanks, or click blank then click option'
AInfo
Bperson
CData
DPerson
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or unrelated names for the structure.
2fill in blank
medium

Complete the code to create a variable of type Person.

C++
Person [1];
Drag options to blanks, or click blank then click option'
APerson
Bstruct
Cperson1
Ddata
Attempts:
3 left
💡 Hint
Common Mistakes
Using the structure name as the variable name.
3fill in blank
hard

Fix the error in accessing the age member of person1.

C++
person1.[1] = 25;
Drag options to blanks, or click blank then click option'
Aages
Bage
CAGE
DAge
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect capitalization for member names.
4fill in blank
hard

Fill 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'
Aperson2
Bperson1
C30
D25
Attempts:
3 left
💡 Hint
Common Mistakes
Using existing variable names or wrong age values.
5fill in blank
hard

Fill 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'
APerson
C28
Dperson
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatched names or wrong initialization values.