discussion3_no_answ

discussion3_no_answ - CS31: Introduction to Computer...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS31: Introduction to Computer Science I Discussion 3 April 15, 2011 TA: Paul Wais ( pwais@cs.ucla.edu ) Discussion Section 1L Information TA: Paul Wais ( pwais@cs.ucla.edu ) Office Hours: Thursdays 11:30am - 1:30pm in Boelter Hall 2432 Discusion Website: http://www.cs.ucla.edu/ pwais Notes and other resources will be posted on the Discussion Website. If you would like to meet me outside of the posted office hours, please email me. Also, if youd like for me to cover something specific during discussion section, please send me email. If there is anything I can do to improve Discussion Section, please feel free to let me know. Using The Debugger Lets use the debugger to step through one of the code examples from project 2. First, well create a project in Visual Studio and paste in the following code to a file called program.cpp : #include <iostream> using namespace std; int main() { int len; cout << "Enter a number: "; cin >> len; for (int i = 0; i < len; i++) { for (int j = i+1; j < len; j++) { cout << ; } cout << "#" << endl; } } Next, right click on the line for (int i = 0; i < len; i++) and choose Breakpoint >> Insert Breakpoint and hit the green Play button to start the program with debugging . The program will start running. Enter input (e.g. 5) and hit enter. The program will now stop at the breakpoint we created, and we can now step through the program manually, observing how the values of variables change as we go. 1 Using the debugger is probably best learned by watching somebody else do it. 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 Notes on Project 2 Solutions for Project 2 have been posted on the Course Website. There are a few key points worth noting: Use const for Constants Its good style to declare const variables for storing constants (as opposed to just leaving numbers like 0.20 in code). Furthermore, to make it very clear that a variable is a constant, we usually use the convention of writing constant variable names using all uppercase characters. For example, heres a snippet of code from the Project 2 solution: const double BRACKET_CUTOFF_1...
View Full Document

Page1 / 9

discussion3_no_answ - CS31: Introduction to Computer...

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