discussion5_w_ans - CS31 Introduction to Computer Science I...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS31: Introduction to Computer Science I Discussion 5 April 29, 2011 TA: Paul Wais ( [email protected] ) Hello Discussion 1J Students! Thank you for having us! Discussion Section 1L Information TA: Paul Wais ( [email protected] ) Office Hours: Thursdays 11:30am - 1:30pm in Boelter Hall 2432 Discusion Website: http://www.cs.ucla.edu/ ˜ pwais 1 Announcements 1.1 Midterm The midterm is next Wednesday, May 4th, during class (10am-11:50am). It will be closed book, closed notes, and you may not use electronic devices. You may use two 8.5in x 11in sheets of paper (both sides) with whatever notes you want. 1.2 Project 4 is up! Due next Tuesday, May 3rd, ( before the Midterm) Project 4 consists of writing 11 utility functions that process arrays. We will go over several examples of arrays today that should help. 1.3 The Debugger is Awesome!! Really! Recall these very useful references on getting started with the debugger: For Visual Studio, check out this video (try to fast forward until 1:30 or so): http://www.youtube.com/user/UCLAChuck#p/c/2775EB517DDA7A95/0/z5gBIizwsY0 The debugger in Xcode is very similar to the one in Visual Studio. Check out this tutorial: http://bit.ly/iecq83 2 Arrays Arrays are extremely useful. Arrays allow us to create and manipulate sequences of variables instead of just single variables. For instance, in Project 3, the “grid” was actually an array (of arrays). All arrays have a type and a fixed length . (Later, we will discuss how to dynamically resize arrays during program execution). Each element in an array has the same type . For example, the array int x[5]; declares a array x that can hold 5 int values. Let’s see an example: 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
void printArray(int arr[], int length); void printArray(char arr[], int length); int main() { int x[10]; // An empty array that can hold 10 integers int threeFives[3] = {5, 5, 5}; // Special initialization syntax int threeFours[] = {4, 4, 4}; // Also valid; size of the array can be inferred const int ARRAY_SIZE = 2; int twoSixes[ARRAY_SIZE]; // Create an array of size defined twoSixes[0] = 6; // by a constant and set each twoSixes[1] = 5; // element to 4. twoSixes[1]++; // You can treat each array element like a variable int userArraySize; cout << "Please enter an array size: "; // Some compilers will throw an error cin >> userArraySize; // if array sizes are not known at compile time. char arr[userArraySize];
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 9

discussion5_w_ans - CS31 Introduction to Computer Science I...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online