Introduction to Object-Oriented Programming with C++

Similar documents
CS24 Week 3 Lecture 1

Fundamentals of Programming. Lecture 19 Hamed Rasifard

Use the dot operator to access a member of a specific object.

Classes - 2. Data Processing Course, I. Hrivnacova, IPN Orsay

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi

Classes and Objects in C++

C C C C++ 2 ( ) C C++ 4 C C

AN OVERVIEW OF C++ 1

UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class

Inheritance, and Polymorphism.

C++ 8. Constructors and Destructors

CS11 Introduction to C++ Fall Lecture 1

CS

CSE 303: Concepts and Tools for Software Development

Midterm Exam 5 April 20, 2015

Friend Functions, Inheritance

Object Oriented Programming: Inheritance Polymorphism

Exceptions, Case Study-Exception handling in C++.

CS 11 C++ track: lecture 1

CSCE 110 PROGRAMMING FUNDAMENTALS

CSC1322 Object-Oriented Programming Concepts

W3101: Programming Languages C++ Ramana Isukapalli

Introduction Of Classes ( OOPS )

Introduction to the C programming language

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CS 162, Lecture 25: Exam II Review. 30 May 2018

Object-Oriented Programming in C++

Introduction to the C programming language

Lab 1: First Steps in C++ - Eclipse

Fast Introduction to Object Oriented Programming and C++

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

EL2310 Scientific Programming

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

CS3157: Advanced Programming. Outline

The Class. Classes and Objects. Example class: Time class declaration with functions defined inline. Using Time class in a driver.

Lecture 8. Object Oriented Design

Understanding main() function Input/Output Streams

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Implementing an ADT with a Class

Computational Physics

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Lecture 7. Log into Linux New documents posted to course webpage

1 Unit 8 'for' Loops

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

Object-Oriented Programming (OOP) Fundamental Principles of OOP

CS11 Intro C++ Spring 2018 Lecture 1

Intermediate Programming, Spring 2017*

Review: C++ Basic Concepts. Dr. Yingwu Zhu

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A.

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

COP 3530 Discussion Session #2 Ferhat Ay

Chapter 1: Object-Oriented Programming Using C++

COMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli

(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

LECTURE 02 INTRODUCTION TO C++

Paytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value

ECE 462 Exam 1. 6:30-7:30PM, September 22, 2010

Friends and Overloaded Operators

Introduction to C++ Homework Assignment. Fundamental Concepts. rvalues and lvalues. Programming Standards. A Basic Program.

Friends and Overloaded Operators

Wentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. C++ Kitchen Sink. Lecture 14.

COEN244: Class & function templates

Intermediate Programming, Spring 2017*

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

Outline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor

Constructor - example

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

DELHI PUBLIC SCHOOL TAPI

CAAM 420 Fall 2012 Lecture 29. Duncan Eddy

Global & Local Identifiers

Short Notes of CS201

More Tutorial on C++:

The mechanism that allows us to extend the definition of a class without making any physical changes to the existing class is called inheritance.

Lecture 8. Xiaoguang Wang. February 13th, 2014 STAT 598W. (STAT 598W) Lecture 8 1 / 47

Programming Language. Functions. Eng. Anis Nazer First Semester

Operator overloading: extra examples

CS201 - Introduction to Programming Glossary By

Object Oriented Programming in C++

EECS 183 Fall 2015 Exam 2 Free Response (134 points)

Dr. Md. Humayun Kabir CSE Department, BUET

Recharge (int, int, int); //constructor declared void disply();

Function Overloading

Classes and Pointers: Some Peculiarities

Programming II Lecture 2 Structures and Classes

Interlude. Object Oriented Design

Programming. C++ Basics

SFU CMPT Topic: Classes

(5 2) Introduction to Classes in C++ Instructor - Andrew S. O Fallon CptS 122 (February 7, 2018) Washington State University

Chapter 9 Objects and Classes. Liang, Introduction to C++ Programming, (c) 2007 Pearson Education, Inc. All rights reserved.

CS 31 Discussion 1A, Week 4. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 a.m.

Engineering Tools III: OOP in C++

Lab 12 Object Oriented Programming Dr. John Abraham

Scientific Computing

CSE030 Fall 2012 Final Exam Friday, December 14, PM

CMSC 202 Section 010x Spring Justin Martineau, Tuesday 11:30am

CSCE Practice Midterm. Data Types

Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING

Transcription:

Computational Introduction to Object-Oriented ming with C++ 02/19/2009

Outline 1 2 3 4

1 Read Chapter 8 Control logic and iteration 2 s of Section 8.10: Part I, (1) - (11) Due next Tuesday, February 24

Some Comments on Grading Scheme for Projects 1 The projects-related files must be posted on your comphy web site... 2 The projects should be properly documented. 3 Your programs must compile. 4 All your programs should be coded according to our programming standards: Variables need to be initialized! 5 The programs must do what is required. 6...

Outline 1 2 3 4

// Simple C style 2D point double Point[2]; Point[0] = 0.0; Point[1] = 0.0; // Data array for x,y // x value // y value void addpoints(double P1[], double P2[], double Psum[]) { Psum[0] = P1[0] + P2[0]; Psum[1] = P1[1] + P2[1]; void printpoint(double P[]) { cout < < point(x,y) is ( < < P[0] < <, < < P[1] < < ) < < endl; Combining Data with Functionality #include <iostream.h> int main() { double P1[2], P2[2], P[2]; P1[0] = 1.0; P1[1] = 1.0; P2[0] = 2.0; P2[1] = 2.0; addpoints(p1, P2, P); printpoint(p1); printpoint(p2); printpoint(p);

Outline 1 2 3 4

Defining an Object via C++ Class A class is a template for containing 1 Data (often hidden from user) 2 Member functions Constructors, Destructors, Getters, & Setters 3 Scope

class { double ix; double iy; OOP Syntax: public: (); (double ax, double ay); void setx(double ax) { ix = ax; void sety(double ay) { iy = ay; double x() { return ix; double y() { return iy; operator+( &ap); void print(); Function Definition ::print() { cout < < Point(x,y) is < < x() < <, < < y() < <, < < endl;

class { OOP Syntax: double ix; double iy; private public: (); (double ax, double ay); void setx(double ax) { ix = ax; void sety(double ay) { iy = ay; double x() { return ix; double y() { return iy; operator+( &ap); void print(); Function Definition ::print() { cout < < Point(x,y) is < < x() < <, < < y() < <, < < endl;

class { double ix; double iy; public: (); (double ax, double ay); void setx(double ax) { ix = ax; void sety(double ay) { iy = ay; double x() { return ix; double y() { return iy; operator+( &ap); void print(); OOP Syntax: Function Definition ::print() { cout < < Point(x,y) is < < x() < <, < < y() < <, < < endl;

class { double ix; double iy; public: (); (double ax, double ay); void setx(double ax) { ix = ax; void sety(double ay) { iy = ay; double x() { return ix; double y() { return iy; operator+( &ap); void print(); OOP Syntax: Constructors Function Definition ::print() { cout < < Point(x,y) is < < x() < <, < < y() < <, < < endl; ::() { setx(0.0); sety(0.0); ::(double ax, double ay) { setx(ax); sety(ay);

#include <iostream> using namespace std; int main() { P1; P2(1.0, 1.0); P3(2.0, 2.0); comphy > g++ points.cc -o points comphy >./points Point(x,y) is (0,0) Point(x,y) is (1,1) Point(x,y) is (2,2) Point(x,y) is (3,3) comphy > P1.print() P2.print() P3.print() P1 = P2 + P3; P1.print();

If we want to represent the data by (r, Θ) rather than by (x, y) then very little changes are need in the class definition and NO changes will be needed in the user code.

Extending Objects: Line2D class Line2D { ip1; ip2; public: Line2D( ap1, ap2); void setp1( ap1); void setp2( ap2);... Line2D has a!

: Point3D class Point3D : public { double iz; public: Point3D(); Point3D(double ax, double ay, double az); void setz(double az) { iz = az; double z() { return iz; Point3D operator+(point3d &ap); void print(); Point3D::Point3D(double ax, double ay, double az) { setx(ax); sety(ay); setz(az); Point3D is a!

Outline 1 2 3 4

This Week s Project Write a program that contains a class Rectangle with two private double precision members ilength and iwidth, public set and get member functions for the two members, a two-argument constructor that sets the length and width to any two user-specified values, and a void function area() that computes the area and prints this value by inserting it into the cout output stream. Write a main function that creates a Rectangle with a length of 10 and width of 20 and computes its area.