EE219 Object Oriented Programming I Repeat Solutions for 2005/2006
|
|
- Charles Rodgers
- 6 years ago
- Views:
Transcription
1 EE219 Object Oriented Programming I Repeat Solutions for 2005/2006 Q1(a) Corrected Code: #include <iostream> using namespace std; class Question1 int a,b; public: Question1(); Question1(int, int); virtual void increment(int); virtual void display(); virtual ~Question1(); ; Question1::Question1(): a(1), b(2) Question1::Question1(int x,int y): a(x), b(y) Question1::~Question1() cout << "(" << a << "," << b << ") destroyed" << endl; void Question1::display() cout << "a has value:" << a << endl; cout << "b has value:" << b << endl; void Question1::increment(int amt = 1) a+=amt; b+=amt; int main() Question1 q1; q1.increment(); q1.display(); q1 = Question1(); q1.increment(5); q1.display(); return 0; No void on line 13 as destructor cannot return anything Line 19 cout missing a << Line 01 should include iostream not string Lines 9 and 10 constructors should not be virtual Line 39 main should return an int, not true (may not give compiler error) Lines 16 and 17 missing empty constructor implementation Line 4 should have class keyword instead Line 2 should be using namespace std; [16 marks 2 each]
2 The output from the code should be: a has value:2 b has value:3 (1,2) destroyed a has value:6 b has value:7 (6,7) destroyed [9 marks] Need to understand when destructors are called 2 marks each Need to understand output due to constructor 1 mark each Need to understand assignment of new object 2 marks [10 possible] [9 marks total] Q2(a) #include<iostream> #include<string> using namespace std; class Person string name; string address; public: Person(string, string); virtual void display(); ; class Staff: public Person string id; int phonenumber; public: Staff(Person, string, int); virtual string getid(); virtual int getphonenumber(); virtual void display(); ; Person::Person(string aname, string anaddress): name(aname), address (anaddress) void Person::display() cout << "Person has name: " << name << endl; cout << "And address: " << address << endl; Staff::Staff(Person p, string anid, int aphone): Person(p), id(anid), phonenumber(aphone) string Staff::getID() return id;
3 int Staff::getPhoneNumber() return phonenumber; void Staff::display() Person::display(); cout << "And ID: " << id << endl; cout << "And Phone Number: " << phonenumber << endl; int main() Staff s(person("derek", "DCU"), "12345", 5355); s.display(); system("pause"); return 0; [19 marks total] [2-3 for each method and main, except 4 for staff display and 4 for main] Q2(b) An abstract class is a class that is incomplete, in that it describes a set of operations, but is missing the actual implementation of these operations. Abstract classes: Cannot be instantiated. So, can only be used through inheritance. To make the Person class abstract we could write: virtual void display() = 0; (any method would do, even adding one) You would then have to write a full implementation for display() in the child class. e.g. void Staff::display() cout << "Person has name: " << name << endl; cout << "And address: " << address << endl; cout << "And ID: " << id << endl; cout << "And Phone Number: " << phonenumber << endl; Importantly, name and address would have to be specified as protected. You would make a class abstract to impose a behaviour on the child classes. You may also wish to prevent a class from being instantiated. [6 marks] Q3(a) Since the responsibility for the initialisation of the class is in the hands of the programmer of the class, the responsibility for the destruction of the class should also be the responsibility of the programmer. In C++ we can write a destructor for a class that performs some clean-up operations and even notifications. To define a destructor for a class the ~ symbol is used in front of the class name, so for the Account class you would use:
4 class Account // state definition public: Account(int thenumber, float thebalance); virtual ~Account(); //destructor ; // other member methods here. Account::~Account() cout << "Account object being destroyed!" << endl; Note: A similar destructor is also written for the CurrentAccount class. The destructor must take no parameters and cannot return a result. A constructor cannot be virtual, but a destructor can (and should) be virtual (we will discuss this later). When is a destructor called? It is not invoked explicitly. It is called when an object goes out of scope. int main() CurrentAccount b = CurrentAccount(50.0, 12345, 200.0); b.display(); What would happen? Since CurrentAccount is a child of the Account class then destruction of an object of the CurrentAccount object will result in the Account destructor being called. The CurrentAccount destructor followed by the Account destructor will be called, just after the main() method ended, and just before the application ran to completion. If you don't declare a destructor, C++ generates a default destructor, that frees up the memory of the object. This is suitable for most classes; however, a destructor may be required for specific actions: Q3(b) Notifying other objects about an imminent destruction. Closing open files, database connections, sockets etc. Freeing dynamically allocated data. If an object does not free data that is dynamically allocated, then that memory will remain locked until the application terminates. [12 marks] So to write a simple method that returns a single value we can use:
5 1 2 // Using Methods 3 4 #include<iostream> 5 using namespace std; 6 7 float addinterest(float val, float rate) 8 9 return val + (val * (rate/100)); int main() float balance = 5000; 15 float irate = 5.0; balance = addinterest(balance, irate); cout << "After interest your balance is " 20 << balance << " Euro." << endl; The source code for this is in Functions1.cpp The method is defined to return a float value, so it is required to do so. In this case the return value will be the new balance. The return keyword defines the value to return. Since the return type has been specified as float the return value must also be of float type. The return value of the method is assigned to the left-hand side of the =. In this case the balance value has been modified to update the balance in the main() method. This will result in the output: After interest your balance is 5250 Euro. Some points about methods: If a method has a return type then it must return a value! The void keyword implies that no return value is expected. void can also mean "no type" in the case of pointers (discussed later). int is the default return type in C++. char* is the string type (pointer to characters). In C if we specified a function with no parameters, e.g. void somefunction() it actually meant that there was an undeterminded number of parameters, thus disabling type checking. In C++ this means that there are zero parameters. The previous code segment passed values to the method using pass by value. In this case you are really passing the value of the variables balance and irate, so in this case the numbers 5000 and 5.0. It is only possible to have one return value when passing by value. If we wish to have multiple return values, or wish to modify the source then we can pass by reference.
6 This example is the same as the previous example except this time we are passing by reference: 1 2 // Using Methods (with Pass by reference) 3 4 #include<iostream> 5 using namespace std; 6 7 void addinterest(float &val, float rate) 8 9 val = val + (val * (rate/100)); int main() float balance = 5000; 15 float irate = 5.0; addinterest(balance,irate); cout << "After interest your balance is " 20 << balance << " Euro." << endl; The source code for this is in Functions2.cpp The method is defined not to return a value, so the return type is set as void. This is to prove that the pass by reference actually works. You will notice that the first parameter val has been changed so that it has an & in front of it. This is notation to signify that the val parameter is to be passed by reference, not by value. You will notice the return keyword is not used, as the return type is set to void. The value is not returned, rather it is modified directly. So when the value of val is modified in the addinterest() this modifies the value of balance directly. The balance is passed in the same way, but the method receives the reference in this case, not the value. The balance variable has been updated by the method and the new value is displayed as below This will result in the output: After interest your balance is 5250 Euro. So the output is exactly the same. Passing by reference is like passing a copy of the name of the variable to the method. [13 marks] [not same level of detail required any example will suffice]
7 Q4(a) Namespaces allow the programmer to define a region that is limited in scope. When writing C++ applications we can make it explicit that we are using the standard namespace by a "using directive": using namespace std; // i.e. I want to use the declarations and // definitions in the "Standard Library" // namespace at the beginning of our code segments, however this can be considered poor practice in certain circumstances as the entire contents of the namespace are included. The alternative is to make it explicit that we were calling the standard cout output stream by typing: std::cout << "Hello World!" << std::endl; which states that the cout and endl that we wish to use are both defined in the std standard library. It is possible to include the exact namespace member to be included by a "using declaration":: using std::cout; would allow us to use cout without including all of the names in the std namespace. Packages are groups of similar classes, that can be, but are not necessarily related to each other through an inheritance structure. Packages are classes organised into directories on a file system. Packages are '.' separated words, where the package refers to the directory that the class files are in. For example java.awt (the directory /java/awt/ is a package that stores the classes for creating buttons, textfields, etc. A package can also contain more packages in a subfolder. For example, java.awt.event contains classes for events, within the awt package. Use the import keyword to load in packages. Multiple classes can be loaded using the * character. So, for example,import java.awt.*; imports all the classes in the awt package, but please note, it does not include classes in the sub-packages, so, you must explicitly import java.awt.event.*;. In a source file, if no package name is defined on an import e.g. import SomeClass; then it is assumed that the class SomeClass is in the same directory as the source file. Packages are very similar to a combination of C++ namespaces and includes, only a lot easier to use. Packages and Namespaces can be nested. There is a friendly default access specifier in java that shares across packages. There is no such access specifier in C++. Q4(b) public class Reverser private String reversedstring; [10 marks]
8 public Reverser(String s) int len = s.length(); char[] revtext = new char[len]; for (int i=0; i<len; i++) revtext[i] = s.charat(len-i-1); reversedstring = new String(revText); public String getreversedstring() return reversedstring; [10 marks] [5 for structure, 5 for reverse code] Q4(c) By default, every class extends the Object class, even if you don't extend any class. The Object class provides methods that are inherited by all Java classes, such as equals(), getclass(), tostring() and more. The Class class (called class descriptors) are automatically created and associated with the objects to which they refer. For example, the getname() and tostring() methods return the String containing the name of the class or interface. We could use this to compare the classes of objects. [5 marks] Q5(a) // A Button Events Application import java.applet.*; import java.awt.*; import java.awt.event.*; public class Question5 extends Applet implements ActionListener private Button button1, button2; private TextField status; public void init()
9 status = new TextField(20); this.button1 = new Button("Upper case"); this.button2 = new Button("Lower case"); this.button1.addactionlistener(this); this.button2.addactionlistener(this); this.add(button1); this.add(status); this.add(button2); public void actionperformed(actionevent e) if (e.getactioncommand().equals("upper case")) status.settext( status.gettext().touppercase() ); else if (e.getactioncommand().equals("lower case")) status.settext( status.gettext().tolowercase() ); HTML page: <title> Question 5 Page </title> <hr> <applet code=question5.class width=200 height=200> </applet> <hr> Q5(b) [20 marks] [2 marks for HTML page, 5 marks for layout, 5 marks for events, 5 marks for functionality, 3 mark for states etc] Java does not suffer from the memory leaks like C++, due to the addition of an embedded Garbage Collector (GC) and carefully structured reference counting. The GC can be run in three ways: The system calls the GC when memory is low. The system calls the GC when the CPU is idle. The user can call the GC directly, but since the GC runs as a thread in a threaded environment, there is no guarantee that it will run immediately. [5 marks]
EE219 - Semester /2009 Solutions Page 1 of 10
EE219 Object Oriented Programming I (2008/2009) SEMESTER 1 SOLUTIONS Q1(a) Corrected code is: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
More informationObject-Oriented Programming EE219 Repeat 2004/2005 Page 1 of 8
REPEAT EXAMINATIONS SOLUTIONS 2004/2005 MODULE: Object-Oriented Programming for Engineers EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Telecommunications Engineering B.Eng. in Digital Media
More informationEE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS
Q1(a) Corrected code is: EE219 Object Oriented Programming I (2007/2008) REPEAT SOLUTIONS 00 #include 01 using namespace std; 02 03 class Shape 04 05 protected: 06 float posx, posy; 07 public:
More informationEE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS
Q1(a) Corrected code is: #include using namespace std; class Shape protected: int x, y; public: Shape(int, int); ; EE219 Object Oriented Programming I (2006/2007) SEMESTER 1 SOLUTIONS Shape::Shape(int
More informationEE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS
Q1(a) Corrected code is: EE219 Object Oriented Programming I (2005/2006) SEMESTER 1 SOLUTIONS 01 #include 02 using namespace std; 03 04 class Question1 05 06 int a,b,*p; 07 08 public: 09 Question1(int
More informationSEMESTER ONE EXAMINATIONS SOLUTIONS 2003/2004
SEMESTER ONE EXAMINATIONS SOLUTIONS 2003/2004 MODULE: Object-Oriented Programming for Engineers EE219 COURSE: B.Eng. in Electronic Engineering B.Eng. in Telecommunications Engineering B.Eng. in Digital
More informationAssumptions. History
Assumptions A Brief Introduction to Java for C++ Programmers: Part 1 ENGI 5895: Software Design Faculty of Engineering & Applied Science Memorial University of Newfoundland You already know C++ You understand
More informationYour first C++ program
Your first C++ program #include using namespace std; int main () cout
More informationObject Oriented Design
Object Oriented Design Lecture 3: Introduction to C++ (Continue) Examples using declarations that eliminate the need to repeat the std:: prefix 1 Examples using namespace std; enables a program to use
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 informationIntermediate Programming, Spring 2017*
600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general
More informationCS 376b Computer Vision
CS 376b Computer Vision 09 / 25 / 2014 Instructor: Michael Eckmann Today s Topics Questions? / Comments? Enhancing images / masks Cross correlation Convolution C++ Cross-correlation Cross-correlation involves
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 informationCS 11 C++ track: lecture 1
CS 11 C++ track: lecture 1 Administrivia Need a CS cluster account http://www.cs.caltech.edu/cgi-bin/ sysadmin/account_request.cgi Need to know UNIX (Linux) www.its.caltech.edu/its/facilities/labsclusters/
More informationCSE 303: Concepts and Tools for Software Development
CSE 303: Concepts and Tools for Software Development Hal Perkins Autumn 2008 Lecture 24 Introduction to C++ CSE303 Autumn 2008, Lecture 24 1 C++ C++ is an enormous language: All of C Classes and objects
More informationCE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings
CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings 19/10/2017 CE221 Part 2 1 Variables and References 1 In Java a variable of primitive type is associated with a memory location
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 informationCSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010
CSE 374 Programming Concepts & Tools Hal Perkins Spring 2010 Lecture 19 Introduction ti to C++ C++ C++ is an enormous language: g All of C Classes and objects (kind of like Java, some crucial differences)
More informationCS
CS 1666 www.cs.pitt.edu/~nlf4/cs1666/ Programming in C++ First, some praise for C++ "It certainly has its good points. But by and large I think it s a bad language. It does a lot of things half well and
More informationInheritance, and Polymorphism.
Inheritance and Polymorphism by Yukong Zhang Object-oriented programming languages are the most widely used modern programming languages. They model programming based on objects which are very close to
More informationCOMS W3101 Programming Language: C++ (Fall 2016) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2016) ramana@cs.columbia.edu Lecture-2 Overview of C C++ Functions Structures Pointers Design, difference with C Concepts of Object oriented Programming Concept
More informationPointers. Developed By Ms. K.M.Sanghavi
Pointers Developed By Ms. K.M.Sanghavi Memory Management : Dynamic Pointers Linked List Example Smart Pointers Auto Pointer Unique Pointer Shared Pointer Weak Pointer Memory Management In order to create
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 informationMidterm Exam 5 April 20, 2015
Midterm Exam 5 April 20, 2015 Name: Section 1: Multiple Choice Questions (24 pts total, 3 pts each) Q1: Which of the following is not a kind of inheritance in C++? a. public. b. private. c. static. d.
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 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 informationException Namespaces C Interoperability Templates. More C++ David Chisnall. March 17, 2011
More C++ David Chisnall March 17, 2011 Exceptions A more fashionable goto Provides a second way of sending an error condition up the stack until it can be handled Lets intervening stack frames ignore errors
More informationG52CPP C++ Programming Lecture 14. Dr Jason Atkin
G52CPP C++ Programming Lecture 14 Dr Jason Atkin 1 Last Lecture Automatically created methods: A default constructor so that objects can be created without defining a constructor A copy constructor used
More informationConstructor - example
Constructors A constructor is a special member function whose task is to initialize the objects of its class. It is special because its name is same as the class name. The constructor is invoked whenever
More informationCA341 - Comparative Programming Languages
CA341 - Comparative Programming Languages David Sinclair Dynamic Data Structures Generally we do not know how much data a program will have to process. There are 2 ways to handle this: Create a fixed data
More informationCS93SI Handout 04 Spring 2006 Apr Review Answers
CS93SI Handout 04 Spring 2006 Apr 6 2006 Review Answers I promised answers to these questions, so here they are. I'll probably readdress the most important of these over and over again, so it's not terribly
More informationDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II Year / Semester: III / V Date: 08.7.17 Duration: 45 Mins
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 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 informationOverview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program
Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of
More informationPaytm Programming Sample paper: 1) A copy constructor is called. a. when an object is returned by value
Paytm Programming Sample paper: 1) A copy constructor is called a. when an object is returned by value b. when an object is passed by value as an argument c. when compiler generates a temporary object
More informationThe issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management
Session 8 Memory Management The issues Dr Christos Kloukinas City, UoL http://staff.city.ac.uk/c.kloukinas/cpp (slides originally produced by Dr Ross Paterson) Programs manipulate data, which must be stored
More informationA brief introduction to C++
A brief introduction to C++ Rupert Nash r.nash@epcc.ed.ac.uk 13 June 2018 1 References Bjarne Stroustrup, Programming: Principles and Practice Using C++ (2nd Ed.). Assumes very little but it s long Bjarne
More informationBasic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable
Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is
More informationPHY4321 Summary Notes
PHY4321 Summary Notes The next few pages contain some helpful notes that summarize some of the more useful material from the lecture notes. Be aware, though, that this is not a complete set and doesn t
More informationCSCE 110 PROGRAMMING FUNDAMENTALS
CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class Prof. amr Goneid, AUC 1 Dictionaries(1): A Key Table Class Prof. Amr Goneid, AUC 2 A Key Table
More informationIntroduction Of Classes ( OOPS )
Introduction Of Classes ( OOPS ) Classes (I) A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. An object is an instantiation of a class.
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 informationFundamentals of Programming Session 24
Fundamentals of Programming Session 24 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2013 These slides have been created using Deitel s slides Sharif University of Technology Outlines
More informationDiscussion 1E. Jie(Jay) Wang Week 10 Dec.2
Discussion 1E Jie(Jay) Wang Week 10 Dec.2 Outline Dynamic memory allocation Class Final Review Dynamic Allocation of Memory Recall int len = 100; double arr[len]; // error! What if I need to compute the
More informationGovernment Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING
Government Polytechnic, Muzaffarpur. Name of the Lab: OBJECT ORIENTED PROGRAMMING THROUGH C++ Practical: OOPS THROUGH C++ Subject Code: 1618407 PROGRAM NO.1 Programming exercise on executing a Basic C++
More information1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?
1. Describe History of C++? The C++ programming language has a history going back to 1979, when Bjarne Stroustrup was doing work for his Ph.D. thesis. One of the languages Stroustrup had the opportunity
More informationUEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class
UEE1303(1070) S12: Object-Oriented Programming Advanced Topics of Class What you will learn from Lab 6 In this laboratory, you will learn the advance topics of object-oriented programming using class.
More informationAN OVERVIEW OF C++ 1
AN OVERVIEW OF C++ 1 OBJECTIVES Introduction What is object-oriented programming? Two versions of C++ C++ console I/O C++ comments Classes: A first look Some differences between C and C++ Introducing function
More informationAppendix G: Writing Managed C++ Code for the.net Framework
Appendix G: Writing Managed C++ Code for the.net Framework What Is.NET?.NET is a powerful object-oriented computing platform designed by Microsoft. In addition to providing traditional software development
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 informationCOMP6771 Advanced C++ Programming
1.. COMP6771 Advanced C++ Programming Week 5 Part Two: Dynamic Memory Management 2016 www.cse.unsw.edu.au/ cs6771 2.. Revisited 1 #include 2 3 struct X { 4 X() { std::cout
More informationChapter 1: Object-Oriented Programming Using C++
Chapter 1: Object-Oriented Programming Using C++ Objectives Looking ahead in this chapter, we ll consider: Abstract Data Types Encapsulation Inheritance Pointers Polymorphism Data Structures and Algorithms
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 informationProgramming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor
Programming C++ Lecture 3 Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor Jennifer.sartor@elis.ugent.be S Inheritance S Software reuse inherit a class s data and behaviors and enhance with new capabilities.
More informationPart VII. Object-Oriented Programming. Philip Blakely (LSC) C++ Introduction 194 / 370
Part VII Object-Oriented Programming Philip Blakely (LSC) C++ Introduction 194 / 370 OOP Outline 24 Object-Oriented Programming 25 Member functions 26 Constructors 27 Destructors 28 More constructors Philip
More informationCOMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C
More informationDUBLIN CITY UNIVERSITY REPEAT EXAMINATIONS 2009/2010 [SOLUTIONS] EE553 Object-oriented Programming for Engineers
DUBLIN CITY UNIVERSITY REPEAT EXAMINATIONS 2009/2010 [SOLUTIONS] MODULE: EE553 Object-oriented Programming for Engineers COURSE: YEAR: MTC M.Eng. in Telecommunications Engineering MEN M.Eng. in Electronic
More informationLecture 2, September 4
Lecture 2, September 4 Intro to C/C++ Instructor: Prashant Shenoy, TA: Shashi Singh 1 Introduction C++ is an object-oriented language and is one of the most frequently used languages for development due
More informationSlide Set 14. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary
Slide Set 14 for ENCM 339 Fall 2016 Steve Norman, PhD, PEng Electrical & Computer Engineering Schulich School of Engineering University of Calgary November 2016 ENCM 339 Fall 2016 Slide Set 14 slide 2/35
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 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 informationC How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. 1
C How to Program, 6/e 1 Structures : Aggregate data types are built using elements of other types struct Time { int hour; int minute; Members of the same structure must have unique names. Two different
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy
CSCI 334: Principles of Programming Languages Lecture 18: C/C++ Homework help session will be tomorrow from 7-9pm in Schow 030A instead of on Thursday. Instructor: Dan Barowy HW6 and HW7 solutions We only
More informationClasses: A Deeper Look
Classes: A Deeper Look 1 Introduction Implementing a Time Abstract Data Type with a class Class Scope and Accessing Class Members Separating Interface from Implementation Controlling Access to Members
More informationInterview Questions of C++
Interview Questions of C++ Q-1 What is the full form of OOPS? Ans: Object Oriented Programming System. Q-2 What is a class? Ans: Class is a blue print which reflects the entities attributes and actions.
More informationClass Destructors constant member functions
Dynamic Memory Management Class Destructors constant member functions Shahram Rahatlou Corso di Programmazione++ Roma, 6 April 2009 Using Class Constructors #include Using std::vector; Datum average(vector&
More informationCOMS W3101 Programming Language: C++ (Fall 2015) Ramana Isukapalli
COMS W3101 Programming Language: C++ (Fall 2015) ramana@cs.columbia.edu Lecture-2 Overview of C continued C character arrays Functions Structures Pointers C++ string class C++ Design, difference with C
More informationObject Reference and Memory Allocation. Questions:
Object Reference and Memory Allocation Questions: 1 1. What is the difference between the following declarations? const T* p; T* const p = new T(..constructor args..); 2 2. Is the following C++ syntax
More informationFunction Overloading
Function Overloading C++ supports writing more than one function with the same name but different argument lists How does the compiler know which one the programmer is calling? They have different signatures
More informationMore Tutorial on C++:
More Tutorial on C++: OBJECT POINTERS Accessing members of an object by using the dot operator. class D { int j; void set_j(int n); int mul(); ; D ob; ob.set_j(4); cout
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 informationClasses in C++98 and C++11
Classes in C++98 and C++11 January 10, 2018 Brian A. Malloy Slide 1 of 38 1. When we refer to C++98, we are referring to C++98 and C++03, since they differ only slightly. C++98 contained 3 types of constructors,
More informationDHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING
DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING CS6456 OBJECT ORIENTED PROGRAMMING Unit I : OVERVIEW PART A (2 Marks) 1. Give some characteristics of procedure-oriented
More informationG52CPP C++ Programming Lecture 16
G52CPP C++ Programming Lecture 16 Dr Jason Atkin http://www.cs.nott.ac.uk/~jaa/cpp/ g52cpp.html 1 Last Lecture Casting static cast dynamic cast const cast reinterpret cast Implicit type conversion 2 How
More informationS.E. Sem. III [CMPN] Object Oriented Programming Methodology
S.E. Sem. III [CMPN] Object Oriented Programming Methodology Time : 3 Hrs.] Prelim Question Paper Solution [Marks : 80 Q.1(a) Write a program to calculate GCD of two numbers in java. [5] (A) import java.util.*;
More information6.096 Introduction to C++ January (IAP) 2009
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture
More informationPackages & Random and Math Classes
Packages & Random and Math Classes Quick review of last lecture September 6, 2006 ComS 207: Programming I (in Java) Iowa State University, FALL 2006 Instructor: Alexander Stoytchev Objects Classes An object
More informationIntroduction to Java
Introduction to Java Module 1: Getting started, Java Basics 22/01/2010 Prepared by Chris Panayiotou for EPL 233 1 Lab Objectives o Objective: Learn how to write, compile and execute HelloWorld.java Learn
More informationScientific Computing
Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course
More informationIS 0020 Program Design and Software Tools
1 Introduction 2 IS 0020 Program Design and Software Tools Exception Handling Lecture 12 November 23, 200 Exceptions Indicates problem occurred in program Not common An "exception" to a program that usually
More informationCours de C++ Introduction
Cours de C++ Introduction Cécile Braunstein cecile.braunstein@lip6.fr Cours de C++ 1 / 20 Généralité Notes Interros cours 1/3 Contrôle TP 1/3 Mini-projet 1/3 Bonus (Note de Participation) jusqu à 2 points
More informationExercise 1.1 Hello world
Exercise 1.1 Hello world The goal of this exercise is to verify that computer and compiler setup are functioning correctly. To verify that your setup runs fine, compile and run the hello world example
More informationReliable C++ development - session 1: From C to C++ (and some C++ features)
Reliable C++ development - session 1: From C to C++ (and some C++ features) Thibault CHOLEZ - thibault.cholez@loria.fr TELECOM Nancy - Université de Lorraine LORIA - INRIA Nancy Grand-Est From Nicolas
More informationUse the dot operator to access a member of a specific object.
Lab 16 Class A class is a data type that can contain several parts, which are called members. There are two types of members, data member and functions. An object is an instance of a class, and each object
More informationC++ Memory Map. A pointer is a variable that holds a memory address, usually the location of another variable in memory.
Pointer C++ Memory Map Once a program is compiled, C++ creates four logically distinct regions of memory: Code Area : Area to hold the compiled program code Data Area : Area to hold global variables Stack
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects Outline Problem: How do I create multiple objects from a class Java provides a number of built-in classes for us Understanding
More informationECE 122. Engineering Problem Solving with Java
ECE 122 Engineering Problem Solving with Java Lecture 4 Creating and Using Objects Outline Problem: How do I create multiple objects from a class Java provides a number of built-in classes for us Understanding
More information(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University
(5-1) Object-Oriented Programming (OOP) and C++ Instructor - Andrew S. O Fallon CptS 122 (February 4, 2019) Washington State University Key Concepts 2 Object-Oriented Design Object-Oriented Programming
More informationProgramming in C++: Assignment Week 4
Programming in C++: Assignment Week 4 Total Marks : 20 March 22, 2017 Question 1 Using friend operator function, which set of operators can be overloaded? Mark 1 a.,, , ==, = b. +, -, /, * c. =,
More informationGet Unique study materials from
Downloaded from www.rejinpaul.com VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : IV Section : EEE - 1 & 2 Subject Code
More informationDistributed Real-Time Control Systems. Lecture 14 Intro to C++ Part III
Distributed Real-Time Control Systems Lecture 14 Intro to C++ Part III 1 Class Hierarchies The human brain is very efficient in finding common properties to different entities and classify them according
More informationSTRUCTURING OF PROGRAM
Unit III MULTIPLE CHOICE QUESTIONS 1. Which of the following is the functionality of Data Abstraction? (a) Reduce Complexity (c) Parallelism Unit III 3.1 (b) Binds together code and data (d) None of the
More informationVariables and numeric types
s s and numeric types Comp Sci 1570 to C++ types Outline s types 1 2 s 3 4 types 5 6 Outline s types 1 2 s 3 4 types 5 6 s types Most programs need to manipulate data: input values, output values, store
More informationProgramming in C++: Assignment Week 8
Programming in C++: Assignment Week 8 Total Marks : 20 September 9, 2017 Question 1 Consider the following code segment. Mark 2 void myfunction(int test) { try { if (test) throw test; else throw "Value
More informationexplicit class and default definitions revision of SC22/WG21/N1582 =
Doc No: SC22/WG21/ N1702 04-0142 Project: JTC1.22.32 Date: Wednesday, September 08, 2004 Author: Francis Glassborow & Lois Goldthwaite email: francis@robinton.demon.co.uk explicit class and default definitions
More informationC++ : Object Oriented Features. What makes C++ Object Oriented
C++ : Object Oriented Features What makes C++ Object Oriented Encapsulation in C++ : Classes In C++, a package of data + processes == class A class is a user defined data type Variables of a class are
More informationHomework 4. Any questions?
CSE333 SECTION 8 Homework 4 Any questions? STL Standard Template Library Has many pre-build container classes STL containers store by value, not by reference Should try to use this as much as possible
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 informationCE221 Programming in C++ Part 1 Introduction
CE221 Programming in C++ Part 1 Introduction 06/10/2017 CE221 Part 1 1 Module Schedule There are two lectures (Monday 13.00-13.50 and Tuesday 11.00-11.50) each week in the autumn term, and a 2-hour lab
More information