210 likes | 316 Views
Class 0: Review and Perspective. Class info. Barry Cohen bcohen@cs.njit.edu Office hours: W 3:15-4:40 F 4:00-5:25 www.cs.njit.edu/~bcohen/601 Text: Irvine, C++ And Object-Oriented Programming Recommended: Schildt, C++ the Complete Reference. Grading. 35% homework 30% midterm 35% final.
E N D
Class info • Barry Cohen • bcohen@cs.njit.edu • Office hours: W 3:15-4:40F 4:00-5:25 • www.cs.njit.edu/~bcohen/601 • Text: Irvine, C++ And Object-Oriented Programming • Recommended: Schildt, C++ the Complete Reference cis 335 Fall 2001 Barry Cohen
Grading • 35% homework • 30% midterm • 35% final cis 335 Fall 2001 Barry Cohen
Homework • Include the following • student name • student ID • date • class and section • homework number • Homework must be handed in on or before the due date. Multiple pages must be stapled together. • You must hand in source code and program output. Programs must compile in VC++. cis 335 Fall 2001 Barry Cohen
Honesty policy • You may discuss class content and assignments with others. You may not present someone else’s work as your own. Any instance of cheating will be disciplined under NJIT rules. cis 335 Fall 2001 Barry Cohen
HW 0 • Due: Sept 13, 2002 • p 20, problems 1,2,3 • p 54, problem 1 cis 335 Fall 2001 Barry Cohen
Life Cycle of a Program • Specification. Analyze and describe the problem. • Design. Choose your data structures and algorithms. • Coding. Translate the design into the programming language of your choice. • Debugging. Squash those pesky beasties. Test and squash some more. • Maintenance. More bug fixes. Add more features. Make friendlier and more efficient. cis 335 Fall 2001 Barry Cohen
What’s a Good Solution? • Correctness. Solve the problem that’s been posed. • Robustness. Handle the unexpected. • Modularity. Make it logical and reusable. • Clarity. Think clearly. Explain your thinking. • Can be maintained and extended. cis 335 Fall 2001 Barry Cohen
How to document • Precondition. Where are you starting from. • Invariant. What stays the same as you progress. • Progress. Show you’re not going in circles. • Post condition. Where you need to end up. • Use asserts. cis 335 Fall 2001 Barry Cohen
Pseudocode • High level summary • One line for each ‘idea’ • Example 1: ‘Read the initialization files’ • Example 2: ‘Perform a topological sort’ cis 335 Fall 2001 Barry Cohen
Flowcharts • Make the logic visible. • Stop or start • Decide • Do cis 335 Fall 2001 Barry Cohen
Use Functions • A function is a unit of code. • The one-page rule. • Keep data private. • Clearly define inputs and outputs. cis 335 Fall 2001 Barry Cohen
Programming Style • Consistent indentation. Use white space. • Document. Give yourself credit. Use comments. • Descriptive names. Follow name conventions. cis 335 Fall 2001 Barry Cohen
Why Document? • Someone will read it - beginning with you. • Programs live longer than programmers. • Tells you where you need to go. cis 335 Fall 2001 Barry Cohen
Quick Review of C • Data types. int, double, char. C++: bool • Data structures. Arrays. cis 335 Fall 2001 Barry Cohen
Control Structures • if .. else • for loop • while loop • do loop • switch .. case cis 335 Fall 2001 Barry Cohen
Scope • Auto • Declared in function • Allocated on stack • Static • Declared outside function • Declared as static • Allocated permanently cis 335 Fall 2001 Barry Cohen
Pass by reference • In C++, you can pass by reference • Example: void swap(int & a, int & b) {int temp = x;x = y;y = temp; } cis 335 Fall 2001 Barry Cohen
Stream I/O Stream output: int n = 65; cout << n; Stream input: int n; cin >> n; cis 335 Fall 2001 Barry Cohen
Comments • Two kinds of comments /* This is a multiline comment. */ int n; // 1-line comment cis 335 Fall 2001 Barry Cohen
C, C++ • C++ is ‘C with classes’ • Class groups object with operations • Object is instance of a class • Example: class coin • Attributes: value, upside • Actions: flip, getValue cis 335 Fall 2001 Barry Cohen