Informatik I (D-ITET) Übungsstunde 12,
|
|
- Julia Stone
- 6 years ago
- Views:
Transcription
1 Informatik I (D-ITET) Übungsstunde 12, Hossein Shafagh shafagh@inf.ethz.ch Self-Assessment now!
2 Task 11.1 Finite rings a) struct int_7 { ; int value; //INV: 0<= value <=6 b) // POST : return value is the sum of a and b int_7 operator+ (int_7 a, int_7 b) { int help; help = a.value + b.value; int_7 r; r.value = help%7; return r;
3 Task 11.1 Finite rings c) // POST : return value is the difference of a and b int_7 operator- (int_7 a, int_7 b) { int_7 r; if (a.value >= b.value) { int help; r.value = a.value - b.value; return r; help = a.value - b.value; r.value = 7 + help; return r;
4 Task 11.2a: Complex numbers // represents complex numbers in cartesian form struct Complex { ; double real; double imag; // real part // imaginary part
5 Task 11.2a: Complex numbers // complex number output std::ostream& operator << (std::ostream& out, const Complex number) { return out << '[' << number.real << ',' << number.imag << ']'; // complex number input std::istream& operator >> (std::istream& in, Complex& number) { unsigned char f1, f2, f3; return in >> f1 >> c.r >> f2 >> c.i >> f3;
6 Task 11.2a: Complex numbers // complex number addition Complex operator + (const Complex a, const Complex b){ Complex result; result.real = a.real + b.real; result.imag = a.imag + b.imag; return result; // complex number subtraction Complex operator - (const Complex a, const Complex b){ Complex result; result.real = a.real - b.real; result.imag = a.imag - b.imag; return result; // complex number multiplication Complex operator * (const Complex a, const Complex b){ Complex result; result.real = a.real * b.real - a.imag * b.imag; result.imag = a.imag * b.real + a.real * b.imag; return result;
7 Task 11.2a: Complex numbers // complex number division Complex operator / (const Complex a, const Complex b) { Complex result; const float divisor = b.real * b.real + b.imag * b.imag; result.real = (a.real * b.real + a.imag * b.imag) / divisor; result.imag = (a.imag * b.real - a.real * b.imag) / divisor; return result; Complex operator - (const Complex c) { Complex result; result.real = - c.real; result.imag = - c.imag; return result; // complex number equality bool operator == (const Complex a, const Complex b){ return a.real == b.real && a.imag == b.imag; // complex number inequality bool operator!= (const Complex a, const Complex b){ return!(a == b);
8 1 A class for vectors class Vector { private: // already private, keyword only used to emphasize ; double x; double y;
9 1 A class for vectors (constructor) class Vector { private: // already private, keyword only used to emphasize double x; double y; ; public: // now switch to public the class initialization list Vector () : x(0), y(0) { Vector (const double _x, const double _y) : x(_x), y(_y) { Vector v1; Vector v2(3,4);
10 1 A class for vectors (getter & setter) class Vector { private: // already private, keyword only used to emphasize double x; double y; public: // now switch to public Vector () : x(0), y(0) { Vector (const double _x, const double _y) : x(_x), y(_y) { ; modify the object via this double get_x() const {return x; double get_y() const {return y; Vector a(3,4); double x = a.get_x(); double y = a.get_y();
11 1 A class for vectors (getter & setter) class Vector { private: // already private, keyword only used to emphasize double x; double y; public: // now switch to public Vector () : x(0), y(0) { Vector (const double _x, const double _y) : x(_x), y(_y) { double get_x() const {return x; double get_y() const {return y; ; void set_x(const double _x) {x = _x; void set_y(const double _y) {y = _y;
12 1 A class for vectors (Arithmetic operators) class Vector { ; // y += z, the first argument passed implicitly, in this case y Vector& operator+= (const Vector& b); Vector v1; Vector v2(3,4); v2 += v1; Vector& Vector::operator+= (const Vector& b) { x += b.get_x(); y += b.get_y(); return *this;
13 1 A class for vectors (Arithmetic operators) class Vector { ; // implicit conversion using a constructor with only x component // add to class: Vector (const double _x) : x(_x), y(0) { Vector v1; Vector v2(3,4); v2 += v1; Vector v4 = v1 + 3; // implicit conversion Vector operator+ (const Vector& a, const Vector& b) { Vector res = a; res += b; return res;
14 1 A class for vectors (output) #include <iostream> std::ostream& operator<< (std::ostream& out, const Vector v) { return out << v.get_x() <<, << v.get_y(); Vector v1; Vector v2(3,4); v2 += v1; Vector v4 = v1 + 3; // implicit conversion const Vector& v5 = v1; std::cout << v1 << "\n" << v5 << "\n";
15 2 Dynamically allocated memory int* dyn_int = new int (3); // constructed with value 3 int n =...; int* dyn_int_range = new int[n]; delete dyn_int; // deconstruct dynamic variable dyn_int = 0; delete[] dyn_int_range; // deconstruct dynamic range dyn_int_range = 0;
16 2 Dynamically allocated memory //... int i; std::cin >> i; int* mem = new int[i]; // length of input for (int j = 0; j < i; ++j) std::cin >> *(mem + j); for (int j = i-1; j >= 0; --j) std::cout << *(mem + j) << " "; delete[] mem; mem = 0; //...
17 3 Dynamic Data Types stack s1; s1.push(1); s1.push(3); s1.push(2); stack s2(s1);
18 3 Dynamic Data Types stack::stack(const stack& s) : top_node (0) { copy(s.top_node, top_node); void stack::copy(const linked_list_node* from, linked_list_node*& to) { assert (to == 0); if (from!= 0) { to = new linked_list_node(from->key); copy(from->next, to->next);
19 3 Dynamic Data Types stack s2; s2.push(4); s2.push(9); s2 = s1; // s1 as before
20 3 Dynamic Data Types stack s2; s2.push(4); s2.push(9); s2 = s1; // s1 as before // overwrite operator= // re-use copy function as before and afterwards free memory void stack::clear(linked_list_node* from) { if (from!= 0) { clear (from->next); delete from;
21 3 Dynamic Data Types stack s2; s2.push(4); s2.push(9); s2 = s1; // s1 as before s1 = s1; // self-assignment fails! stack& stack::operator= (const stack& s) { if (top_node!= s.top_node) { // test for self-assignment clear(top_node); top_node = 0; // fix dangling pointer copy(s.top_node, top_node); return *this;
22 Übungsblatt 12 Problem Understanding structs and classes Problem Averager Special restriction: Must use provided main function Problem Queue (dynamic data types) Special restriction: Must use provided template (no simplifcaton allowed) Must implement a dynamic data type, reuse of existing dynamic container (e.g., vector) is not allowed. Similar to stack as dynamic structure enqueue, dequeue, is_empty output operator operator<< [ ] copy constructor, assignment operator, destructor (rule of three)
23
Informatik I (D-ITET) Übungsstunde 11, Hossein Shafagh
Informatik I (D-ITET) Übungsstunde 11, 4.12.2017 Hossein Shafagh shafagh@inf.ethz.ch Problem 10.1. Recursive Function Analysis Problem 10.1. Recursive Function Analysis (a) bool f (const int n) { if (n
More informationCSC 330 Object Oriented Programming. Operator Overloading Friend Functions & Forms
CSC 330 Object Oriented Programming Operator Overloading Friend Functions & Forms 1 Restrictions on Operator Overloading Most of C++ s operators can be overloaded. Operators that can be overloaded + -
More information19. Classes. Encapsulation: public / private. Member Functions: Declaration. Member Functions: Call. class rational { int n; int d; // INV: d!
Encapsulation: public / private 9. Classes Classes, Member Functions, Constructors, Stack, Linked List, Dynamic Memory, Copy-Constructor, Assignment Operator, Concept Dynamic Datatype class rational int
More information17. Classes. Encapsulation: public / private. Member Functions: Declaration. Member Functions: Call. class rational { int n; int d; // INV: d!
Encapsulation: public / private 7. Classes Classes, Member Functions, Constructors, Stack, Linked List, Dynamic Memory, Copy-Constructor, Assignment Operator, Concept Dynamic Datatype class rational int
More informationInformatik I (D-ITET) Übungsstunde 6, Hossein Shafagh
Informatik I (D-ITET) Übungsstunde 6, 30.10.2017 Hossein Shafagh shafagh@inf.ethz.ch Self-Assessment Self-Assessment 1 Typen und Werte int i = 11; unsigned int u = 12; double d = 2.0; int j = 0; double
More informationInformatik I (D-ITET) Übungsstunde 5, Hossein Shafagh
Informatik I (D-ITET) Übungsstunde 5, 23.10.2017 Hossein Shafagh shafagh@inf.ethz.ch Übungsblatt 4 Problem 4.1. Loop mix-up // Fakultät unsigned int n; std::cin >> n; unsigned int f = 1; if(n!= 0) { do
More informationWhat is a Structure? related data items. Examples: n Used for handling a group of logically
Structures 1 What is a Structure? n Used for handling a group of logically related data items Examples: n Student name, roll number, and marks n Real part and complex part of a complex number n Helps in
More informationInformatik I (D-ITET) Übungsstunde 9, Hossein Shafagh
Informatik I (D-ITET) Übungsstunde 9, 20.11.2017 Hossein Shafagh shafagh@inf.ethz.ch Self-Assessment III 1) Characters: FILO - 2P for the completely correct answer - 0P otherwise 2) Pointers Self-Assessment
More informationProgramming & Data Structure
Structure Programming & Data Structure CS 11002 Partha Bhowmick http://cse.iitkgp.ac.in/ pb CSE Department IIT Kharagpur Spring 2012-2013 Structure Why A Math Puzzle Subdivide an integer square by a minimum
More information16. Structs and Classes I
Calculating with Rational Numbers 16. Structs and Classes I Rational Numbers, Struct Definition, Overlading Functions and Operators, Const-References, Encapsulation Rational numbers (Q) are of the form
More information21. Dynamic Datatypes and Memory Management
21. Dynamic Datatypes and Memory Management 695 Problem 696 Last week: dynamic data type Have allocated dynamic memory, but not released it again. In particular: no functions to remove elements from llvec.
More informationCS11 Intro C++ Spring 2018 Lecture 3
CS11 Intro C++ Spring 2018 Lecture 3 C++ File I/O We have already seen C++ stream I/O #include cout > name; cout
More informationStructures. 21 July 2009 Programming and Data Structure 1
Structures 21 July 2009 Programming and Data Structure 1 What is a Structure? It is a convenient tool for handling a group of logically related data items. Student name, roll number, and marks Real part
More information21. Dynamic Datatypes and Memory Management
Problem 21. Dynamic Datatypes and Memory Management Last week: dynamic data type Have allocated dynamic memory, but not released it again. In particular: no functions to remove elements from llvec. Today:
More information17. Classes. Overloading Functions. Operator Overloading. Function Overloading. operatorop
Overloading Functions 17. Classes Overloading Functions and Operators, Encapsulation, Classes, Member Functions, Constructors Functions can be addressed by name in a scope It is even possible to declare
More informationINFORMATIK 1 am D-ITET
INFORMATIK 1 am D-ITET Eine Einführung mit C++ Kurzzusammenfassung zur Vorlesung 252-0835-00 Herbstsemester 2017, ETH Zürich Felix Friedrich und Bernd Gärtner 2 The first program and the C++ syntax and
More informationPIC10B/1 Winter 2014 Exam I Study Guide
PIC10B/1 Winter 2014 Exam I Study Guide Suggested Study Order: 1. Lecture Notes (Lectures 1-8 inclusive) 2. Examples/Homework 3. Textbook The midterm will test 1. Your ability to read a program and understand
More informationOperator Overloading in C++ Systems Programming
Operator Overloading in C++ Systems Programming Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. Global Functions Overloading
More informationChapter 18 - C++ Operator Overloading
Chapter 18 - C++ Operator Overloading Outline 18.1 Introduction 18.2 Fundamentals of Operator Overloading 18.3 Restrictions on Operator Overloading 18.4 Operator Functions as Class Members vs. as friend
More informationThe University of Nottingham
The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER 2011-2012 G52CPP C++ Programming Examination Time allowed TWO hours Candidates may complete the front cover of
More informationCOMP 2355 Introduction to Systems Programming
COMP 2355 Introduction to Systems Programming Christian Grothoff christian@grothoff.org http://grothoff.org/christian/ 1 Today Class syntax, Constructors, Destructors Static methods Inheritance, Abstract
More informationdouble d0, d1, d2, d3; double * dp = new double[4]; double da[4];
All multiple choice questions are equally weighted. You can generally assume that code shown in the questions is intended to be syntactically correct, unless something in the question or one of the answers
More informationClasses. Christian Schumacher, Info1 D-MAVT 2013
Classes Christian Schumacher, chschuma@inf.ethz.ch Info1 D-MAVT 2013 Object-Oriented Programming Defining and using classes Constructors & destructors Operators friend, this, const Example Student management
More informationIntroduction to C++ Systems Programming
Introduction to C++ Systems Programming Introduction to C++ Syntax differences between C and C++ A Simple C++ Example C++ Input/Output C++ Libraries C++ Header Files Another Simple C++ Example Inline Functions
More informationAbstraction and Encapsulation. Benefits of Abstraction & Encapsulation. Concrete Types. Using Typedefs to streamline classes.
Classes II: Type Conversion,, For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Abstraction and Encapsulation Abstraction: Separation of interface from
More informationOutline. User-dened types Categories. Constructors. Constructors. 4. Classes. Concrete classes. Default constructor. Default constructor
Outline EDAF50 C++ Programming 4. Classes Sven Gestegård Robertz Computer Science, LTH 2018 1 Classes the pointer this const for objects and members Copying objects friend inline 4. Classes 2/1 User-dened
More information3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.
3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.
More informationIntroduction to Programming
Introduction to Programming session 6 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Spring 2011 These slides are created using Deitel s slides Sharif University of Technology Outlines
More informationOBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe
OBJECT ORIENTED PROGRAMMING USING C++ CSCI 5448- Object Oriented Analysis and Design By Manali Torpe Fundamentals of OOP Class Object Encapsulation Abstraction Inheritance Polymorphism Reusability C++
More informationCMSC 341 Lecture 6 Templates, Stacks & Queues. Based on slides by Shawn Lupoli & Katherine Gibson at UMBC
CMSC 341 Lecture 6 Templates, Stacks & Queues Based on slides by Shawn Lupoli & Katherine Gibson at UMBC Today s Topics Data types in C++ Overloading functions Templates How to implement them Possible
More informationObject-Oriented Programming
- oriented - iuliana@cs.ubbcluj.ro Babes-Bolyai University 2018 1 / 56 Overview - oriented 1 2 -oriented 3 4 5 6 7 8 Static and friend elements 9 Summary 2 / 56 I - oriented was initially created by Bjarne
More informationAn Introduction to C++
An Introduction to C++ Introduction to C++ C++ classes C++ class details To create a complex type in C In the.h file Define structs to store data Declare function prototypes The.h file serves as the interface
More information8. Floating-point Numbers II
Floating-point Number Systems A Floating-point number system is defined by the four natural numbers: 8. Floating-point Numbers II Floating-point Number Systems; IEEE Standard; Limits of Floating-point
More informationarrays review arrays and memory arrays: character array example cis15 advanced programming techniques, using c++ summer 2008 lecture # V.
topics: arrays pointers arrays of objects resources: cis15 advanced programming techniques, using c++ summer 2008 lecture # V.1 some of this lecture is covered in parts of Pohl, chapter 3 arrays review
More informationChapter7 Expression and Assignment Statement. Introduction
Chapter7 Expression and Assignment Statement Arithmetic Expressions Overloaded Operators Boolean Expressions Short-Circuit Evaluation Assignment Statements Mixed-Mode Assignment Introduction Fundamental
More informationIntroduction to the C programming language
Introduction to the C programming language From C to C++: Stack and Queue Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 23, 2010 Outline 1 From struct to classes
More informationShort Notes of CS201
#includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system
More informationC and C++ 7. Exceptions Templates. Alan Mycroft
C and C++ 7. Exceptions Templates Alan Mycroft University of Cambridge (heavily based on previous years notes thanks to Alastair Beresford and Andrew Moore) Michaelmas Term 2013 2014 1 / 20 Exceptions
More informationC++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay
C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming
More informationChapter 12 - Templates
Chapter 12 - Templates O utline 12.1 Introd uction 12.2 Function Te m plate s 12.3 Ove rload ing Te m plate Functions 12.4 Class Te m p late s 12.5 Class Te m plate s and Non-type Param e te rs 12.6 Te
More informationCS201 - Introduction to Programming Glossary By
CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with
More informationIntroduction to the C programming language
Introduction to the C programming language From C to C++: Stack and Queue Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 23, 2010 Outline 1 From struct to classes
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 11 October 3, 2018 CPSC 427, Lecture 11, October 3, 2018 1/24 Copying and Assignment Custody of Objects Move Semantics CPSC 427, Lecture
More informationLogistics. Templates. Plan for today. Logistics. A quick intro to Templates. A quick intro to Templates. Project. Questions? Introduction to Templates
Logistics Templates Project Part 1 (clock and design) due Sunday, Sept 25 th Start thinking about partners for Parts 2-3 Questions? Logistics Important date: THURSDAY is Exam 1 Will cover: C++ environment
More informationExample Final Questions Instructions
Example Final Questions Instructions This exam paper contains a set of sample final exam questions. It is for practice purposes only. You ll most likely need longer than three hours to answer all the questions.
More informationl Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)
Final Exam Exercises Chapters 1-7 + 11 Write C++ code to: l Determine if a number is odd or even CS 2308 Fall 2016 Jill Seaman l Determine if a number/character is in a range - 1 to 10 (inclusive) - between
More informationUser Defined Data: Product Constructor
PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 1 User Defined Data: Product Constructor PDS: CS 11002 Computer Sc & Engg: IIT Kharagpur 2 Built-in Data Types Built-in data types of C language are int,
More informationIntroduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.
Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p. 9 Self-Test Exercises p. 11 History Note p. 12 Programming and
More informationCS 33. Introduction to C. Part 4. CS33 Intro to Computer Systems IV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.
CS 33 Introduction to C Part 4 CS33 Intro to Computer Systems IV 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. Lifetime int count; int main() { func();... func(); // what s printed by func?
More informationCPSC 427: Object-Oriented Programming
CPSC 427: Object-Oriented Programming Michael J. Fischer Lecture 7 September 21, 2016 CPSC 427, Lecture 7 1/21 Brackets Example (continued) Storage Management CPSC 427, Lecture 7 2/21 Brackets Example
More informationpointers & references
pointers & references 1-22-2013 Inline Functions References & Pointers Arrays & Vectors HW#1 posted due: today Quiz Thursday, 1/24 // point.h #ifndef POINT_H_ #define POINT_H_ #include using
More informationOperator Overloading
Operator Overloading Introduction Operator overloading Enabling C++ s operators to work with class objects Using traditional operators with user-defined objects Requires great care; when overloading is
More information04-19 Discussion Notes
04-19 Discussion Notes PIC 10B Spring 2018 1 Constructors and Destructors 1.1 Copy Constructor The copy constructor should copy data. However, it s not this simple, and we need to make a distinction here
More informationObject-Oriented Programming
Object-Oriented Programming Section 3: Classes and inheritance (1) Piotr Mielecki, Ph. D. piotr.mielecki@pwr.edu.pl pmielecki@gmail.com Class vs. structure declaration Inheritance and access specifiers
More informationObject Oriented Programming COP3330 / CGS5409
Object Oriented Programming COP3330 / CGS5409 Intro to Data Structures Vectors Linked Lists Queues Stacks C++ has some built-in methods of storing compound data in useful ways, like arrays and structs.
More informationData Structures (INE2011)
Data Structures (INE2011) Electronics and Communication Engineering Hanyang University Haewoon Nam Lecture 4 1 Stacks Insertion and deletion are made at one end () Last input first output (LIFO) Inserting
More informationCS24 Week 4 Lecture 2
CS24 Week 4 Lecture 2 Kyle Dewey Overview Linked Lists Stacks Queues Linked Lists Linked Lists Idea: have each chunk (called a node) keep track of both a list element and another chunk Need to keep track
More informationFast Introduction to Object Oriented Programming and C++
Fast Introduction to Object Oriented Programming and C++ Daniel G. Aliaga Note: a compilation of slides from Jacques de Wet, Ohio State University, Chad Willwerth, and Daniel Aliaga. Outline Programming
More informationeingebetteter Systeme
Praktikum: Entwicklung interaktiver eingebetteter Systeme C++-Tutorial (falk@cs.fau.de) 1 Agenda Classes Pointers and References Functions and Methods Function and Operator Overloading Template Classes
More informationEXP54-CPP. Do not access an object outside of its lifetime
EXP54-CPP. Do not access an object outside of its lifetime Every object has a lifetime in which it can be used in a well-defined manner. The lifetime of an object begins when sufficient, properly aligned
More informationObject-Oriented Programming for Scientific Computing
Object-Oriented Programming for Scientific Computing Dynamic Memory Management Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de 2. Mai 2017
More informationAIMS Embedded Systems Programming MT 2017
AIMS Embedded Systems Programming MT 2017 Object-Oriented Programming with C++ Daniel Kroening University of Oxford, Computer Science Department Version 1.0, 2014 Outline Classes and Objects Constructors
More informationG52CPP C++ Programming Lecture 13
G52CPP C++ Programming Lecture 13 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last lecture Function pointers Arrays of function pointers Virtual and non-virtual functions vtable and
More informationCMSC 341 Lecture 6 STL, Stacks, & Queues. Based on slides by Lupoli, Dixon & Gibson at UMBC
CMSC 341 Lecture 6 STL, Stacks, & Queues Based on slides by Lupoli, Dixon & Gibson at UMBC Templates 2 Common Uses for Templates Some common algorithms that easily lend themselves to templates: Swap what
More informationChapter 15 - C++ As A "Better C"
Chapter 15 - C++ As A "Better C" Outline 15.1 Introduction 15.2 C++ 15.3 A Simple Program: Adding Two Integers 15.4 C++ Standard Library 15.5 Header Files 15.6 Inline Functions 15.7 References and Reference
More informationOutline. 1 About the course
Outline EDAF50 C++ Programming 1. Introduction 1 About the course Sven Gestegård Robertz Computer Science, LTH 2018 2 Presentation of C++ History Introduction Data types and variables 1. Introduction 2/1
More informationCSC 330 Object-Oriented Programming. Exception Handling CSC 330
Object-Oriented Programming Exception Handling 1 C++ Exception Handling Topics Exception Handling C++ Exception Handling Basics Throwing and Catching Exceptions Constructors, Destructors and Exceptions
More informationCS242 COMPUTER PROGRAMMING
CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing
More informationEvolution of Programming Languages
Evolution of Programming Languages 40's machine level raw binary 50's assembly language names for instructions and addresses very specific to each machine 60's high-level languages: Fortran, Cobol, Algol,
More informationC++ Modern and Lucid C++ for Professional Programmers
Informatik C++ Modern and Lucid C++ for Professional Programmers part 9 Prof. Peter Sommerlad Institutsleiter IFS Institute for Software Rapperswil, HS 2015 Functors and Parameterizing STL Functors, Lambdas,
More informationCommon Misunderstandings from Exam 1 Material
Common Misunderstandings from Exam 1 Material Kyle Dewey Stack and Heap Allocation with Pointers char c = c ; char* p1 = malloc(sizeof(char)); char** p2 = &p1; Where is c allocated? Where is p1 itself
More informationObject-Oriented Programming. Lecture 2 Dr Piotr Cybula
Object-Oriented Programming Lecture 2 Dr Piotr Cybula Encapsulation : data protection code safety and independence better team support with the code separation without «giving
More informationChapter-8 DATA TYPES. Introduction. Variable:
Chapter-8 DATA TYPES Introduction To understand any programming languages we need to first understand the elementary concepts which form the building block of that program. The basic building blocks include
More informationScott Gibson. Pointers & Dynamic Memory. Pre & Co Requisites. Random Access Memory. Data Types. Atomic Type Sizes
Scott Gibson Pointers & Dynamic Memory Lecture #1 Office: LAH 103 Email: sgibson@brookdalecc.edu sgib@optonline.net Web: www.brookdalecc.edu/fac/cos/sgibson Phone: (732) 224 2285 1 2 Pre & Co Requisites
More informationLecture 8: Object-Oriented Programming (OOP) EE3490E: Programming S1 2017/2018 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lecture 8: Object-Oriented Programming (OOP) 1 Introduction to C++ 2 Overview Additional features compared to C: Object-oriented programming (OOP) Generic programming (template) Many other small changes
More information11. Reference Types. Swap! Reference Types: Definition. Reference Types
Swap! 11. Reference Types Reference Types: Definition and Initialization, Pass By Value, Pass by Reference, Temporary Objects, Constants, Const-References // POST: values of x and y are exchanged void
More informationPIC 10A Objects/Classes
PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous
More informationIntroduction. W8.2 Operator Overloading
W8.2 Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. as friend Functions Overloading Stream Insertion and Extraction
More informationCS304 Object Oriented Programming Final Term
1. Which of the following is the way to extract common behaviour and attributes from the given classes and make a separate class of those common behaviours and attributes? Generalization (pg 29) Sub-typing
More informationCSE030 Fall 2012 Final Exam Friday, December 14, PM
CSE030 Fall 2012 Final Exam Friday, December 14, 2012 3-6PM Write your name here and at the top of each page! Name: Select your lab session: Tuesdays Thursdays Paper. If you have any questions or need
More informationCS201 Some Important Definitions
CS201 Some Important Definitions For Viva Preparation 1. What is a program? A program is a precise sequence of steps to solve a particular problem. 2. What is a class? We write a C++ program using data
More informationCSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 19 Introduction to C++ C++ C++ is an enormous language: All of C Classes and objects (kind of like Java, some crucial differences) Many
More informationObject oriented programming
Exercises 6 Version 1.0, 21 March, 2017 Table of Contents 1. Operators overloading....................................................... 1 1.1. Example 1..............................................................
More informationCHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object
CHAPTER 1 Introduction to Computers and Programming 1 1.1 Why Program? 1 1.2 Computer Systems: Hardware and Software 2 1.3 Programs and Programming Languages 8 1.4 What is a Program Made of? 14 1.5 Input,
More informationChapter 18: Stacks And Queues
Chapter 18: Stacks And Queues 18.1 Introduction to the Stack ADT Introduction to the Stack ADT Stack: a LIFO (last in, first out) data structure Examples: plates in a cafeteria return addresses for function
More informationCSC1322 Object-Oriented Programming Concepts
CSC1322 Object-Oriented Programming Concepts Instructor: Yukong Zhang February 18, 2016 Fundamental Concepts: The following is a summary of the fundamental concepts of object-oriented programming in C++.
More informationC++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator
C++ Addendum: Inheritance of Special Member Functions Constructors Destructor Construction and Destruction Order Assignment Operator What s s Not Inherited? The following methods are not inherited: Constructors
More informationAnd Even More and More C++ Fundamentals of Computer Science
And Even More and More C++ Fundamentals of Computer Science Outline C++ Classes Special Members Friendship Classes are an expanded version of data structures (structs) Like structs, the hold data members
More information17. Classes. Encapsulation, Classes, Member Functions, Constructors
556 17. Classes Encapsulation, Classes, Member Functions, Constructors A new Type with Functionality... 557 struct rational { int n; int d; // INV: d!= 0 // POST: return value is the sum of a and b rational
More informationW8.2 Operator Overloading
1 W8.2 Operator Overloading Fundamentals of Operator Overloading Restrictions on Operator Overloading Operator Functions as Class Members vs. as friend Functions Overloading Stream Insertion and Extraction
More informationRecharge (int, int, int); //constructor declared void disply();
Constructor and destructors in C++ Constructor Constructor is a special member function of the class which is invoked automatically when new object is created. The purpose of constructor is to initialize
More information1.00 Lecture 5. Objects
All code produced with Java software. Java is a trademark of Sun Microsystems Inc. 1.00 Lecture 5 Java Classes and Objects Objects Objects are things 8.01 defined matter as stuff We decompose programming
More informationCOMP6771 Advanced C++ Programming
1. COMP6771 Advanced C++ Programming Week 4 Part One: (continued) and 2016 www.cse.unsw.edu.au/ cs6771 2. Inline Constructors, Accessors and Mutators Question (from 2015): In the week 3 examples, constructors
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 22 March 14 th, 2016 Object Oriented Programming in Java Java Bootcamp tonight Announcements Monday, March 14 from 6-8pm in Levine 101 (Wu & Chen)
More informationWe look back... #include <iostream> #include <vector>
165 6. C++ advanced (I) Repetition: vectors, pointers and iterators, range for, keyword auto, a class for vectors, subscript-operator, move-construction, iterators We look back... #include #include
More informationProgramming in C and C++
Programming in C and C++ 6. C++: Operators, Inheritance, Virtual Methods Dr. Neel Krishnaswami University of Cambridge (based on notes from and with thanks to Anil Madhavapeddy, Alan Mycroft, Alastair
More informationCS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0)
CS11001/CS11002 Programming and Data Structures (PDS) (Theory: 3-0-0) Class Teacher: Pralay Mitra Jayanta Mukhopadhyay Soumya K Ghosh Department of Computer Science and Engineering Indian Institute of
More informationChapter 18: Stacks And Queues. Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 18: Stacks And Queues Copyright 2009 Pearson Education, Inc. Copyright Publishing as Pearson 2009 Addison-Wesley Pearson Education, Inc. Publishing as Pearson Addison-Wesley 18.1 Introduction to
More informationDerived and abstract data types. TDT4205 Lecture 15
1 Derived and abstract data types TDT4205 Lecture 15 2 Where we were We ve looked at static semantics for primitive types and how it relates to type checking We ve hinted at derived types using a multidimensional
More informationWentworth Institute of Technology COMP201 Computer Science II Spring 2015 Derbinsky. Stacks and Queues. Lecture 11.
Lecture 11 1 More Data Structures In this lecture we will use a linked list to implement two abstract data types (ADT) An ADT provides the interface, or what a data structure does We can then use code
More information