联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> CS作业CS作业

日期:2024-09-19 12:57

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.

 


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp