1 CS 132 Spring 2008 Chapter 1 Software Engineering Principles and C++ Classes.

Slides:



Advertisements
Similar presentations
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
Advertisements

The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Wednesday, 10/2/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 10/2/02  QUESTIONS (on HW02 – due at 5 pm)??  Today:  Review of parameters  Introduction.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 11: Classes and Data Abstraction.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
1 Lab Session-XIV CSIT121 Spring 2002 b Namespaces b First Class Travel b Lab Exercise 14 (Demo) b Lab Exercise b Practice Problem.
C++ data types. Structs vs. Classes C++ Classes.
Chapter 11: Classes and Data Abstraction
Software Engineering Principles and C++ Classes
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
COMP 14 Introduction to Programming Miguel A. Otaduy May 24, 2004.
Introduction - The Need for Data Structures Data structures organize data –This gives more efficient programs. More powerful computers encourage more complex.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
Data Structures Using C++1 Chapter 2 Object-Oriented Design (OOD) and C++
CLASSES AND DATA ABSTRACTION
Chapter 11: Inheritance and Composition. Objectives In this chapter, you will: – Learn about inheritance – Learn about derived and base classes – Redefine.
Chapter 11: Classes and Data Abstraction. C++ Programming: Program Design Including Data Structures, Fourth Edition2 Objectives In this chapter, you will:
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
CHAPTER 13 CLASSES AND DATA ABSTRACTION. In this chapter, you will:  Learn about classes  Learn about private, protected, and public members of a class.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Data Structures Using C++1 Chapter 1 -Software Engineering Principles -ADT and Classes.
Chapter 8: User-Defined Classes and ADTs
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
Data Structures Using C++1 Chapter 1 Software Engineering Principles and C++ Classes.
Design.ppt1 Top-down designs: 1. Define the Problem IPO 2. Identify tasks, Modularize 3. Use structure chart 4. Pseudocode for Mainline 5. Construct pseudocode.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Software Engineering Review CS 244 Brent M. Dingle, Ph.D. Game Design and Development Program Department of Mathematics, Statistics, and Computer Science.
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.
CSCI 1100/1202 April 1-3, Program Development The creation of software involves four basic activities: –establishing the requirements –creating.
Data Structures Using C++ 2E
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 12: Classes and Data Abstraction.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
EGR 2261 Unit 11 Classes and Data Abstraction  Read Malik, Chapter 10.  Homework #11 and Lab #11 due next week.  Quiz next week.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
CS 132 Spring 2008 Chapter 2 Object-Oriented Design (OOD) and C++ Ideas: * Inheritance (and protected members of a class) ** Operator overloading Pointer.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 11: Classes and Data Abstraction.
Chapter 1 Software Engineering Principles. Problem analysis Requirements elicitation Software specification High- and low-level design Implementation.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 12: Classes and Data Abstraction.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 05: Classes and Data Abstraction.
Chapter 11: Inheritance and Composition. Introduction Two common ways to relate two classes in a meaningful way are: – Inheritance (“is-a” relationship)
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
72 4/11/98 CSE 143 Abstract Data Types [Sections , ]
Chapter 2 Principles of Programming and Software Engineering.
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 11: Classes and Data Abstraction.
CHAPTER 13 CLASSES AND DATA ABSTRACTION. In this chapter, you will:  Learn about classes  Learn about private, protected, and public members of a class.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Chapter 12 Classes and Abstraction
EGR 2261 Unit 13 Classes Read Malik, Chapter 10.
CS 215 Final Review Ismail abumuhfouz Fall 2014.
Java Programming: Guided Learning with Early Objects
About the Presentations
User-Defined Classes and ADTs
Chapter 8: User-Defined Classes and ADTs
User-Defined Classes and ADTs
Chapter 8 Classes User-Defined Classes and ADTs
Presentation transcript:

1 CS 132 Spring 2008 Chapter 1 Software Engineering Principles and C++ Classes

2 What Do You Know Now? You can –take a problem of medium complexity –write an algorithm to solve it –code the algorithm in C++, and –determine the correctness of the solution You are reasonably adept at trouble-shooting when something does not work Next: –new data structures –object-oriented approach to program organization –a greater emphasis on software engineering

Software Engineering A disciplined approach to the design, production, and maintenance of computer programs that are developed on time and within cost estimates, using tools that help to manage the size and complexity of the resulting software products Life cycle: the phases a program goes through from when is conceived until it is retired

4 Approximate lifecycle costs

5 Software Development Phases Analysis –understand problem –divide it into subproblems and analyze them Design –algorithms –structured design (functions) –object-oriented design (objects/classes) Implementation –write code for classes and functions discovered in design phase Testing and Debugging –make sure the program does what it is supposed to –find and fix errors –run program through series of specific tests and test cases

6 Development Phases, Another View Requirements (what should the system do) Implementation Test Plan Formal Testing Our emphasis this semester: implementation

Design: Two Approaches to Building Manageable Modules Divides the problem into more easily handled subtasks, until the funct- ional modules (subproblems) can be coded Identifies objects composed of data and operations that can be used to solve the problem STRUCTURED DESIGN OBJECT-ORIENTED DESIGN FOCUS: processes FOCUS: data objects Which have you done?

8 Object-Oriented Design (OOD) Three principles –encapsulation combine data and operations in a single unit what have we encapsulated to date? –inheritance create new data types from existing types e.g. car → suv –polymorphism use the same expression to denote different operations where have we done this?

9 Algorithm Analysis: the Big-O notation n = # houses effort = n = 2n to each house back

10 Algorithm Analysis: Big-O Notation n = # houses effort = 2( n) = 2(n+1)n/2 = n 2 + n to each house and back

11 Algorithm Analysis: Big-O Notation

12 Algorithm Analysis: Big-O Notation We will refer to the order of algorithms, but not do much with it

13 Class The BIG concept A collection of a fixed number of components Components: –public (members of class accessible outside class) –private (members of class not accessible outside the class) –protected (members of class that only "friends" can use)

14 Syntax for Defining a Class reserved word the name you give a class a variable in the class a function applied to it variables and functions Where have you seen something like this? fout.open classIdentifier classVariableName; Declaring a variable: classIdentifier classVariableName; classVariableName.memberName Invoking a function: classVariableName.memberName

15 class clockType { public: void setTime(int hours, int minutes, int seconds); void getTime(int& hours, int& minutes, int& seconds); void printTime() const; void incrementSeconds(); clockType(int hours, int minutes, int seconds); clockType(); private: int hr; int min; int sec; }; Class name Private members* Public members* * members are variables or methods (functions)

16 class clockType clockType myClock; myClock.SetTime(2, 26, 47); clockType yourClock; yourClock.SetTime(14, 39, 28);

17 class clockType After myClock = yourClock;

18 How Do We Use This? clockType.h // the file that specifies the member functions clockTypeImp.cpp // implementation of the member functions clock1.cpp // a driver that uses the class A project that links them –compile the driver –this creates a project –add the implementation to the project –project files are visible via View/Workspace/FileView Try it: –add a member function that returns just the hour –augment the driver (clock1.cpp) to test it –run it

19 Constructors Invoked when a class instance is created. (analogous to a when variable is declared last semester) Functions included in public clockType(); //default clockType(int hours, int minutes, int seconds); clockType(int hours, int minutes, int seconds); Syntax to invoke the default constructor clockType myClock; //initializes components to 0,0,0

20 Constructors Syntax to invoke a constructor with a parameter: clockType myClock(2, 26,47); //initializes to 2,26,47 If no parameters are given, the default constructor applies See clock2.cpp Destructors Function like constructors Called when the object goes out of scope Used to return memory Later

21 Data Abstraction Abstract data type (ADT): –specify the logical properties without the implementation details Information hiding –separate implementation details from the logical properties of an ADT In C++ classes –a header file (clockType.h) that contains the specification –a separate file (clockTypeImp.cpp) with implementation details How does clockTypeImp.cpp implement clockType.h? Note, we are hiding how clockType is represented Could it be done differentl y?

22 Example: listType (p.38) Why is this a good candidate for data abstraction? What functions would you want for a list? –check to see if list is empty –check to see if list is full –search for a given item –delete an item –insert an item –sort How might you implement it? –an array –an integer for the number of elements

23 Example: personType Components: first and last name Functions: print, change the name, retrieve the name Code: person.h, personImp.cpp, persondr.cpp Exercise: add a function to return the last name personType -firstName: string -lastName: string +print(): void +setName(string, string): void +getName(string&, string&): void +personType(string="", string="")

24 complexType Complex numbers: a + bi or (a,b) where i 2 = -1 (a,b) + (c,d) = (a+c, b+d) (a,b) - (c,d) = (a-c, b-d) (a,b) * (c,d) = (ac - bd, bd + ac) (a,b) / (c,d) = ((ac+bd)/(c 2 + d 2 ), (bc-ad)/(c 2 + d 2 )) How would we make a class? Code: complexType.h, complexType.cpp, testComplex.cpp Later: a version with function overloading

25 Programming Example: Candy Machine Problem statement: A common place to buy candy is from a candy machine. A new candy machine is bought for the gym, but it is not working properly. The machine sells candies, chips, gum, and cookies. You have been asked to write a program for this machine so that it can be put into operation. The program should do the following: 1.Show the customer the different products sold by the candy machine. 2.Let the customer make a selection. 3.Show the customer the cost of the item selected. 4.Accept money from the customer. 5.Release the item.

26 Candy Machine Input –Item selection –Cost of Item Output –The selected item Components –Cash register –Several dispensers

27 Candy Machine: sample run