Classes (Chapter 6.2-6.3) Classes (Chapter 6.2-6.3) Data with natural operations Classes Using Classes.

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick Strings #include using namespace std; int main () { string word; cout
Advertisements

ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 11/8/06CS150 Introduction to Computer Science 1 Arrays Chapter 8 page 477 November 13, 2006.
1 10/9/06CS150 Introduction to Computer Science 1 for Loops.
1 CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 9/26/07CS150 Introduction to Computer Science 1 Exponents & Output page & Section 3.8.
1 11/8/06CS150 Introduction to Computer Science 1 More Functions! page 343 November 8, 2006.
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.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Chapter 1 Working with strings. Objectives Understand simple programs using character strings and the string library. Get acquainted with declarations,
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 223 – Advanced Data Structures C++ Review Part-I.
Advanced Computer Science Lesson 4: Reviewing Loops and Arrays Reading User Input.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
1 COMS 261 Computer Science I Title: Functions Date: October 12, 2005 Lecture Number: 17.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
Chapter 3 Functions. 2 Overview u 3.2 Using C++ functions  Passing arguments  Header files & libraries u Writing C++ functions  Prototype  Definition.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
1 COMS 261 Computer Science I Title: Classes Date: November 9, 2005 Lecture Number: 29.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays days until the AP Computer Science test.
1 COMS 261 Computer Science I Title: Classes Date: November 4, 2005 Lecture Number: 27.
Input, Output and Variables GCSE Computer Science – Python.
Chapter 1.2 Introduction to C++ Programming
Programming what is C++
Chapter 1.2 Introduction to C++ Programming
Chapter 7 User-Defined Methods.
Chapter 1.2 Introduction to C++ Programming
Engineering Problem Solving With C An Object Based Approach
What Actions Do We Have Part 1
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Template Classes CMPS 2143.
Data Types and Conversions, Input from the Keyboard
Chapter 7 Text Input/Output Objectives
COMPUTER 2430 Object Oriented Programming and Data Structures I
Designing Classes Eric Roberts CS 106B January 16, 2015.
Chapter 5 Classes.
Multi-dimensional Array
Java Generics Lecture 17 CS2110 – Spring 2017
C++ Arrays.
– Introduction to Object Technology
group work #hifiTeam
CS 1430: Programming in C++.
Chapter 2 Elementary Programming
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Operator Overloading; String and Array Objects
CS150 Introduction to Computer Science 1
Computing Functions with Turing Machines
Wednesday 09/23/13.
Coding Concepts (Data- Types)
COMS 261 Computer Science I
Lecture 2: A Tour of the Standard Library
Fundamentals of Python: First Programs
CS150 Introduction to Computer Science 1
Jeff West - Quiz Section 4
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
CS149D Elements of Computer Science
What Actions Do We Have Part 1
Introduction to Computer Science
COMS 261 Computer Science I
Presentation transcript:

Classes (Chapter ) Classes (Chapter ) Data with natural operations Classes Using Classes

Data and Associate Operations As we saw last time there is an natural set of operations associate with strings: Initializing Printing Matching substrings Concatenating strings Extracting substrings. Copying strings

Data and Associate Operations But copying a string is a different operation than copying an integer. Likewise printing a string is a different operation that printing a double. Generally it is the case that a specific type of data must have a specific set of operations associated with it to manipulate that data. Moreover the programs designed to manipulate the data are dependent on the specific way the data is stored in the computer.

Data and Associate Operations The form of the data's representation may need to different on machines with different architectures but the natural operations remain the same. That is, for a given type of data, we should implement a set of operations that is associate with it without requiring the user to know details of how it is implemented.

Classes class These observation led to the development of the concept of a class the defined both the implementation and the natural operations associate with the type of data. object oriented programming languages Classes are the basic underlying idea of a object oriented programming languages like C++, Java, Python, etc

Computer Science Fact Barbara Liskov won the 2008 Turing award (the CS equivalent of the Nobel Prize) for her work on Object Oriented Programming Languages.

A Simple Class #include using namespace std; class Point { // point in Cartesian plane public: Point() {} Point( double, double ); double getX() const { return x; } double getY() const { return y; } private: double x, y; }; // // Create a Point object, initializing data members to parameter values // Point::Point( double xval, double yval ) { x = xval; y = yval; } int main() { Point pt1( 5.1, -4.7 ); cout << "The point is (" << pt1.getX() << ", " << pt1.getY() << ")\n"; return 0; } Access specifier class name constructo r class data Object declaration

Using Classes gplot.h graph.cpp Homework: (Due Thursday November 12 before class). Write a program to plot the function f(x)=sin(exp(x))+x/4. The program should ask the user for the range of x over which the program should be graphed and the number of points to plot. Then it should plot f(x) for x in the specified range. Five points extra credit if you can use that program to find the first positive zero of that function to 3 digits accuracy. Explain how you did it.

Homework Problem: Compute the average and standard deviation of a set of n integer test scores, where the user is asked to input n and then the n test scores. A solution is here.here