Solutions to review questions
-1. TopHalf
function C = topHalf(A)
% Refer to Lecture 21.
% Suppose A is a length-50 structure array with two fields
% Assume A(k).name is a string that names a state and A(k).pop
% is an integer whose value is the states po
CS1112 Spring 2016 Project 1
due Thursday 2/11 at 11pm
You must work either on your own or with one partner. If you work with a partner you must first register
as a group in CMS and then submit your work as a group. Adhere to the Code of Academic Integrit
CS1112 Discussion Exercise 3
1
Multiples of k
The following program reads an integer k and outputs all the multiples of k up to 1000. Fill in
the blank.
k = input(Please enter a positive integer smaller than 1000: );
for j = _
fprintf(0 , j);
end
fprintf(
CS 1112 Spring 2017 Project 3 Part A
due Thursday 3/9 at 11pm
You must work either on your own or with one partner. If you work with a partner you must first register as a group
in CMS and then submit your work as a group. Adhere to the Code of Academic I
CS1112 Discussion (Lab) Exercise 4
1
Fibonacci numbers
You should read Insight 3.2 before doing the following exercise. Download the script Fibonacci:
% Fibonacci
clc
f_old = 0;
f_cur = 1;
n = 1;
% f_cur is the nth Fibonacci number
while (n<=10)
fprintf(%
CS1112 Discussion (Lab) 1
When you have completed this exercise, show this sheet and any associated programs to your lab instructor,
who will record that you have completed the exercise. If you do not finish this exercise during the lab, show the
instruct
CS1112 Spring 2017 Project 2
due Monday 2/27 at 11pm
You must work either on your own or with one partner. If you work with a partner you must first register as a group
in CMS and then submit your work as a group. Adhere to the Code of Academic Integrity.
CS1112 Spring 2017 Project 3 Part B
due Thursday 3/9 at 11pm
You must work either on your own or with one partner. If you work with a partner you must first register as a group
in CMS and then submit your work as a group. Adhere to the Code of Academic In
CS1112 Lab Exercise 6
1
Different ways to create vectors
Type the following expressions in the Matlab Command Window to see what kind of vectors they create. Write
the resulting vectors (and answer the questions) on the blanks.
2
a= zeros(1,4)
%_
b= zeros
Previous Lecture:
Todays Lecture:
Executing a user-defined function
Function scope
Subfunction
1-d arrayvector
Probability and random numbers
Simulation using random numbers, vectors
Announcements:
Project 3 Part A posted, due Thurs 10/10 at 11pm
Discuss
Review questions
-1. TopHalf
function C = topHalf(A)
% Refer to Lecture 21.
% Suppose A is a length-50 structure array with two fields
% Assume A(k).name is a string that names a state and A(k).pop
% is an integer whose value is the states population.
% A
CS1112 Fall 2013
Prelim 2
Nov 14 7:309:00pm
Q1: (15)
Name:
(Legibly print last name, rst name, middle name)
Q2: (25)
NetID:
Q3: (15)
Statement of integrity:
I did not, and will not, violate the rules of academic integrity
on this exam.
Q4: (20)
(Signature
Fall 2013 Prelim 2 Solutions
Question 1: (15 points)
(a) What is the output from executing the following fragment? Write the word error instead of the
output if executing the fragment would cause a run-time error.
M = [ 2 6
8 10 ; .
9 4 12
1 ; .
3 5
7 11
Fall 2013 Prelim 1 Solutions
Question 1: (15 points)
(a) What is the output from executing the following script? If the program doesnt terminate or if
there will be an error during execution, write the word error instead of the output.
v = [3 1 2];
w = [4
CS1112/CS1142 Fall 2013
Prelim 1
Oct 17 7:309:00pm
Q1: (15)
Name:
(Legibly print last name, rst name, middle name)
Q2: (15)
NetID:
Q3: (20)
Statement of integrity:
I did not, and will not, violate the rules of academic integrity
on this exam.
Q4: (20)
(Si
Previous Lecture:
Todays Lecture:
Nesting if-statements
Logical operators short-circuit
Top-down design
Iteration using for
Announcements:
Register your clicker with Cornell CIT (link on website)
Project 1 due tonight at 11pm
Question
A stick of unit len
Previous Lecture:
Today s
Todays Lecture:
Iteration using while
Nested loops
Developing algorithms
Announcements:
Read Insight 3.2 before discussion, in the lab next week
g
,
Project 2 Parts A & B due Thurs 9/26 at 11pm
Problem 1: user inputs n, r, h
W
Previous Lecture:
Iteration using for
Todays Lecture:
Details on for-loop
Iteration using while
Review loop & conditionals using graphics
Announcements:
Discussion this week is in the classroom as listed on the roster
Register your iClicker! See regi
Previous Lecture (and Lab):
Todays Lecture:
Intro to the course, Computational senses
The Matlab Command Window
Anatomy of a program
Variables, assignment, mathematical operations
Functions for input & output
Announcements
Discussion this week computer l
Previous lecture
User-defined functions
Todays lecture
User defined
User-defined functions
Function header
Input parameters and return variables
local memory space
Subfunction
1-dimensional arrays and p
y
plot
Announcement
Project 2 due tonight at 11pm
L
Previous Lecture:
Todays Lecture:
1-d arrayvector
Probability and random numbers
More examples on vectors and simulation
Color computation
Linear interpolation
Announcement:
Project 3 due on Thurs 10/10
Prelim 1 on Thurs 10/17 at 7:30pm
% Simulate the ro