This lab has two goals: To introduce the lab environment to those of you who haven't taken CSCI 235 and to give all of you some initial practice with C. The first section below gives some background on how we do labs in this course. It's mainly written for those who didn't take CSCI 235 here, but the rest of you should also read it for review.
In CSCI 245 labs (and CSCI 235 labs, too), we use a protocol called pair programming. As its name suggests, it means two people working together at one computer, programming as a two-person team. This approach is common in industrial settings, especially software groups that use modern or "agile" methodologies. But our reason for using pair programming is its usefulness as a learning experience.
By programming in pairs, you learn from each other. Your partner will help clear up simple misunderstandings you have about the recent concepts or the task at hand. You will catch each other's simple mistakes. By discussing the problem at hand and its solution, you'll notice and remember more things than if working alone.
There are two roles in pair programming: The driver and the navigator. The driver controls the keyboard and mouse and does the actual programming. The navigator talks through the current problem or task with the driver, catches the driver's simple mistakes, thinks about how to test the driver's code for correctness, and glances ahead to the next task.
The students in a pair should switch roles every ten or fifteen minutes, or between each task. It's usually better to position yourselves so all you need to do to switch roles is slide the keyboard and mouse over (as opposed to getting up and switching seats).
As tempting as it is, the navigator should not log in to the next computer over. It seems innocent enough to have the other computer logged in so that the lab instructions can be on a separate screen, but having a second computer logged in means that the navigator's eyes are not on the code being written, and the driver will psychologically feel more ownership over the computer and the code being written. In pair programming, all code needs to be considered common property of the pair, and so two eyes on the same screen.
Students are also expected to switch partners each lab session. Work with as many other classmates as possible over the course of the semester.
To give the pair neutral territory to work in, the lab machines will be logged into a "class account" (named csci245a, csci245b, etc) when you arrive to lab on most lab periods (there will be a few labs during the course of the semester when you will need to log in as yourself). This also makes for convenient grading: You won't need to turn anything in---the TA will simply log into each class account and grade the work saved under that account. (So, don't forget to put your names somewhere in the files you work on.)
In this lab you will be given two (hopefully) easy tasks that will review programming in general but more importantly give you a first try at C. The tasks are
i
be the boundary position between the sorted
and unsorted sections; the array from 0 inclusive to i
exclusive is sorted, and from i
inclusive to n
exclusive is unsorted.
i
i
(moving the boundary, that is,
making the sorted section grow and unsorted section shrink)
substring()
method,
but the protocol for the function you will write is
int substring(char source[], char destination[], int start, int stop);
Note that this function takes (references to) two arrays---the first
is the array we are copying from, the second is the array we are copying
the characters to.
You don't need to know their sizes; all you care about is where the string
ends (you have to assume that the arrays are big enough to hold the
respective strings).
The function also takes a starting index (inclusive) and
stopping index (exclusive).
It copies the subsequence source[start, stop]
to destination[0, stop-start]
and adds an end-of-string marker to position
stop-start
.