CSS342: Introduction1 Professor: Munehiro Fukuda.

Slides:



Advertisements
Similar presentations
Modular Programming With Functions
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Object Oriented Design An object combines data and operations on that data (object is an instance of class) data: class variables operations: methods Three.
Software Engineering and Design Principles Chapter 1.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Wednesday, 12/11/02, Slide #1 CS 106 Intro to Comp. Sci. 1 Wednesday, 12/11/02  QUESTIONS??  Today: CLOSING CEREMONIES!  HW #5 – Back Monday (12/16)
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Introduction and a Review of Basic Concepts
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 8. 2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays as Arguments Two-Dimensional Arrays Common.
Review on pointers and dynamic objects. Memory Management  Static Memory Allocation  Memory is allocated at compiling time  Dynamic Memory  Memory.
Chapter 1 Principles of Programming and Software Engineering.
C++ for Engineers and Scientists Third Edition
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
1 Procedural Concept The main program coordinates calls to procedures and hands over appropriate data as parameters.
C++ fundamentals.
Distribution of Marks Internal Sessional Evaluation Assignments – 10 Quizzes – 10 Class Participation Attendence – 5 Mid – Term Test – 25 External Evaluation.
Java and C++, The Difference An introduction Unit - 00.
Modular Programming Chapter Value and Reference Parameters t Function declaration: void computesumave(float num1, float num2, float& sum, float&
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Recursion Chapter Nature of Recursion t Problems that lend themselves to a recursive solution have the following characteristics: –One or more.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
Introduction Ellen Walker CPSC 201 Data Structures Hiram College.
1 Today’s Objectives  Announcements Turn in Homework #1 Homework #2 is posted and it is due on 21-Jun  Review Quiz #1  Pointers and C-style strings.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Modular Programming Chapter Value and Reference Parameters computeSumAve (x, y, sum, mean) ACTUALFORMAL xnum1(input) ynum2(input) sumsum(output)
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
Introduction CS 3358 Data Structures. What is Computer Science? Computer Science is the study of algorithms, including their  Formal and mathematical.
Pointers OVERVIEW.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
CS Data Structures I Chapter 2 Principles of Programming & Software Engineering.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
Chapter 7 Pointers: Java does not have pointers. Used for dynamic memory allocation.
Chapter 13 – C++ String Class. String objects u Do not need to specify size of string object –C++ keeps track of size of text –C++ expands memory region.
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE C++ INTERLUDE 1.3. C++ BOOK.
1 CSCD 326 Data Structures I Software Design. 2 The Software Life Cycle 1. Specification 2. Design 3. Risk Analysis 4. Verification 5. Coding 6. Testing.
Data Structures Using C++ 2E
1 Cannon_Chapter9 Strings and the string Class. 2 Overview  Standards for Strings  String Declarations and Assignment  I/O with string Variables 
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: One-Dimensional Arrays Array Initialization Arrays.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Engineering and Object-Oriented Design Topics: Solutions Modules Key Programming Issues Development Methods Object-Oriented Principles.
CSS 332 PROGRAMMING ISSUES WITH OBJECT-ORIENTED LANGUAGES LECTURE
CSS 342 DATA STRUCTURES, ALGORITHMS, AND DISCRETE MATHEMATICS I LECTURE CARRANO , APP D, C++ BOOK.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
Chapter 1 Data Abstraction: The Walls CS Data Structures Mehmet H Gunes Modified from authors’ slides.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
DATA STRUCTURES (CS212D) Overview & Review Instructor Information 2  Instructor Information:  Dr. Radwa El Shawi  Room: 
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
Principles of Programming. Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition.
Object-Oriented Programming (OOP) and C++
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
14-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
Computer Programming in C++ 黃鐘揚 教授 Prof. Chung-Yang (Ric) Huang Department of Electrical Engineering National Taiwan University 2007/06/26.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Principles of Programming & Software Engineering
CSS342: Objects and Classes
CSS 342 Data Structures, Algorithms, and Discrete Mathematics I
Principles of Programming and Software Engineering
About the Presentations
CS150 Introduction to Computer Science 1
Presentation transcript:

CSS342: Introduction1 Professor: Munehiro Fukuda

CSS342: Introduction2 Course Objectives You will: –Learn problem solving with object-oriented design –Analyze algorithms in formal mathematical methods –Exercise software engineering concepts You may say: –I know C++, templates, Big-O, sorting, recursion, lists, stacks, and queues. I read “for dummies” books. However: –Can you swim, ski, and play tennis with only reading “swimming, skiing, and tennis for dummies”? How: –Math/programming need exercises as sports do. –Solve many programming and mathematical problems. (7 assignments, 7 lab work, 4 math exercises, and 4 quizzes) Introduction

CSS342: Introduction3 Grading Read the class syllabus very carefully. Introduction Course Work% Midterm exam25% Final exam25% Programming assignments #1 - #732.5% Quizzes #1 - #412% (3% each) Laboratory work #1 - #73.5% In-classroom exercises #1 - #42% Total100%

CSS342: Introduction4 Questions and Discussions Professors’s account: Mailing list: Your account: –Only your UW account can participate in the discussion group. –You can still me from non-UW accounts for questions and appointments. GoPost: –Visit the class syllabus under and click GoPost. Introduction

CSS342: Introduction5 Introduction Programming Environment On-campus computing resources: –UW1-320: Linux Laboratory –UW1-310: Windows Laboratory IDE: –You can use any IDE: Eclips, etc. –HOWEVER, make sure that your program runs on Linux. Don’t use Windows-specific system functions. Visit for details: – nment.htmlhttp://courses.washington.edu/css342/fukuda/prog/assig nment.html

CSS342: Introduction6 Today’s Topics Software Engineering Principles –How to develop software –Namely, how to solve programming assignments in your case Chapter 1: –Review arrays, pointers, and structures Introduction

CSS342: Introduction7 Life Cycle of Software Specification Design Risk Analysis Verification Coding Testing Refining Production Maintenance Software Engineering

CSS342: Introduction8 Specification Clarify all aspects of the problem –What input data? Who will use it? What user interface? What level of error handling? Any special cases? What form of the output? Example: –Given a list of names, write a program to search the list for a specific name. Input data: a file containing a list of names and names to search for through keyboard input Who: your instructor User interface: ASCII-based Error handling: an error message upon a wrong file name Special cases:There may be two or more identical first names. Output:if the name is found, print out its entire name, otherwise output “Not found”. Software Engineering

CSS342: Introduction9 Design Modularity –Group cohesive parts into one well-defined module –Divide loosely-coupled parts into independent modules. Design Specification of Each Module –Write its interface as a contract with other modules. –Do not describe the method/implementation of solution. –Include preconditions and postconditions. Example: –Read a name list from a given input file.readFile( ) –Sort it.sort( ) –Repeat:while ( ) { Input a new name. Cin >> ….; Search for it. search( ) Print out if it was found. Cout << ….; } Software Engineering

CSS342: Introduction10 Design Cont’d Example: Sort( anArray, num ) // Sorts an array into alphabetical order. // Precondition: anArray is an array of num strings // and 1 <= num <= MAX_ARRAY, where MAX_ARRAY // is a global constant that specifies the maximum size of // anArray. // Postcondition: anArray[0] <= anArray[1] <= … <= // anArray[num – 1], num is unchanged. Software Engineering

CSS342: Introduction11 Design Cont’d How about Classes? UML Class Diagrams Software Engineering UML Interaction Diagrams Bank -name:string=null -routingNum:int=-1 +authorize( in name:string, in identifier:string ) -createAccount( ) attribute operation Account 1 0..* containment CheckingSavings generalization (inheritance) :Customerbank:Bank authorize(name, identifier) OK

CSS342: Introduction12 Verification Invariant: a condition that is always true at a particular point in an algorithm. Using invariants, algorithm will contain fewer errors before you begin coding. Example: // computes the sum of item[0], item[1], …, item[n-1] for any n >= 1 // Loop invariant: sum is the elements item[0] through item[j – 1]. int sum = 0; int j = 0;// 1: the invariant is true… sum = 0, item[0]..item[-1] while (j < n) {// 2: the invariant is true… sum is the same as case 1 or 3. sum += item[j]; ++j;// 3: the invariant is true… sum = item[0]+…+item[j-1] }// 4: the invariant is true and the loop always exits. Software Engineering

CSS342: Introduction13 Coding Coding is a relatively minor phase in the software life cycle. For any assignments, good coding style and appropriate comments reduce possible errors and makes modification easier. –Use descriptive variable names. –Use proper indentation in the loop and if-then interiors. –Insert blank lines between distinct functions, between code blocks, etc.. –Remove redundant code –Use functions for identifiable and recurring tasks. –Avoid tricky codes. –Adhere consistent coding style. (Otherwise, your assignment will be graded down.) Software Engineering

CSS342: Introduction14 Testing Test individual modules first: –Methods, –Objects, –Functions, –Each portion of main, and finally –Entire runs of your program If certain data must lie within a range, test with values at the endpoints of the range. Example: –Test how your program behaves given a wrong file name –Test what output will be shown upon a wrong name –Test what if there are two or more identical last names –Test what if there are two ore more identical first/last names. Software Engineering

CSS342: Introduction15 Data Abstraction and Objects Data Abstraction –A collection of data and a set of well-defined operations to the data can be reused without knowing the internal data representation and structure. Objects –Instances of such abstracted data structure = the first- class objects –Then, how about the second-class objects? Our main focus Information hiding Arrays, Pointers, and Structures

CSS342: Introduction16 Discussion: Why are the ordinary arrays and C strings the second-class objects? Arrays: C strings: Arrays, Pointers, and Structures

CSS342: Introduction17 Using the C++ Standard vector Arrays, Pointers, and Structures #include vector array; vector array( size_type num, const type &val ); vector array( const vector &from ); Creates a vector Example: vector a; vector a(3); vector a(3, 0); vector b( a ); ==, !=, =,, =, [] Operators, assignment, and indexing Example: a == b; (true if a and b has the same size, and the i-th member of a and that of b are identical void push_back( const type &val) Appends val to the end of the current vector Example: a.push_back(5); void resize( size_type size, type val ) Changes the size of the current vector to size, setting any newly-created elements to val. Example: a.resize(5, 10); size_type size( ) Returns the number of elements in the current vector. Example: a.size( ); For more info., visit

CSS342: Introduction18 Using the C++ Standard string Arrays, Pointers, and Structures In CIn C++ #include #include using namespace std; char *first = “Munehiro”;string first = “Munehiro”; char *last = “Fukuda”;string last = “Fukuda”; strcat( first, last );first += last; Note: first.length( ) returns the string size. first.c_str( ) returns an ordinary C char string. For more info., visit

CSS342: Introduction19 Call by Value, Reference, and Constant Reference Which of swap functions is appropriate? Arrays, Pointers, and Structures void swap(string a, string b) { string tmp = a; a = b; b = tmp; } void swap(const string &a, const string &b) { string tmp = a; a = b; b = tmp; } void swap(string &a, string &b) { string tmp = a; a = b; b = tmp; } int findMax(vector a) { int max = a[0]; int i; for (i=1; i < a.size(); i++) if (a[i] > max) max = a[i]; return max; } int findMax(vector &a) { int max = a[0]; int i; for (i=1; i < a.size(); i++) if (a[i] > max) max = a[i]; return max; } int findMax(const vector &a) { int max = a[0]; int i; for (i=1; i < a.size(); i++) if (a[i] > max) max = a[i]; return max; } Which of findMax functions is appropriate?

CSS342: Introduction20 Pointers 1.Pointer variablesint *p, *q; 2.Static allocationint x; 3.Address-of operatorp = &x; 4.Memory cell to which P points*p = 6; 5.Pointer operationsq = p; ??? pqx ?? pqx ?6 pqx 6 pqx Arrays, Pointers, and Structures

CSS342: Introduction21 Dynamic Allocation 1. Pointer declarationint *p, *q; 2. Dynamic allocationp = new int; q = new int; 3. Deallocationdelete p; p = NULL; 4. Memory leakq = new int; ? ? ? p q p q p q p q ??? ? NULL Leak! Arrays, Pointers, and Structures

CSS342: Introduction22 Discussion: What is the difference between the following three programs? Arrays, Pointers, and Structures string *stupid( ) { string s = “stupid”; return &s; } int main( ) { cout << *stupid( ) << endl; return 0; } string stupid( ) { string s = “stupid”; return s; } int main( ) { cout << stupid( ) << endl; return 0; } string *stupid( ) { string *s = new string( “stupid” ); return s; } int main( ) { cout << *stupid( ) << endl; return 0; }

CSS342: Introduction23 #include #define MAXSIZE 10 struct Students { string firstName; string lastName; char sex; int id; } void swap( Students& s1, Students& s2 ); void main( ) { vector myClass(MAXSIZE); swap( myClass[0], myClass[1] ); } void sway( Students& s1, Students& s2 ) { Students temp = s1; s1 = s2; s2 = temp; } Berger Cioch Olson Erdly Meske Liu McDaniel Fukuda Jackels Smolar Arnold Frank Clark Bill Dina Baili Janet Munehiro Chuck Darian M M M M F F F M M F myClass[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] temp BergerArnoldM0201 CiochFrankM0202BergerArnoldM0201 Structure and Its Array Arrays, Pointers, and Structures

CSS342: Introduction24 Discussion: What If Students’ firstName and lastName are pointers to string struct Students { string firstName; string lastName; char sex; int id; } struct Students { string *firstName; string *lastName; char sex; int id; } void sway( Students& s1, Students& s2 ) { Students temp = s1; s1 = s2; s2 = temp; } Arrays, Pointers, and Structures

CSS342: Introduction25 Some C++ Fundamentals Input/Output In C:In C++:In Java: #include #include using namespace std; int i;int i;int i; scanf( “%d”, &i );cin >> i;ObjectInputstream input = new ObjectInputStream( System.in ); try { i = input.readInt( ); } catch (..) { } i += 10;i += 10;i += 10; printf( “i + 10 = %d\n”, i );cout << “i + 10 =“ << i << endl;System.out.println( ‘i + 10 = “ + i ); Note: cin:standard input (from keyboard) cout:standard output (to display) cerr:standard error (to display but distinguished from cout) Arrays, Pointers, and Structures

CSS342: Introduction26 C++ Fundamentals Files In C:In C++:In Java: FILE *fp;ifstream inFile(“name.dat”);import java.io.*; orFileInputStream infile = istream inFile;new FileInputStream( “name.dat” ); if ((fp = fopen( “name.dat”, “r” ))inFile.open(“name.dat”);ObjectInputStream input = != NULL {if ( inFile ) { // true of falsenew ObjectInputStream( infile ); fscanf( fp, “%d”, &i );inFile >> i;try { i = input.readInt( ); fclose(fp);inFile.close( );} catch ( EOFException e ) { }}input.close( ); } Note: for output, use ofstream. Arrays, Pointers, and Structures