程序代写代做 flex NYU Tandon School of Engineering Department of Computer Science and Engineering CS-UY 1133 Exam II, 2019.11.19

NYU Tandon School of Engineering Department of Computer Science and Engineering CS-UY 1133 Exam II, 2019.11.19
• Take the exam in the classroom assigned to you.
• Do not consult anyone in any way or means, or any materials in any form during the
exam.
• Use of any electronic devices such as computers and calculators are prohibited.
• Need your NYU ID card to take the exam and to return your exam paper.
• Put the answers to be graded in your bluebook.
• You can use any page of your bluebooks as scratch paper, but do not tear off any. Cross out anything that you do not want to be graded.
• Circle your last name on the cover sheet of the blue-book, return it, and sign your name before leaving the exam room.
• You should keep the question sheets with you. Do not return those with the bluebooks.
• No need to put comments in your programs.
• Unless the problem specifies a particular output format, there is no need to display any results.
• Make sure you do the problems using only materials covered in the course thus far, otherwise no credits will be given.
• Write programs that are reasonably flexible. Do not deal only with a given example, and avoid hardwiring as much as possible.
The following list provides you the names of the built-in MATLAB functions that you may use on this exam. You are not allowed to use any other functions! If you believe that you need to use any other functions not on this list, you need to ask me during the exam.
cos tan sind
acosd atand sinh
size sqrt abs
sum mean max min find all any nnz sort
For this exam you can also use the following programming constructs if else elseif for while end
log log10
asin acos
double logical
fix round
mod rem
rand randn randi
exp sin
atan asind linspace length ceil floor input transpose
cosd tand cosh tanh num2str disp
1

Problem 1 [50 pts]
Given a vector of numbers, replace all the positive numbers by their square roots. Re- place all the zeros by the total number of zeros in the entire vector. And replace all the negative elements by the negative of their indices (their positions within the vector). For example, given a vector:
Vec = [25 -24 -16 16 0 36 -22 -23 9 0 -21]
will result in
Vec = [5 -2 -3 4 2 6 -7 -8 3 2 -11]
As another example, given a vector:
Vec = [0 25 -31 -1 1 0 4 -9 0]
will result in
Vec = [3 5 -3 -4 1 3 2 -8 3]
No vectorized operation is allowed in this problem. Only scalar operations are allowed.
The above vector serves only as an example. Assume that such a vector is given. Do not generate it at all. Your program must be sufficiently general to work for any given vector of arbitrary length.
No need to write a statement to display the resulting vector.
2

Problem 2 [50 pts]
Write a program that randomly generates two integers between 1 and 99 inclusively, and have the user enter the product of those two integers. The user must be made to repeat the calculation until finally getting the correct answer or until he or she gives up by entering a 0 to signal the desire to quit.
Unless the user gave up, report the total number of attempts he or she took to come up with the correct answer.
Your program must produce output displays accordingly in the format shown by the following examples.
One sample output:
Enter the product of 80 and 15 : 137
Enter the product of 80 and 15 : 290
Enter the product of 80 and 15 : 1200
It took you 3 attempts to get it right.
Another sample output:
Enter the product of 42 and 91 : 93874
Enter the product of 42 and 91 : 12
Enter the product of 42 and 91 : 9023
Enter the product of 42 and 91 : 783
Enter the product of 42 and 91 : 0
Fail to calculate it correctly. Need to take the test again!
3