COS 126/128, Spring 1996. Sample Mid-term questions

COS 126/128: Sample Questions for Midterm 1

These questions are meant to further help you study for the midterm.

Question 1

Suppose you are logged into a SPARCstation in the lab and you type the following unix command.

ls

Suppose unix types back the following:

test.c primes.c

Now suppose you type:

mv test.c mytest.c

and then

ls

What does unix type back this time?

Note: Are you confused by Question 1? Look at Bob Thomas's Unix quick reference (1/2 page), and if you have more time, then at the COS111 Unix cheatsheet (4-5 pages).

Question 2

Write a program that gets an integer input from the user, converts that integer into binary, and prints that binary number.

Note that in class Prof. LaPaugh solved this problem using a program that uses recursion. But strictly speaking, you don't need recursion to solve this problem.

Question 3

In an array a that contains n integers, the subarray from location i to location j is the sequence of integers a[i], a[i+1], ... a[j], where we assume i<= j. The length of this subarray is j-i+1. The subarray is said to be increasing if a[i]< a[i+1] < ... < a[j].

Write a program that defines an array of 10000 integers, gets values for those 10000 integers from the user, and then computes the length of the longest increasing subarray among these integers.