CS111 Introduction to Computer Science Midterm 2 Fall 2023Java

CS111 2023秋季Java期中考试内容

Java Python CS111 Introduction to Computer Science

Midterm 2

Fall 2023

Section 1: Weeks 1-4 (35 points)

1) (8 points) For each of the following scenarios, identify the best data type. Choose from any primitive data type, as well as String. Give a 1-line justification of why it is the best data type for the variable.

a) (2 points) Price of a product

Data Type:

Explanation:

b) (2 points) Rutgers NetID (the ID comprised of letters and numbers)

Data Type:

Explanation:

c) (2 points) Age

Data Type:

Explanation:

d) (2 points) Letter Grade

Data Type:

Explanation:

2) (15 points) Consider the following code snippet.

a) (10 points - 2 points each row) What are the values of m and n at the end of each iteration? Fill in the table below.

Iteration

m

n

0

0

54321

1

2

3

4

5

b) (5 points) What is the above code snippet doing in terms of n? Explain in 1-2 sentences.

3) (12 points - 3 points each) Consider the following code snippet. What is the output of this code snippet with the following inputs?

a)  x=0, y=0                    

b)  x=2, y=3                    

c)  x=3, y=2                    

d)  x=2, y=0  dai 写CS111 Introduction to Computer Science Midterm 2 Fall 2023Java ;                  

Section 2: Arrays (35 points)

1) (15 points) Write a snippet of code that creates an integer array of size 10 and populates each entry using the formula 2+3*index. For example, index 5 will contain the value 2 + 3 * 5=17. Print out each array entry on a new line. You DO NOT need to include the headers (public class/public static void main).

2) (10 points) Consider the following code snippet and line numbers.

a)   (2 points) What is line 1 doing?

b) (2 points) What does arr[r].length represent inline 5? What is the numerical value?

c) (2 points) What is happening inline 6?

d) (4 points) In 1-2 sentences, describe what the code snippet is printing? What is the actual output?

3) (10 points) Write a code snippet that finds and prints the minimum value in a 2-dimensional array of integers. Assume the array name is arr. You DO NOT need to include the headers (public class/public static void main).

Section 3: Input/Output

1. (5 points) Write a program that reads two inputs from the command line as integer values and displays the smallest of the two inputs. Assume the inputs are integers.

2) (10 points) What is the output of the program below when executed with the command java M2 < input.txt?

Output:

3) (5 points) Write the command to execute the program in question 2 and save the output in a file named output.txt.

Section 4: Functions (30 points)

1) (5 points) Consider the following function below.

a) (1 point) What is the name of the function?

b) (1 point) What are the inputs for this function?

c) (1 point) What is the return type?

d) (2 points) What would we write in the main method to call this function with the base as 2 and the exponent as 4?

2) (15 points) averageOf3

a) (10 points) Write a function averageOf3 that takes in 3 separate integers as parameters, and returns the average of the three numbers. Include the whole method signature

(modifiers, return type, method name, inputs) and the body of the method.

b) (5 points) Write 1-2 lines of code that will call your function with the inputs 2, 3, and 5, and print out the result.

3) (10 points) Write a function calculateWage that takes in a number of hours worked and an hourly rate as parameters. The function returns the total wage. For example, if the 5 hours are worked and the hourly rate is 13.50, the function will return 67.50.

Section 5: Recursion

1) (15 points) Consider the following recursive function foo() as well as the line numbers.

a) (2 points) Which line(s) handles the base case?

b) (3 points) What is the outcome if foo(0,0) is called?

c) (4 points) What are the values returned for foo(4,2) and foo(5,3) respectively?

d) (6 points) Briefly (1-2 lines) explain the purpose of the function foo().

2) (15 points) Answer the following questions given the recursive function mysteryFunc.

a) (5 points) What is printed when the following code snippet is executed?

b) (5 points) What is printed when the following code snippet is executed?

c) (5 points) Describe, in a sentence, what mysteryFunc computes         

【事件触发一致性】研究多智能体网络如何通过分布式事件驱动控制实现有限时间内的共识(Matlab代码实现)内容概要:本文围绕多智能体网络中的事件触发一致性问题,研究如何通过分布式事件驱动控制实现有限时间内的共识,并提供了相应的Matlab代码实现方案。文中探讨了事件触发机制在降低通信负担、提升系统效率方面的优势,重点分析了多智能体系统在有限时间收敛的一致性控制策略,涉及系统模型构建、触发条件设计、稳定性与收敛性分析等核心技术环节。此外,文档还展示了该技术在航空航天、电力系统、机器人协同、无人机编队等多个前沿领域的潜在应用,体现了其跨学科的研究价值和工程实用性。; 适合人群:具备一定控制理论基础和Matlab编程能力的研究生、科研人员及从事自动化、智能系统、多智能体协同控制等相关领域的工程技术人员。; 使用场景及目标:①用于理解和实现多智能体系统在有限时间内达成一致的分布式控制方法;②为事件触发控制、分布式优化、协同控制等课题提供算法设计与仿真验证的技术参考;③支撑科研项目开发、学术论文复现及工程原型系统搭建; 阅读建议:建议结合文中提供的Matlab代码进行实践操作,重点关注事件触发条件的设计逻辑与系统收敛性证明之间的关系,同时可延伸至其他应用场景进行二次开发与性能优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值