SIT102 – Introduction to ProgrammingMatlab

Java Python 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 SIT102 – Introduction to ProgrammingMatlab 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         

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值