SNPL1 Woochang Lim C+OOP = C++ C (non OOP)  C++ (non OOP+OOP)  Java (OOP) Object-Oriented Design  Object-Oriented Programming Programming with C++

Slides:



Advertisements
Similar presentations
A C++ Crash Course Part II UW Association for Computing Machinery Questions & Feedback.
Advertisements

C++ Language Fundamentals. 2 Contents 1. Introduction to C++ 2. Basic syntax rules 3. Declaring and using variables.
IT 325 OPERATING SYSTEM C programming language. Why use C instead of Java Intermediate-level language:  Low-level features like bit operations  High-level.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
C++ Classes & Data Abstraction
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
Writing a Good Program 6. Pointers and Arrays
C++ for the MFE class at UC Berkeley Yuli Kaplunovsky MFE, MBA, MS-Tax, CFA (408)
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
1 Writing a Good Program 5. Objects and Classes in C++
C++ data types. Structs vs. Classes C++ Classes.
CS31: Introduction to Computer Science I Discussion 1A 4/2/2010 Sungwon Yang
1 Writing a Good Program 5. Objects and Classes in C++
CS31: Introduction to Computer Science I Discussion 1A 5/28/2010 Sungwon Yang
1 Introduction to C++ Programming Concept Basic C++ C++ Extension from C.
Guide To UNIX Using Linux Third Edition
C++ fundamentals.
C - Input & Output When we are saying Input that means to feed some data into program. This can be given in the form of file or from command line. C programming.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
Introduction to C++ - How C++ Evolved Most popular languages currently: COBOL, Fortran, C, C++, Java (script) C was developed in 1970s at AT&T (Richie)
Programming Languages
Introduction to C++. Overview C++? What are references Object orientation Classes Access specifiers Constructor/destructor Interface-implementation separation.
EC-241 OBJECT-ORIENTED PROGRAMMING (OOP)
Programming Languages and Paradigms Object-Oriented Programming.
C++ C++ Overview (I) What is Object Orientated Programming? Approach: Break problem into subgroups of related parts that take into account code and data;
Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Object-Oriented Programming (OOP). Implementing an OOD in Java Each class is stored in a separate file. All files must be stored in the same package.
Object Oriented Programming Elhanan Borenstein copyrights © Elhanan Borenstein.
Rossella Lau Lecture 1, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 1: Introduction What this course is about:
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
Copyright  Hannu Laine C++-programming Part 1 Hannu Laine.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
SNPL1 Woochang Lim What (Variable) + How (Function) = Object Objects are the physical and conceptual things we find in the universe around us. Object-Oriented.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 7 Structured Data and Classes.
CS1201: Programming Language 2 Classes and objects By: Nouf Aljaffan Edited by : Nouf Almunyif.
Chapter 10 Inheritance and Polymorphism
1 Simple Input/Output  C++ offers the iostream library, which defines a system of character-oriented Input/Output (I/O) using object oriented programming.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account sysadmin/account_request.cgi Need to know UNIX (Linux)
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
C/C++ Basics. Basic Concepts Basic functions of each language: Input, output, math, decision, repetition Types of errors: Syntax errors, logic errors,
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
Console Programs Console programs are programs that use text to communicate with the use and environment – printing text to screen, reading input from.
CS Class 19 Today  Practice with classes Announcements  Turn in algorithm for Project 5 in class today  Project 5 due 11/11 by midnight – .
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
EEL 3801 C++ as an Enhancement of C. EEL 3801 – Lotzi Bölöni Comments  Can be done with // at the start of the commented line.  The end-of-line terminates.
1 CSE Programming in C++. 2 Overview Sign roster list Syllabus and Course Policies Introduction to C++ About Lab 1 Fill Questionnaire.
11 Introduction to Object Oriented Programming (Continued) Cats.
1 Classes classes and objects - from object-oriented programming point of view class declaration class class_name{ data members … methods (member functions)
Copyright 2005, The Ohio State University CSE – Introduction to C++ Name: Shirish Tatikonda Time: T 3:30 PM Room: BE 394
Lecturer: Nguyen Thi Hien Software Engineering Department Home page: hienngong.wordpress.com Chapter 2: Language C++
DEF & FACTS! C + 1 = C++ C & C++ ARE MIDDLE LEVEL LANGUAGES INTRODUCTION BRIEF REVIEW OF C NEED OF C++ © arbit club cu 2010.
C is a high level language (HLL)
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Object-Oriented Programming (OOP) and C++
CS32 Discussion Section 1B Week 5 TA: Hao Yu (Cody)
Console Programs Console programs are programs that use text to communicate with the use and environment – printing text to screen, reading input from.
C++ ReviewEECE 3521 EECS 352 Data Structures and Algorithms José M. Vidal Office: 3A47.
Introduction Every program takes some data as input and generate processed data as out put . It is important to know how to provide the input data and.
Chapter 13 Introduction to C++ Language
Institute of Business & Technology (BIZTEK)
CS1201: Programming Language 2
Week 8 Lecture -3 Inheritance and Polymorphism
PRG 218 Week 5 Individual Assignment Coding: Derived Classes Please click here to buy ( (
Programming -2 برمجة -2 المحاضرة-7 Lecture-7.
الوحدة الرابعة البرمجة وصياغة حل المسائل البرمجة وأهميتها أهداف الدرس الأول مفهوم البرمجة. الفرق بين المبرمج ومستخدم البرنامج. الحاجة إلى البرامج.
Introduction to C Programming
CS1201: Programming Language 2
CECS 130 Final Exam Review Session
Presentation transcript:

SNPL1 Woochang Lim C+OOP = C++ C (non OOP)  C++ (non OOP+OOP)  Java (OOP) Object-Oriented Design  Object-Oriented Programming Programming with C++

SNPL2 Generic Program in C++ C++: Object-Oriented version of C C language + OOP = C Generic program in C = Generic program in C++ Basic statements in C can be used in C++. - Declaration of variables and functions e.g. Global variables and local variables - Flow-control statements e.g. if, if … else, while, do … while - Screen and file I/O e.g. printf, scanf, fprintf, scanf - Operators, format specifiers, escape sequences, etc. e.g. && (AND), || (OR), etc. For the C programmer, C++ is easy to use.

SNPL3 C++, Useful Programming Language // This is an example #include typedef unsigned short int USHORT int main() { USHORT Width; USHORT Length=10; USHORT Area=Width*Length; cout << “Enter the width:”; cin >> Width; cout << “Width:” << Width << “\n”; cout << “Length:” << Length << endl; cout << “Area:” << Area << “\n”; } //: Comments cout: Print output to screen cint: Input from the keyboard typedef: Define a new variable type You can use C++ as non-OOP language. When your program is not designed for the object-oriented concept, you are doing non-object-oriented programming although you are using the object-oriented languages, C++.

SNPL4 Classes Class: Member variables (data members) + Member functions (methods) class Cat { unsigned int itsAge; unsigned int itsWeight; Meow(); }; Defining an object: An object is an instance of the class. Cat Frisky; Accessing the class member Frisky.itsAge=5; Frisky.itsWeight=6; Frisky.Meow(); Declaring a class

SNPL5 Public and Private All members of classes are private by default. Private members can be accessed through the methods in the classes. Public members can be accessed by other objects class Cat { public: // Public methods unsigned int GetAge(); void SetAge(unsigned int Age); unsigned int GetWeight(); void SetWeight(unsigned int Weight); // Public member function Meow(); private: unsigned int itsAge; unsigned int itsWeight; }; Private members: Security for the programming error

SNPL6 Implementing Class Method // Implementing class method #include // Declare a class Cat class Cat { public: int GetAge(); void SetAge(int age); void Meow(); Private: int itsAge; }; // Define a public method GetAge() int Cat::GetAge() { return itsAge; }; // Define a public method SetAge() int Cat::SetAge(age) { itsAge=age; }; // Define a public method Meow() // Print out “Meow” void Cat::Meow() { cout << “Meow.\n”; }; int main() { // Define a object Frisky Cat Frisky; // Set the Frisky’s age Frisky.SetAge(5); // Call the public member function Meow() Frisky.Meow(); cout << “Frisky is a cat who is” << Frisky.GetAge() << “ years old.\n”; Frisky.Meow(); return 0; }

SNPL7 Constructor and Destructor // Implementing class method #include class Cat { public: Cat(int initialAge); // Constructor ~Cat(); // Destructor int GetAge(); void SetAge(int age); void Meow(); Private: int itsAge; }; // Constructor Cat::Cat(int initialAge) { itsAge = initialAge; }; // Destructor Cat::~Cat() { }; int Cat::GetAge() { return itsAge; }; int Cat::SetAge(age) { itsAge=age; }; void Cat::Meow() { cout << “Meow.\n”; }; int main() { Cat Frisky(5); Frisky.Meow(); cout << “Frisky is a cat who is” << Frisky.GetAge() << “ years old.\n”; Frisky.Meow(); Frisky.SetAge(7); cout << “Frisky is a cat who is” << Frisky.GetAge() << “ years old.\n”; return 0; }

SNPL8 Inheritance class animal { public: void eat(void); void sleep(void); protected: void breathe(void); }; class elephant: public animal { public: void trumpet(void); }; class animal { public: void eat(void); void sleep(void); protected: void breathe(void); }; class terrestrial { public: void walk(void); }; class elephant: public animal, public terrestrial { public: void trumpet(void); }; InheritanceMultiple Inheritance

SNPL9 Polymorphism Function overloading: Compile-time polymorphism Same function names, but various operations #include class printer_type { public: void printem(char the_char); void printem(char* the_string); void printem(int the_ASCII_code); }; void printer_type::printem(char the_char) { cout << the_char; } void printer_type::printem(int the_ASCII_code) { cout << (char) the_ASCII_code; } void printer_type::printem(char* the_string) { cout << the_string; } int main() { printer_type my_printer; my_printer.printem(97); // ASCII code for ‘a’ my_printer.printem(‘b’); // Char my_printer.printem(“c”); // String cout << endl; return 0; }

SNPL10 More Information for The OOP in C++ Books 1. S. Holzner, C++ Programming, Prentice Hall J. Liberty, SAMS Teach Yourself C++ in 21 Days: Complete Compiler Edition, SAMS Home Pages 1. C/C++ Language Guide 2. Standard C++ Library