0
0
C++programming~10 mins

Defining structures in C++ - Interactive Code Practice

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;
    double height;
};
Drag options to blanks, or click blank then click option'
AInfo
Bperson
CData
DPerson
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different names like 'person' or 'Data'.
Forgetting to name the structure.
2fill in blank
medium

Complete the code to declare a variable of type Person named p1.

C++
Person [1];
Drag options to blanks, or click blank then click option'
Ap
Bp1
Cperson1
Dperson
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names like 'p' or 'person'.
Forgetting the semicolon after declaration.
3fill in blank
hard

Fix the error in the structure definition by completing the missing keyword.

C++
[1] Person {
    int age;
    double height;
};
Drag options to blanks, or click blank then click option'
Aenum
Bclass
Cstruct
Dunion
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'struct'.
Omitting the keyword entirely.
4fill in blank
hard

Fill both blanks to define a structure named Car with members make and year.

C++
struct [1] {
    [2] make;
    int year;
};
Drag options to blanks, or click blank then click option'
ACar
Bstring
Cint
DVehicle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' for 'make' instead of 'string'.
Naming the structure something other than 'Car'.
5fill in blank
hard

Fill all three blanks to define a structure named Book with members title, author, and pages.

C++
struct [1] {
    [2] title;
    [3] author;
    int pages;
};
Drag options to blanks, or click blank then click option'
ABook
Bstring
DPage
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the structure.
Using wrong types for 'title' or 'author'.