Copyright  1997 Oxford University Press All Rights Reserved

Slides:



Advertisements
Similar presentations
Chapter 12 Separate Compilation and Namespaces. Abstract Data Type (ADT) ADT: A data type consisting of data and their behavior. The abstraction is that.
Advertisements

Programming Paradigms and languages
EGR 141 Computer Problem Solving in Engineering and Computer Science
Overview Reference parameters Documenting functions A game of craps. Design, code, test and document.
Programming games Reprise on dice game and alternative dice game Homework: [Catch up.]. Finish dice game.
Chapter 3 Data Abstraction: The Walls. © 2005 Pearson Addison-Wesley. All rights reserved3-2 Abstract Data Types Modularity –Keeps the complexity of a.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
Probability And Expected Value ————————————
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 12 – Craps Game Application: Introducing Random.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 CSE1301 Computer Programming: Lecture 25 Software Engineering 2.
 2007 Pearson Education, Inc. All rights reserved C++ as a Better C; Introducing Object Technology.
C++ Functions. 2 Agenda What is a function? What is a function? Types of C++ functions: Types of C++ functions: Standard functions Standard functions.
CS Class 07 Topics –  When software goes wrong  Count controlled loops  Sentential controlled loops  putting it all together Announcements.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
38 4/11/98 CSE 143 Modules [Chapter 2]. 39 4/11/98 What is a Module?  Collection of related items packaged together  Examples:  Stereo System Components.
Loops Wrap Up 10/21/13. Topics *Sentinel Loops *Nested Loops *Random Numbers.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions (Header files and Library Functions) Outline.
Chapter 3 Top-Down Design with Functions Part II J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National.
Structures and Classes Version 1.0. Topics Structures Classes Writing Structures & Classes Member Functions Class Diagrams.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Craps Game Application Introducing Random-Number Generation and Enum.
1 CSC 222: Computer Programming II Spring 2004  classes and objects  abstract data types, classes and objects  using existing classes, #include, member.
ISBN Chapter 11 Abstract Data Types and Encapsulation Concepts.
Chapter 1 t Software Engineering and Computer Programming t Course presentations are available for view and downloading on the course web page: t
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 16 – Craps Game Application Introducing Random-Number.
Chapter 1 The Phases of Software Development. Software Development Phases ● Specification of the task ● Design of a solution ● Implementation of solution.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
Data Structures Lecture 4: Classes in C++ Azhar Maqsood NUST Institute of Information Technology (NIIT)
Fall 2001(c)opyright Brent M. Dingle 2001 Abstract Data Types (ADTs) Brent M. Dingle Texas A&M University Chapter 8 – Sections 2 and 3 (and some from Mastering.
Chapter 15 - C++ As A "Better C"
ICS 253: Discrete Structures I
Chapter 6: Modular Programming
Computer Fundamentals
Number guessing game Pick a random number between 1 and 10
Principles of Programming and Software Engineering
Chapter 4: Writing Classes
Abstract Data Types and Encapsulation Concepts
Chapter 5 - Functions Outline 5.1 Introduction
Chapter 5 Probability.
One-Dimensional Array Introduction Lesson xx
Using, Understanding, Updating, Designing and Implementing Classes
Chapter 4: Writing classes
Expected Value.
Chapter 16.
Probability And Expected Value ————————————
Chapter 1: An Overview of Computers and Programming Languages
Object-Oriented Programming Using C++ Second Edition
Truth tables: Ways to organize results of Boolean expressions.
Truth tables: Ways to organize results of Boolean expressions.
Object-Oriented Programming
Wednesday 09/23/13.
Programming We have seen various examples of programming languages
Chapter 7 Software Engineering.
Computing Fundamentals
Discrete Distributions
Probability And Expected Value ————————————
Discrete Distributions
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Discrete Distributions.
CS 144 Advanced C++ Programming January 31 Class Meeting
Discrete Distributions
Chapter 17 JavaScript Arrays
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Copyright  1997 Oxford University Press All Rights Reserved
Software Re-engineering and Reverse Engineering
Programming games Reprise on dice game and alternative dice game
Presentation transcript:

Copyright  1997 Oxford University Press All Rights Reserved Transparency Masters for Chapter 1 of Data Structures via C++ Objects by Evolution A. Michael Berman Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Chapter 1 Software Engineering and | Computer Programming Overview A preview and a context for the subjects covered in this book. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Chapter Objectives 1. To outline the relationship between Computer Science, Software Engineering, and the topics covered in this book. 2. To define “Data Structures” and “Abstract Data Types”. 3. To provide an overview of the process of software development 4. To describe the rationale for using the programming language C++. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Figure 1-1: The concerns of the computer scientist and the software engineer 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Definition 1-1 A data structure consists of a base storage method (e.g., an array) and one or more algorithms that are used to access or modify that data. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Code Example 1-1: A program demonstrating a dice data structure (part 1 of 2) // cx1-1.cpp // Code Example 1-1: a dice program that does not use an adt // // Illustrates the solution to a "dice simulation", without using // abstract data types. Compare this approach to cx1-2.cpp. #include "dslib.h" // contains standard header files for this book #include <stdlib.h> int main() { int die1, die2, total; randomize(); // initialize the pseudorandom number generator 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Code Example 1-1: A program demonstrating a dice data structure (part 2 of 2) die1 = random(6) + 1; // random(6) returns random number between 0 and 5 die2 = random(6) + 1; total = die1 + die2; cout << "first die: " << die1 << ", second die: " << die2 << endl; cout << "total for roll is: " << total << endl; return 0; } 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Definition 1-2 An Abstract Data Type (ADT) is a well- specified collection of data and a group of operations that can be performed upon the data. The ADT’s specification describes what data can be stored (the characteristics of the ADT), and how it can be used (the operations), but not how it is implemented or represented in the program. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved ADT 1-1: Dice (part 1 of 2) Characteristics: Represents a pair of 6-sided dice, that can be rolled to get a random sum between 2 and 12. Operations: int roll() Precondition: none. Postcondition: A random value between 1 and 6 is stored for each of the dice. Returns: The sum of the two dice values, lying between 2 and 12. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved ADT 1-1: Dice (part 2 of 2) int die1() Precondition: The dice have been rolled at least once. Postcondition: None. Returns: The value of the first die. int die2() Returns: The value of the second die. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Code Example 1-2: A program using a Dice ADT (Part 1 of 4) // cx1-2.cpp // Code Example 1-2: a dice program that uses an adt // // Illustrates the solution to a "dice simulation", using // abstract data types. Compare this approach to cx1-1.cpp. // Dice ADT // Characteristics: // Represents a pair of 6-sided dice, that can be rolled to get a // random sum between 2 and 12. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Code Example 1-2: A program using a Dice ADT (Part 2 of 4) // Operations: // int roll() // Preconditions: none // Postcondition: A random value between 1 and 6 is stored for each of // the dice. // Returns: The sum of the two dice values, lying between 2 and 12 // int die1() // Precondition: The dice have been rolled at least once. // Postcondition: None // Returns: The value of the first die. // int die2() // Returns: The value of the second die. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Code Example 1-2: A program using a Dice ADT (Part 3 of 4) // Note on encapsulation: The representation of the dice is contained // within global variables -- we'll see shortly a better way to do // this. #include <iostream.h> #include <stdlib.h> #include "dslib.h" int dice_1, dice_2; int roll() { // note -- you don't really want to call randomize every time you // roll the dice, but for this simplified design you don't have // much choice. randomize(); dice_1 = random(6) + 1; dice_2 = random(6) + 1; return dice_1 + dice_2; } 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Code Example 1-2: A program using a Dice ADT (Part 4 of 4) int die1() { return dice_1; } int die2() return dice_2; // end of Dice ADT int main() // test program to demonstrate Dice ADT cout << "The value rolled is: " << roll() << endl; cout << "The first die was: " << die1() << endl; cout << "The second die was: " << die2() << endl; return 0; 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Exercises 1-1 In the software distribution for this book you can find the programs cx1-1 and cx1-2, representing the Data Structure and ADT described above. Read, compile, and compare these two programs. 1-2 Design a different implementation of Dice, and modify cx1-2 to reflect your new implementation. How is the “main” function in cx1-1 affected by your change? 1-3 Design a different implementation of Dice, and modify cx1-2 to reflect your new implementation. How is the “main” function in cx1-2 affected by your change? 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Exercises 1-4 Some games for young children use colored squares on a board and a “spinner” that, in effect, picks one of the colors at random. Suppose that the game has five colors  red, green, blue, yellow, and orange. Design a “Spinner” ADT. 1-5 Implement your “Spinner” from Exercise 1-4. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Figure 1-2: One version of the waterfall model of software development Initiation Analysis Design Implementation Testing Maintenance 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Table 1-1: The waterfall model: A summary of the players and the deliverables 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Copyright  1997 Oxford University Press All Rights Reserved Exercises 1-6 What are the pluses and minuses of using comments in source code for systems documentation? 1-7 Determine the name and version number of the C++ compiler you will be using for your course. What standards, if any, does your compiler correspond with? 1-8 Determine which of the following relatively recent features of C++ your compiler supports: templates, exceptions, namespaces, Standard Template Library. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Chapter Summary (part 1 of 2) The subject matter of this book includes topics from Computer Science  the study of the principles that underlie computer software  and hardware and Software Engineering  the application of these principles to the development of software systems. Three processes encompass the work of the computing professional: theory, abstraction, and design. Data Structures implement Abstract Data Types. The Waterfall models the process of software development. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Chapter Summary (Part 2 of 2) Software engineers often supplement the waterfall model with development of prototypes. The trend toward reusable software has driven the development of new models of software development. C++ supports data abstraction and object-oriented programming. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-1 Using the Dice ADT from Section 1.1.1, write a program to measure the results of rolling 1000 pair of dice. Keep track of how many times the pair sums to each possible value between 2 and 12, and print out a histogram of the results. 1-2 Using the Dice ADT from Section 1.1.1, write a program that plays the game “Craps”. In Craps, the player makes a bet, then rolls a pair of dice. If the first roll is 7, the player wins the bet; if the first roll is 2, 11, or 12, the player loses. Otherwise, the total is called the “point”, and the player rolls pairs of dice until the dice add up to the point again (a winner) or until 7 is rolled (called “craps”, a loser). 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-3 Design and implement an ADT to represent a coin flip. Your ADT should have an operation, “flip”, which randomly returns a value “heads” or “tails” each time it is called. Test your ADT in a program that flips 10,000 coins and reports the number of heads and tails. 1-4 Design and implement an ADT for money. Note that money cannot be represented accurately by a floating point number, because of rounding. Test your ADT by writing a program that simulates a cash register  the user enters amounts which are added together and a total is reported. You can enhance your program by adding a tax computation, and a way to back out a transaction after it has been entered. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-5 Find a program that you wrote last semester. Write a functional specification for the program. Develop, in consultation with your instructor, a significant improvement to the program, and write a revised functional specification for the new program. Modify your program to correspond with the new specification. What things about the way you wrote your original program made it easier to modify? What things made it harder? 1-6 Find a program that you wrote in a language other than C++, and convert it to C++. In what ways is the program different in C++ than it was in the original language? 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-7 The C++ standard includes a definition of a String ADT. C++ also supports the traditional “C”-style string (char *). Write a program, using the String ADT, that creates a string of length 1000, puts random characters into the string, and then counts the number of times the letter “A” is found. Rewrite the program using “C”- style strings. Using the “Stopwatch” class provided by the author of this book, compare the performance of the two programs. If you see no difference, try making the problem bigger. Report the performance difference, if any, between the two String implementations. 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-8 (For those already familiar with C++ classes.) Rewrite the Dice ADT as a C++ class. Test your class by instantiating several Dice objects. What are the advantages of using a C++ class? Are there any disadvantages? 1-9 Design an ADT and a data structure for storing an email header. You can assume that the following fields are required: From, To, Reply-To, Date, and Subject, and that the each line can be stored in a single string. Implement your ADT, and a program that tests it by first prompting the user to enter the data for the header and then printing it out. (Hint: I recommend you use C++ strings, not C (char *) strings.) 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved

Programming Laboratory Problems 1-10 Using the facilities provided by your implementation of C++, write a program that uses a graphical user interface (GUI) to open a window, read in a word, and convert it to uppercase. What abstraction mechanisms does the GUI software use? 2019-06-03 Copyright  1997 Oxford University Press All Rights Reserved