CPS 100 1.1 What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.

Slides:



Advertisements
Similar presentations
Chapter 8 Technicalities: Functions, etc. Bjarne Stroustrup
Advertisements

Chapter 12 Lists and Iterators. List Its an abstract concept not a vector, array, or linked structure. Those are implementations of a List. A list is a.
A Computer Science Tapestry 1.1 What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is.
Inheritance. Extending Classes It’s possible to create a class by using another as a starting point  i.e. Start with the original class then add methods,
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
CSE 332: C++ templates and generic programming I Motivation for Generic Programming in C++ We’ve looked at procedural programming –Reuse of code by packaging.
CPS 108 : Spring What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking.
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Object Oriented Data Structures
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
Programming Languages and Paradigms Object-Oriented Programming.
Lecture 22 Miscellaneous Topics 4 + Memory Allocation.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Introduction to Object-oriented programming and software development Lecture 1.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
Compsci 06/101, Fall COMPSCI 06/101, Fall 2010 Owen Astrachan Robert Duvall
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Introduction. 2COMPSCI Computer Science Fundamentals.
Chapter 6 Writing a Program John Keyser’s Modification of Slides by Bjarne Stroustrup
CSCI-383 Object-Oriented Programming & Design Lecture 13.
CPS Topics since last test l Recursion l Software design  Object-oriented  Copyright issues l Computer systems  Hardware  Architecture  Operating.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
A Computer Science Tapestry 12.1 Tools for programming l Syntatic details of control and variables  If, while, switch, function calls  Scope and lifetime.
CPS 100, Fall COMPSCI 100, Fall 2009 Owen Astrachan
1 CSC 222: Computer Programming II Spring 2004 See online syllabus at: Course goals:
CPS Anagram: Using Normalizers l How can we normalize an Anaword object differently?  Call normalize explicitly on all Anaword objects  Have.
CompSci CompSci 6 Programming Design and Analysis I Dietolf (Dee) Ramm
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 1.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 6 Writing a Program Hartmut Kaiser
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.
Software Design 14.1 CPS 108 l Object oriented design and programming of medium-sized projects in groups using modern tools and practices in meaningful.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
APCS Workshop 1 Why is programming fun? What delights may its practitioner expect as a reward? First is the sheer joy of making things Second is the pleasure.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
CPS 100, Spring COMPSCI 100, Spring 2009 Owen Astrachan
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
1 Today’s Objectives  Announcements Homework #3 is due on Monday, 10-Jul, however you can earn 10 bonus points for this HW if you turn it in on Wednesday,
C++ Inheritance Data Structures & OO Development I 1 Computer Science Dept Va Tech June 2007 © McQuain Generalization versus Abstraction Abstraction:simplify.
A Computer Science Tapestry 10.1 From practice to theory and back again In theory there is no difference between theory and practice, but not in practice.
Overview of C++ Polymorphism
Compsci 06/101, Spring COMPSCI 06/101, Spring 2011 Introduction to Computer Science Owen Astrachan
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
Duke CPS CPS 108, Spring 1998 l Software Design and Implementation ä Object oriented programming and design ä good design helps do away with late.
Duke University Computer Science 1 Topics since last test l More invariants l Pixmap l Sorting & Templates  Selection sort  Insertion sort  Quicksort.
(c) University of Washington05-1 CSC 143 Java Abstract Classes and Frameworks Reading: Ch. 11.
CPS Searching, Maps, Tables l Searching is a fundamentally important operation ä We want to do these operations quickly ä Consider searching using.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Motivation for Generic Programming in C++
CSC 222: Object-Oriented Programming
Reuse Separate classes could be developed for all the different objects that are needed in each program. However that would be wasteful. Often many functionalities.
7. Inheritance and Polymorphism
CompSci 100 Dietolf (Dee) Ramm
Announcements HW6 due this Wednesday
CompSci 6 Introduction to Computer Science
Lecture 2 of Computer Science II
Announcements Final Exam on August 17th Wednesday at 16:00.
Announcements Final Exam on August 19th Saturday at 16:00.
Announcements HW6 due this Wednesday
Program Design and Analysis II Professor: Jeffrey Forbes
COMPSCI 100, Spring 2008 Owen Astrachan
Presentation transcript:

CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex. C.A.R. (Tony)Hoare

CPS Why is programming fun? What delights may its practitioner expect as a reward? First is the sheer joy of making things Second is the pleasure of making things that are useful Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts Fourth is the joy of always learning Finally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from pure thought- stuff. Fred Brooks

CPS Efficient Programming l Designing and building efficient programs efficiently requires knowledge and practice  Hopefully the programming language helps, it’s not intended to get in the way  Object-oriented concepts, and more general programming concepts help in developing programs  Knowledge of data structures and algorithms helps l Tools of the engineer/scientist programmer  A library or toolkit is essential, don’t reinvent the wheel  Someone must build the tools  Programming is not just art, not just science, not just engineering

CPS Course Overview l Lectures, Recitations, Quizzes, Programs  Recitation based on questions given out in previous week Discuss answers, answer new questions, small quiz? More opportunities for questions to be answered.  Lectures based on readings, questions, programs Online quizzes used to motivate/ensure reading In-class questions used to ensure understanding  Programs Theory and practice of data structures and OO programming Fun, practical, tiring, … l Ask questions, give feedback, provide guidance  Arno Penzias and others say "ask good questions"

CPS Tradeoffs l This course is about all kinds of tradeoffs: programming, structural, algorithmic  Programming: simple, elegant, quick to run/to program Tension between simplicity and elegance?  Structural: how to structure data for efficiency What issues in efficiency? Time, space, programmer-time  Algorithmic: similar to structural issues l How do we decide which choice to make, what tradeoffs are important?

CPS See readwords.cpp l This reads words, how can we count different/unique words? tvector list; string filename,word; cin >> filename; ifstream input(filename.c_str()); CTimer timer; timer.Start(); while (input >> word) { list.push_back(word); } timer.Stop(); cout << "read " << list.size() << " words in "; cout << timer.ElapsedTime() << " seconds" << endl;

CPS Tracking different/unique words l We want to know how many times ‘the’ occurs  Do search engines do this? Does the number of occurrences of “basketball” on a page raise the priority of a webpage in some search engines? Downside of this approach for search engines? l Constraints on solving this problem  We must read every word in the file (or web page)  We must search to see if the word has been read before  We must process the word (bump a count, store the word)  Are there fundamental limits on any of these operations? Where should we look for data structure and algorithmic improvements?

CPS Search: measuring performance l How fast is fast enough? bool search(const tvector & a, const string & key) // pre: a contains a.size() entries // post: return true if and only if key found in a { int k; int len = a.size(); for(k=0; k < len; k++) if (a[k] == key) return true; return false; } l C++ details: parameters? Return values? Vectors? l How do we measure performance of code? Of algorithm?  Does processor make a difference? PIII, G4, ???

CPS Tradeoffs in reading and counting l If we read all the words, then sort them, can we determine unique words?  frog, frog, frog, rat, tiger, tiger, tiger, tiger l If we look up words as we're reading them and bump a counter if we find the word, is this slower than previous idea?  How do we look up word, how do we add word l Are there kinds of data that make one approach preferable?  What is best case, worst case, average case?

CPS Structuring data: readwords4.cpp l Search for a word using binary search  Differences from sequential/linear search?  What’s a precondition for binary search to work? l How can we store new words so that binary search will work?  Add to end of vector and sort the vector  Add to end of vector and shift (down) until location found  Advantages of one method over another? l What about the C++ details in using a struct/class to store data, how are comparisons made?

CPS Flexibility l About Linux compared to Windows  “ All this flexibility comes with a price : complexity. Many vendors are realizing that ease of use is paramount for most and have developed standard "distributions" consisting of Linux bundled with a wide range of necessary software, from word processors and spreadsheets to personal organizers. Some of these distributions are: RedHat (perhaps the best known), SuSE, Debian, Slackware and Mandrake.”

CPS Flexibility l About FPGAs compared to general computers  “The most common type of computing system is the general- purpose processor. Under this model, the hardware of the system is limited to merely a few basic tasks. By combining and building off of these operations, a general-purpose computer can perform a much larger number of operations than it was originally designed to handle. Which is why the general- purpose computer is so flexible. However this flexibility comes with a price. For any specific application, the general-purpose processor will perform poorly when compared to a custom hardware implementation”

CPS Toward understanding inheritance l Consider Yahtzee program  Several kinds of score-card entries: aboveline, fullhouse,…  What do we do to add a new kind, or change definition Edit working program, add code to code that already works Not haphazard, but dangerous: if it ain’t broke, don’t touch l The “open-closed” principle of program building/design  Programs/classes should be open for extension, but closed to modification (Bertrand Meyer and Robert Martin)  How do we change code without altering it? This is a goal, in practice we modify some, but minimize l Inheritance lets us realize the principle (in theory)

CPS Use interfaces, not implementations l See yahtzee program, ScoreEntry, DiceGroup  Subclasses: AboveLine, FullHouse, ThreeKind, …  Subclasses: CupOfDice and FixedDice (game and testing) l We have parent, base, or super -class for interface  Child or Subclasses extend the parent class ( implement interface)  pointers to parent class, which can point to child object I’m pointing at an animal (could be marsupial or bird) l Child/sub classes don’t have access to private data/functions, but the data are there (alternative: use protected)  See ScoreEntry for details

CPS Syntactic details l Functions in parent class that are changeable in subclasses must be declared as virtual  The “real” function is determined at runtime  In parent/base/super class make all functions virtual  We must have a virtual destructor that’s implemented l For interface only functions, that have no default version  Pure virtual functions, aka abstract functions  Syntax requires = 0 in.h file  Can’t instantiate an object of an abstract (base) class Doesn’t matter, really, we use pointers to objects