代写SIT102 – Introduction to Programming代写留学生Matlab语言

- 首页 >> CS

SIT102 – Introduction to Programming

7.1P Arrays and Structs Submission

THEORY ANSWERS

Question 1: Briefly explain what each part of the following statement is doing. Note that the colors are used to highlight the different parts you must explain – they do not mean anything else:

kingdom.knights.push_back ( new_knight );

Statement: kingdom.knights.push_back(new_knight);

1. kingdom: Refers to an object or instance of a struct (or class) that contains a list of knights.

2. knights: A member of the kingdom struct, likely a vector or list that stores multiple knight objects.

3. push_back: A function used to add a new element (new_knight) to the end of the knights list.

4. new_knight: The object being added to the knights list.

Question 2: What code can we write to find out the current number of knights in the kingdom? Write the code below:

int numberOfKnights = kingdom.knights.size();

This code uses the .size() function to get the number of elements (knights) currently stored in the knights list of the kingdom.

 


站长地图