Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase or different names like 'person' or 'Data'.
Forgetting to name the structure.
✗ Incorrect
The structure name should be Person to match the task requirement.
2fill in blank
mediumComplete the code to declare a variable of type Person named p1.
C++
Person [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names like 'p' or 'person'.
Forgetting the semicolon after declaration.
✗ Incorrect
The variable should be named p1 as requested.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'class' instead of 'struct'.
Omitting the keyword entirely.
✗ Incorrect
The keyword struct is needed to define a structure in C++.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'int' for 'make' instead of 'string'.
Naming the structure something other than 'Car'.
✗ Incorrect
The structure name is Car and the type of 'make' is string.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for the structure.
Using wrong types for 'title' or 'author'.
✗ Incorrect
The structure is named Book. Both 'title' and 'author' are text, so their type is string.