CS304 Lecture Wise Questions by Virtualians Social

Size: px
Start display at page:

Download "CS304 Lecture Wise Questions by Virtualians Social"

Transcription

1 Lecture No 1: What is Object-oriented programming (OOP)? Object-oriented programming (OOP) is a programming paradigm using "objects" data structures consisting of data fields and methods together with their interactions to design applications and computer programs. Whereas C++ is a partial implementation of OOP paradigm where you can include features such as data abstraction, encapsulation, messaging, modularity, polymorphism, and inheritance. What are the applications of oop in our professional life? OOP is the basic programming language which is widely used in many other languages. Or we can say that is it the base of many other concepts and emerging technologies. Many modern programming languages extensively used and support OOP. Some of the applications of OOP are: Dynamic programming languages Design patterns Wed application What is difference between Encapsulation and Abstraction? In encapsulation all the characteristics of an object is present in the object itself while in abstraction we capture only those details which are relevant to object current prospective. Read handout as their difference is given in handout with enough details. How can differentiate b/w OOP and OO Model? We make Object Oriented models showing several interacting objects to understand a system given to us for implementation. During coding in object oriented programming approach we have objects with their attributes and behaviors that are hidden from other classes, so we can say that object oriented programming follows the principle of information hiding. Prepared By: Irfan Khan (Chief Admin) Page 1

2 What is difference between Tangible and Intangible? Tangible: Something that can be physically touched or felt. For example something real and substantial. Intangible: Something that cannot be touched. If something is intangible it does not mean it's not real. It just means it has no physical existence like emotions. development What is a model? A model is an abstraction of something real or conceptual. We need models to understand an aspect of reality. Advantages of Object-Orientation We can easily develop an object oriented model for a problem. Everyone can easily understand an object oriented model. We can easily implement an object oriented model for a problem using any object oriented language like c++ using its features like classes, inheritance, virtual functions and so on. What is an object? An object is, 1. Something tangible (Ali, School, House, Car). 2. Something conceptual (that can be apprehended intellectually for example time, date and so on.). An object has, 1. State (attributes) 2. Well-defined behavior (operations) 3. Unique identity What is Polymorphism? it can be described as existence of one entity in more than one form its simplest example is function overloading in c++, where a function can work for more than one data type according to nature of parameters passed to the function. Prepared By: Irfan Khan (Chief Admin) Page 2

3 Lecture no 2: Information Hiding: Showing only those details to the outside world which are necessary for the outside world and hiding all other detail from the out side world. Key Points in information hiding: information is stored within the object Outside World can't have direct access to the information however outside world can ask the object to give information so we can say there is indirect access by the outside world Encapsulation(closely related to information hiding) " Data and behavior are tightly coupled inside an object" In C Function are separate from data while in objects the behavior of entity and state are tightly coupled. Both the information structure and implementation details of its operations are hidden from the out world in encapsulation. Advantages Of Encapsulation: Following are some advantage of Encapsulation: Simplicity and clarity Low complexity Better understanding As there is no direct to the information in encapsulation so it makes a model simple, easy to understand. Prepared By: Irfan Khan (Chief Admin) Page 3

4 Separation of interface and implementation: Changes in information does not affect the object interface. this is achieved via principles of information hiding and encapsulation. Messages: Objects communicate with each other through messages. message is a terminology used in object oriented programming. object send message by invoking appropriate operations on the target object. We can say message activate the interface Data Hiding: Information is stored within the object. It is hidden from the outside world. It can only be manipulated by the object itself. All of these are the known principles of OOP paradigm. What is difference b/w characteristic, behavior and interface? All these concepts are very related to each other. Characteristics is a general word that most often represents the state/data related to any specific object, like Age, size, color etc. but sometimes it also indicates the features related to any specific object depends upon the scenario,,,,,, e.g. eat(), play() etc As for as concerns the behavior of an object, its definitely the functions owned by that particular object. For example, your course selection() process is a behavior related to you (object). Now, Messages stimulates interfaces. For example a car has hidden information how to change the Gear internally from end users, but driver/ user of the car access that hidden information/service through well defined interface i.e. by moving back and forth, around the liver. What barrier against change propagation means? It s an advantage of information hiding that it makes difficult to change the sate of object, while one has to access only that part of object for which it gives access. Prepared By: Irfan Khan (Chief Admin) Page 4

5 So, barrier against change propagation means to stop irrelevant changes in an object state. What is difference between interface,encapsulation and implementation? Encapsulation: Encapsulation means data and behavior are tightly coupled both the information structure and implementation detail of its operations are hidden from the outer world. Interface: When one object wants to interact with another object they communicate with their interfaces. Let take an example of a car when we want to stop car (operation) there is an interface of break paddles through which we stop the car. Implementation: Implementation means, provides services offered by the object interface, in simple words, practically coding these concepts in programming language called implementation. Lecture no 3: What is Information Hiding? Information hiding means to show only the relevant details to outside world and hide irrelevant details from outside world. For example, to give input to computer, you use keyboard; means you are not aware from the details that how the information is being input/stored in the computer. You just use this interface (i.e. keyboard) to input your data while rest of the details are hidden from you. In object oriented paradigm, encapsulation is a way to achieve the concept of information hiding. It encapsulates data and functions into a single unit. Difference between Abstraction ad Class? Abstraction Real life objects have a lot of attributes and much kind of behaviors but most of the time we are interested in only that part of the objects that is related to the problem. Let take an example of a student in a school, when we consider it as an object in a school system we don t need the personal detail of student (Ali) we just take the behaviors and characteristics related to the school. Prepared By: Irfan Khan (Chief Admin) Page 5

6 Classes A class is the physical structure of objects, for example, we have objects like, Ali, Asad and Saad in a University environment. All of these are students and studying different subjects. We make (Define) a class of students and all of them put together and named as class student. What is the concept of "Less Redundancy" and "Increased maintainability" please with the example of real life? Less redundancy and increases maintainability are two of the advantages of inheritance. See the example given below to understand the concept of Less redundancy. Example: Suppose you have a class of Person with attributes name, age, and behaviors eat() and walk(). Now, we want to create another class Scientist with attributes name, age, Specialization Field and behavior eat (), walk (), experiment (). If we don t use the concept of inheritance, we will have to write name, age, eat () and walk () again in Scientist class resulting in redundant information. On the other hand, if we use the concept of inheritance here, we will write only those details i.e. attribute SpecializationField and behavior experiment () that are related to Scientist class while inherit other attributes and behavior from Person class. Thus information will not be written again, and redundancy will be reduced. Now, for other advantage; in maintenance phase, if you want to make some changes to eat (), walk () or any other common method of Person class, you will only change methods of Person class and that change will automatically be made in all derived classes such as Scientist etc. Thus, maintainability will be increased. Lecture no4: What is the diagram of Specialization? Specialization means that derived class is behaviorally incompatible with the base class Behaviorally incompatibility means that base class can t always be replaced by the derived class Prepared By: Irfan Khan (Chief Admin) Page 6

7 Derived class has some different of restricted characteristics than of base class. What is the Sub typing? Sub typing and generalization are related concepts, Subtyping (extension) and generalization is a way to look same thing in two ways. Sub typing is looking at things from Top to bottom whereas in generalization we look at things from bottom to top. What is the Generalization? A class containing common features for all other classes to be inherited. Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods. What is Restriction? Restriction is a process in which derived class inherits base class characteristics and then applies some restriction on base class method while Overriding concept is related with inheritance. In overriding child class gives a new implementation to a derived method by either extending its behaviour or restricting its behavior. What is use of overriding? Overriding concept is related with inheritance. In overriding child class gives a new implementation to a derived method by either extending its behavior or restricting its behavior while in concrete class represents a concrete concept; we can only instantiate an object of concrete object. It is used to provide specialization, extension, restriction and to improve performance. what is the relation between abstract class and generalization? Abstract class and generalization are related concepts. Abstract class is a class, whose object can not be instantiated. Through inheritance we convert Abstract classes into concrete classes which can then be instantiated. Abstraction reduces complexity by hiding irrelevant details, while generalization reduces complexity by replacing multiple entities which perform similar functions with a single construct. Prepared By: Irfan Khan (Chief Admin) Page 7

8 Example: Person class is an abstract class; through inheritance we can derive some specialized classes like, teacher, student, Doctor, etc, having some general characteristics of base class. What are Concrete Classes? Concrete classes are those classes whose objects can be instantiated. Examples: Student, Teacher, Doctor, Circle, Triangle etc are concrete classes, whose objects can be instantiated. Student Std; Teacher Tch; Doctor Dr; What is the difference between oop and procedural programming? These two are of different approaches of software development. Both have some advantages and disadvantages over each others. OOP uses and sees everything in terms of "Object". You know that in OOP an object has some characteristics, behavior and unique ID.OOP is very close to real world scenario and easy to model as compared to procedural approach. When an organization decides to develop an application by using OOP approach, then, definitely analysis and design of that particular application will be developed by using OOA/D concepts. All these concepts, you will study in detail in Software Engineering course. However, major components of OOP that makes it different from Procedural programming is as follows: Abstraction, Encapsulation, Inheritance, Coupling, Cohesion, Information hiding, Aggregation, Composition, Association etc. What is the difference between overriding and abstraction? You know that in inheritance, derived class has right to own all the data and behaviour of its base class. It is seen practically that there might be at least one situation among the four listed below while in inheritance under the concept of Overriding a function. Prepared By: Irfan Khan (Chief Admin) Page 8

9 1- Derived class uses the override function as it is from base class 2- Derived class extends somehow the behaviour of Overrided function as per its needs 3- Derived class restrict somehow the behaviour of Overrided function as per its needs. Abstraction is different from that one in such a way that it "Abstraction is used to minimize the complexity of the system by binding up the relevant data and behavior together. What is concert class? Almost all classes we studied so far are concrete classes, by concrete class we mean such class for which we can create objects. However in coming lectures of this course we will study Abstract classes which are conceptual parent classes for child classes, then the difference of concrete and abstract class will become clearer What is Generalization? Generalization is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass. Shared characteristics can be attributes, associations, or methods. In class diagrams, a generalization relationship, which is also called an inheritance or an is-a relationship, implies that a specialized, child, class is based on a general, parent, class. Generalization implies an "is a" relationship. One class is derived from another, the base class. Generalization is implemented as inheritance in C++. The derived class has more specialization. It may either override the methods of the base, or add new methods What are Abstract classes? Lecture No 5: Abstract classes are used to fulfill abstract concepts in our model like (shape, person), we cannot make any object of this (abstract) class. It can only be used as a parent (in hierarchy) for derived classes that inherits from the abstract class. Abstract Classes cannot exists standalone in an object model as it allows you to define a problem into imaginary classes that are not fully defined; therefore abstract classes cannot exists standalone in a model, there will definitely exist some concrete classes as well which are derived from this abstract class otherwise there is no use of abstract class. Prepared By: Irfan Khan (Chief Admin) Page 9

10 Objects are also called instances of a class as they are used to instantiate a class in a program. What is class association? And what is public and private inheritance described in class association? We implement class association in terms of Inheritance. You are already studied that Inheritance is used to implement generalization/specialization relationship between objects. Inheritance can be of three types: public inheritance, private inheritance and protected inheritance. Class association in case of public inheritance is IS-A relationship and in case of private inheritance it is Implemented in terms of relationship. In case of public inheritance public members of base class become public members of derived class. And in case of private inheritance public members of base class become private members of derived class Why association is used in programming? In an object model, usually all objects interact with all other objects. So programming requires Association. As OOP programming models the real world where all objects needs some services to other objects. So association is required in real world as well as in OOP. What is orientation inherence? Object orientation is a way we think our programming solutions in terms of real life objects and relationship among them. There are many concepts which have been originated in Object Oriented Progamming. We think each and every entity / concept in terms of object when we talk about object oriented programming. Now when we talk about inheritance in objects and classes in programming this is exactly the real life phenomena of object orientation. Similar like in our families there is a relationship between parent objects and child objects same is the case in the programming phenomena. We take everthing as object or class to deal with. So inheritance is a feature of object oriented programming. What is cop and complexity? Cope means handle, manage, deal with etc Complexity means difficulty, complication etc Prepared By: Irfan Khan (Chief Admin) Page 10

11 Complexity increases without abstraction: Without abstraction all the data (either relevant or irrelevant) will store, and all the functionality will be implemented, which increased the complexity of program. And using abstraction only relevant data will be stored, minimizing the complexity of program. What is domain? Domain represents any specific field/area. Domain knowledge means knowledge/ information/ data about any particular area. If a person has knowledge about a particular field, he is called Domain Expert of that field. Example: If Ali is expert in Security, then his domain is network security. What is the main difference between Two way and Binary Association? In binary association two entities are involved but association between these entities may be one way or two way. But in two way association two entities are involved but association between these entities must be two way. One way association is represented with an arrow, while two way association is represented by a line. What is the value of cardinality(*) in association? Cardinality is a rule specifying how many times an entity can be related to another entity in a given relationship. "*" means many i.e. an entity can be related to another entity many times. Example: Company and Employees: Many employees can related with a single entity i.e. company What is is a relationship? The is a or is a kind of relationship between two classes is represented in object oriented programming through inheritance. Prepared By: Irfan Khan (Chief Admin) Page 11

12 Examples: Triangle is a Shape or Triangle is a kind of Shape. Student is a Person or Student is a kind of Person. CS304 is a Subject or CS304 is a kind of Subject. In all of the above examples there is a relationship of is a or is a kind of between these classes. So while coding, we should mention inheritance relationship between these classes. What is the * of the one way direction? * represents many instance of an entity that can be related with other entity. Examples: Ali drives many cars. A teacher teaches to many students. A single instance of Ali can be related with many instances of car. A single instance of teacher can be related with many instances of students. what is definition, declaration and initialization? A declaration is a statement that says "here is the name of something and the type of thing that it is, but I'm not telling you anything more about it". A definition is a statement that says "here is the name of something and what exactly it is". For functions, this would be the function body; for global variables, this would be the translation unit in which the variable resides. An initialization is a definition where the variable is also given an initial value. Some languages automatically initialize all variables to some default value such as 0, false, or null. Some (like C/C++) don't in all cases: all global variables are default-initialized, but local variables on the stack and dynamically allocated variables on the heap are NOT Prepared By: Irfan Khan (Chief Admin) Page 12

13 default initialized - they have undefined contents, so you must explicitly initialize them. C++ also has default constructors, which is a whole nother can of worms. Examples: // In global scope: extern int a_global_variable; // declaration of a global variable int a_global_variable; // definition of a global variable int a_global_variable = 3; // definition & initialization of a global variable int some_function(int param); // declaration of a function int some_function(int param) // definition of a function { return param + 1; } What is Aggregation? Aggregation is a form of composition where one looks at the system as a whole rather than as parts. It is also based on has-a relationship and is implemented by creating objects of other classes inside the class. An example will be a car class which is an aggregation of different classes like wheel, engine, body etc.this may be explained with the help of an example. Suppose you have a class named User Information. And with that class you are having a object instance named UserContactInfo Class UserInformation { UserContactInfo usercontactinfo ; } This leads to aggregation. The UserContactInfo object is aggreated within UserInformation class. Both the classes have individual identity. Prepared By: Irfan Khan (Chief Admin) Page 13

14 Now suppose we have a class named Rectangle. And within that class you have Class Point as a object. Class Rectangle { Point point ; } Now rectangle is a composition of points. Point class doesn't have any individual important. It is point that makes a rectangle. This is known as composition What are Advantages and Disadvantages of Multiple Inheritance? Advantages: It reduces the Code of a class and use their function without to write them again Disadvantages: Increase Complexity Reduce Understanding Duplicate feature Q:How many Types of Association? class Association Object Association Prepared By: Irfan Khan (Chief Admin) Page 14

15 WHAT IS COMPOSITION? It is a strong ownership of the part by the whole,for example:a person has a strong relationship with his head,,where head is a composition relationship What is Association? It Is a structural relationship which represents a binary relationship between a class. What is aggregation? Relationship between container and contained object. It is weak due to: aggregated object is not a part of container and the object can exist independently What are Advantages of information hiding? Lecture no 6 It s an advantage of information hiding that it makes difficult to change the sate of object, while one has to access only that part of object for which it gives access. So, barrier against change propagation means to stop irrelevant changes in an object state. Two way association? Yes in two way association we can navigate in both directions, so there is no arrow mentioned in this association as both objects can act as a server object. You are confused in label of association, so dear student make it clear that label of association is changed with respect to server object in this association. Employee works for company and Company employs employees are two different aspects of the same association. Prepared By: Irfan Khan (Chief Admin) Page 15

16 In first case of this association, company act as a server object and in second case employees act as server object. So that label of associations may change according to the services of objects. What is difference between overloading and overriding? The main difference between overloading and overriding is that in overloading we can use same function name with different parameters to perform multiple tasks on the basis of parameters with in a class. Overriding means we can use same function name with same parameters in base and derived class. Base class only declares the function but derived class implements the function. Can we use UML for developing any object oriented model? An object is a self-contained entity with well-defined characteristics and behaviors while the characteristics and behaviors are represented by attributes and operations respectively. A class is a generic definition for a set of similar objects. Hence, an object is an instance of a class. An object model provides a static conceptual view of an application. It shows the key components (objects) and their relationships (associations) within the application system. The object model is drawn using UML notations. What is Polymorphism? Polymorphism in simple words can be defined as" Single Interface Multiple Behavior". poly means many morph means shapes so, one function taking many shapes,for ex: take the function name as add, by passing different sets of arguments it can add 2no.s,3 numbers etc... there are two types of polymorphism namely, runtime polymorphism, compile time polymorphism, compile time Polymorphism means function overloading, run time polymorphism means virtual functions. Prepared By: Irfan Khan (Chief Admin) Page 16

17 What is Pointer? In C++ or OOP by using C++, we have a "this" pointer. Pointer is used to store the address of any variable/object. this pointer stores the address of the class instance, to enable pointer access of the members to the member functions of the class. this pointer is not counted for calculating the size of the object. this pointers are not accessible for static member functions. this pointers are not modifiable What are security and privacy? Defining "computer security" is not trivial. The difficulty lies in developing a definition that is broad enough to be valid regardless of the system being described, yet specific enough to describe what security really is. In a generic sense, security is "freedom from risk or danger." In the context of computer science, security is the prevention of, or protection against, access to information by unauthorized recipients, and intentional but unauthorized destruction or alteration of that information1 This can be re-stated: "Security is the ability of a system to protect information and system resources with respect to confidentiality and integrity." Note that the scope of this second definition includes system resources, which include CPUs, disks, and programs, in addition to information. A feature of a voice mail system that allows a sender to mark a message as private or confidential, thereby denying the recipient the ability to forward it to another user is the privacy. Class Compatibility? A class is behaviorally compatible with another if it supports all the operations of the other class. Such a class is called subtype. A class can be replaced by its subtype. Derived class is usually a subtype of the base class. It can handle all the legal messages (operations) of the base class. Therefore, base class can always be replaced by the derived class. Polymorphism in OO Model In OO model, polymorphism means that different objects can behave in different ways for the same message (stimulus). Consequently, sender of a message does not need to know exact class of the receiver. Sender sends message to receiver and appropriate method is called on receiver side. Prepared By: Irfan Khan (Chief Admin) Page 17

18 Lecture no 7 What is the difference between constructor and destructor? Difference between constructor and destructor is given in table form: Constructor Same name as class name Used for memory allocation/ initialization Constructor automatically called when an object is created Destructor Same name as class name but preceded by tilde (~) sign Used for memory de-allocation Destructor is automatically called when an object is destroyed What is abstraction? Abstraction is infact an OOP concept that deals with "Relevancy". Put only relevant information in an object ans remove irrelevancy with in a particular scenario. For example, if you want Student Record that is used by Exam department, So, in this scenario, Exam department doesn't require information about student's brother as they only concern your marks, CGPA Roll No etc. So, putting relevant information as required in a particular scenario is the Abstraction. What is this pointer? this pointer is used as a pointer to the class object instance by the member function. The address of the class instance is passed as an implicit parameter to the member functions. When a class need to access its objects (data members) in any of its functions then it use this pointer to access that data member. Look at the following example to understand how to use the 'this' pointer. class this_pointer_example // class for explaining C++ tutorial { int data1; public: //Function using this pointer for C++ Tutorial int getdata() { return this->data1; } Prepared By: Irfan Khan (Chief Admin) Page 18

19 void setdata(int data1) { this->data1 = data1; } }; What is "bool"? bool or Boolean is a data type in C++. Boolean variables only have two possible values: true (1) and false (0). To declare a boolean variable, we use the keyword bool. bool bvalue; When assigning values to boolean variables, we use the keywords true and false. bool bvalue1 = true; Just as the unary minus operator (-) can be used to make an integer negative, the logical NOT operator (!) can be used to flip a boolean value from true to false, or false to true: bool bvalue1 =!true; // bvalue1 will have the value false When boolean values are evaluated, they actually don t evaluate to true or false. They evaluate to the numbers 0 (false) or 1 (true). Consequently, when we print their values with cout, it prints 0 for false and 1 for true: bool bvalue = true; cout bvalue endl; cout!bvalue endl; bool bvalue2 = false; cout bvalue2 endl; cout!bvalue2 endl; Outputs: One of the most common uses for boolean variables is inside if statements: bool bvalue = true; if (bvalue) cout "bvalue was true" endl; else cout "bvalue was false" endl; Output: bvalue was true Prepared By: Irfan Khan (Chief Admin) Page 19

20 Don t forget that you can use the logical not operator to reverse a boolean value: Boolean values are also useful as the return values for functions that check whether something is true or not. When converting integers to booleans, the integer zero resolves to boolean false, whereas non-zero integers all resolve to true. What is domain knowledge? Domain knowledge means knowledge about specific area. For example; extract properties from the object line from the domain knowledge, its mean that extract that properties which are discuss in the given scenario only. Use of scope resolution? Scope resolution is used to access a static data member and to define a function outside the class. Example: #include <iostream> using namespace std; char c = 'a'; // global variable int main() { char c = 'b'; //local variable } cout << "Local c: " << c << "\n"; cout << "Global c: " << ::c << "\n"; //using scope resolution operator return 0; Use of char *? Where * is used to declare the pointer of a variable and that pointer is used to save the address of another variable. Prepared By: Irfan Khan (Chief Admin) Page 20

21 Example; char *name will save the address of a character variable char abc; name = &abc; Example: #include <iostream> using namespace std; int main() { int x; // A normal integer int *p; // A pointer to an integer p = &x; // Read it, "assign the address of x to p" cin>> x; // Put a value in x, we could also use *p here cin.ignore(); cout<< *p <<"\n"; // Note the use of the * to get the value cin.get(); } Lecture no 8 What is difference member function and public members? Classes can contain data and functions. These functions are referred to as "member functions." Any function declared inside a class declaration is considered a member function. For example: // member_functions1.cpp // compile with: /EHsc #include <iostream> using namespace std; Prepared By: Irfan Khan (Chief Admin) Page 21

22 class Point { public: int i=13; void Show() { cout "Member function\n"; } }; int main() { Point pt; pt.show(); } void Show() is a member function of class Point and i is a public member of the class. This public member is accessed outside the class while private and protected members are not accessible outside the class. What is Default Access specified? Access specifier are keywords (private, protected and public) which are used to set the scope of any variable or function, by default access specifier we mean the default scope used to access the member variables or functions in case we don't mention any access specifier for example in classes the default access specifier is private, same in the case for inheritance, however default access specifier for structures is public as they were used only to group data. Can we use protected keyword instead of private keyword? Prepared By: Irfan Khan (Chief Admin) Page 22

23 The protected keyword specifies access to class members in the member-list up to the next access specifier (public or private) or the end of the class definition. Class members declared as protected can be used only by the following: Member functions of the class that originally declared these members. Friends of the class that originally declared these members. Classes derived with public or protected access from the class that originally declared these members. Direct privately derived classes that also have private access to protected members. protected: [member-list] protected base-class What is the difference b/w base class & concrete class? A base class is a class containing all common attributes and behaviors. Whereas concrete class is a class which is not of abstract type and whose object can be created. What is default constructor? A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values. If no user-defined constructor exists for a class A and one is needed, the compiler implicitly declares a default parameter-less constructor A::A(). This constructor is an inline public member of its class. The compiler will implicitly define A::A() when the compiler uses this constructor to create an object of type A. The constructor will have no constructor initialize and a null body. Prepared By: Irfan Khan (Chief Admin) Page 23

24 What is difference between copy constructor or shallow copy? A copy constructor is used to initialize a newly declared Object from an existing Object. This makes a deep copy like assignment. A shallow copy of an object copies all of the member field values. This works well if the fields are values, but may not be what you want for fields that point to dynamically allocated memory. The pointer will be copied. but the memory it points to will not be copied -- the field in both the original object and the copy will then point to the same dynamically allocated memory. A deep copy copies all fields, and makes copies of dynamically allocated memory pointed to by the fields. To make a deep copy, you must write a copy constructor and overload the assignment operator, otherwise the copy will point to the original, with disastrous consequences. I am giving you one example which perform deep copy in this example if you do not override copy constructor then it will give run time error, not perform as what we want so it will be help full for understanding why we have to override copy constructor if compiler provide it by default. class base { int *a; public: base() {} void allocate() { a = new int(10); } void disp() { cout*aendl; } base(base &b) { a = new int(*(b.a)); } Prepared By: Irfan Khan (Chief Admin) Page 24

25 ~base() { delete a; } }; int _tmain(int argc, _TCHAR* argv[]) { base *b1 = new base; b1->allocate(); base *b2 = new base(*b1); b1->disp(); delete b1; b2->disp(); delete b2; return 0; } What is an Inline function? Inline functions is a way used by compilers to improve efficiency of the program, when functions are declared inline normal process of function calling (using stack) is not followed instead function code is added by compiler at all points where these functions have been called. Basic concept behind inline functions is that they are functions in our code but in compiler generated files these functions code is added by compiler at all places where they were called in the code. Normally small size functions that need to be called many times during program execution are declared inline. Inline functions decrease the code execution time because program in their case doesn t involve function call overhead. Keyword inline is used to request compiler to make a function inline. However using inline keyword with function doesn t guarantee that function will definitely in inlined, it depends on the compiler if it finds it can make function inline it does so otherwise it ignores the keyword inline and treat the function as normal function Prepared By: Irfan Khan (Chief Admin) Page 25

26 What is Navigation? Navigation is an aspect of a simple association between classes, which refers that whether objects of two classes are related in one way or in two ways. In one-way association, we can navigate in single direction, while in two way association we can navigate in both directions. Lecture no 9 This Pointer? This pointer is a constant pointer that stores the memory address of the current object. It is an implicit/hidden parameter to all member functions of a class. See the use of this pointer in the following example code segment in which value of data member of the current object is setting through this pointer. class A { int a; public: void set(int a1){ this->a=a1; } }; In order to return current object to the calling function, return *this statement is used. Q:Friend function increase bugs? As for as your second question is concern, Friend functions do not increase bugs, however programmer are required to use friend functions only when there is a need. Prepared By: Irfan Khan (Chief Admin) Page 26

27 What is class hierarchy? A set of classes and their interrelationships is called class hierarchy. When a method is invoked on an object it is first looked for in the object s class, then the superclass of that class and son on up the hierarchy until it is found. Thus a class need only define those methods which are specific to it, and inherit methods from all its superclasses. Example: Class C is derived from class of B, and B class is derived from class A. Now class C object accessed the method (SetName(char *)), then it first looked in class C, if not found, then looked in class B, if not found, then looked in class A. What is access specifier? Access specifier specifies whether that a specific data member is accessible at a particular location in a program. There are three access specifiers in C++. Public specifier tells that this data member can be accessed any where in the program. Protected access specifier tells that this data member can only be accessed in the class, in which it is declared, or in the child class. Private access specifier tells that this data member can only be accessed inside the class, in which it is declared. Example: class Student { private: int RollNo; char * Name; protected: int age; public: void display(); }; Now "RollNo" and "Name" can only be accessible in the "Student" class. Similarly "age" can be accessed in the derived class, and "display()" function can be used in any new class, function, or main function. Prepared By: Irfan Khan (Chief Admin) Page 27

28 What is resolution operator? :: is called scope resolution operator. Scope resolution operator is used the define data members/functions outside class body or to define static variable. Example: Student::Student(){cout "Default constructor"; } int Student::noOfStudents=0; What is override? Override means "dominate", while in OOP override means that child class function override the behaviour of parent class function. The override function must have the same name in both derived and parent class. While accessing base class function through derived class, then the derived class function will execute instead of parent class function. Example: class Person{ int age; public: void setage(int _age){ age=_age; } }; class Adult: public Person { int age; public: void setage(int _age){ if(_age>=18){ age=_age; } cout "Enter the age of an adult person"; } int main(){ Adult obj; obj.setage(17); // Adult class method setage() will be execute system("pause"); } What is a override function? Prepared By: Irfan Khan (Chief Admin) Page 28

29 If base class and derived class have member functions with same name and arguments. If you create an object of derived class and write code to access that member function then, the member function in derived class is only invoked, i.e., the member function of derived class overrides the member function of base class. This feature in C++ programming is known as function overriding. Example Prepared By: Irfan Khan (Chief Admin) Page 29

30 What are constant members functions? Lecture no 10 Constant member functions are those functions that can not modified the object state. Constant member functions are read only. Constant data member function can not change data member. To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition. Syntax: class classname{ returnvalue Function() const; }; Definition: returnvalue classname:: function() const{ } Example: class Student{ public: int getrollno() const { return rollno; } }; Lecture no 11 What is difference between Definition and Declaration? Declaration of a variable or function means to tell the compiler about its type, while defition means the exact code. For example, declaration of function means, to tell the compiler about the return type of function, Prepared By: Irfan Khan (Chief Admin) Page 30

31 its parameter types etc, while definition of function means the actual code of the function. Similarly, declaration of a variable means to tell the compiler about its type, while definition means to assign some value to the variable. Difference between initializing and Assignments? Initialization is assigning value along with creation of variable. int i; i=7; Assignment is assigning value after creation. Int i; I=7; Member Initialize List Member initialization list is used where we cannot modify the state of data members in the member functions of the class including constructor, Constant Member Functions Make all functions that don t change the state of the object constant This will enable constant objects to access more member functions Static Variables Static variables of a class are such variables which are independent of class objects. Lifetime of static variable is throughout the program life, if static variables are not explicitly initialized then they are initialized to 0 of appropriate type. Prepared By: Irfan Khan (Chief Admin) Page 31

32 Class Variable: Lecture no 12 A variable which is defined inside a class and have same copy for all objects of this class is called class variable that is, static variable in class. Instance Variable: A variable which is defined inside a class and have separate copy for each object of this class is called instance variable, that is, normal variable defined inside class (data members). Lecture no 13 Intrinsic relationship means, relation between two or more objects which is mandatory or fundamental. What is primitive data type, primitive variable and structure variable? The data types int, float, char etc are called primitive data types. Variables of primitive data types are called primitive variable. The variable of type structure (struct) is called structure variable. What is main difference b/w Copy Constructor and shallow copy.? Copy constructor is of two type, default copy constructor and deep copy constructor. The default copy constructor is also called shallow copy. Lecture no 14 What is bool or boolean when n why we use it? bool is a data type, when a variable defines with bool data type, its value would be either true or false. We do not return 0 when a function s return type is void. Prepared By: Irfan Khan (Chief Admin) Page 32

33 arollno, Rollno, a_name etc all are user define variables. Lecture no15 Why const data member of a class need to be initialized at the constructor why not somewhere else? const data members cannot be initialized through constructor; they are initialized through member initialization list. Further, constructor initializes the state (non constant data members) of an object. What are binary operators? The operators which take two operands are called binary operators. For example, +, -,* etc The code examples of binary operators have given in handouts, read handouts thoroughly. Explain the definition of Operator Overloading? Operator overloading is a technique which allows the basic operators like +, -, = etc to work for user defined type (class/object) as well. This can be achieved through user defined functions with a keyword operator followed by the operator which is going to be overloaded (allow for user defined type). These functions may be the member functions of the class or non-member functions of the class. Lecture no 16 Explain the definition of Operator Overloading? Operator overloading is a technique which allows the basic operators like +, -, = etc to work for user defined type (class/object) as well. Prepared By: Irfan Khan (Chief Admin) Page 33

34 This can be achieved through user defined functions with a keyword operator followed by the operator which is going to be overloaded (allow for user defined type). These functions may be the member functions of the class or non-member functions of the class. What are binary operators? The operators which take two operands are called binary operators. For example, +, -,* etc The code examples of binary operators have given in handouts, read handouts thoroughly. Lecture no 17 Shallow copy: When an object is created and initialized with an already defined/constructed object, then this copying is done through default copy constructor and such type of copying object is called shallow copy. In shallow copy the state of the created object is initialized member-wise and as a result both objects pointing to the same memory location. When const keyword is used before a variable declaration in the parameter list of a function, it means, the function can use the variable within its body but cannot changes/update its value. When const keyword is used before the return type of a function, it means, the function will return constant value. When const keyword is used after a function name, it means, this member function cannot change/update the object status (that is, cannot change the data members). Prepared By: Irfan Khan (Chief Admin) Page 34

35 What is a Cascaded expression means? Lecture No 18: an expression in which an operator like = use more than once, following is an example of cascaded expression. Obj4 = obj3= obj2 = obj1; Second, rhs is a user define variable name in the given function definition. + is a binary operator, when it applies on user define variables (objects), then the right hand side operand must be passed to the function which implement the + operator. So here rhs has used for right-hand-side operand. What is Operator overloading? Operator overloading is a technique which allow the basic operators like +, -, = etc to work for user defined type (class/object) as well. This can be achieved through user defined functions with a keyword operator followed by the operator which is going to be overloaded (allow for user defined type). These functions may be the member functions of the class or non-member functions of the class. Function overloading: Function overloading means, when there are more than one function with same name and different number or type of arguments, then it is called function overloading. Complex Number: It is a number which has two parts real and imaginary and can be expressed in the form of, a + bi Prepared By: Irfan Khan (Chief Admin) Page 35

36 Lecture No 19: What is difference Between Shallow Copy and Deep Copy? Shallow copy: When an object is created and initialized with an already defined/constructed object, then this copying is done through default copy constructor and such type of copying object is called shallow copy. In shallow copy the state of the created object is initialized member-wise and as a result both objects pointing to the same memory location. Deep copy: In the deep copy new memory assign to the new created object instead of pointing it (member-wise copying) to pre defined object. What is Self assignment? Lecture No 20 Self assignment means, assigning a string to itself. It may create problem, because as the source and destination variables are the same and we release (delete memory) the destination variable before assignment. Copy constructor? A constructor which is used to copy one object to another is called copy constructor. There are two type of copy constructors, Default copy constructor which is also called shallow copy and deep copy constructor. Prepared By: Irfan Khan (Chief Admin) Page 36

37 Lecture No 21: Behavior of ++ and -- for pre-defined types: Pre-increment ++: Pre-increment operator ++ increments the current value and then returns it s reference Pre-decrement --: Works exactly like Pre-increment ++ Example: int x = 2, y = 2; ++++y; cout y; ++y = x; cout y; Output: 4 2 Lecture No 22: Inheritance in Classes If a class B inherits from class A, then B contains all the characteristics (information structure and behavior) of class A The parent class is called base class and the child class is called derived class Besides inherited characteristics, derived class may have its own unique characteristics Prepared By: Irfan Khan (Chief Admin) Page 37

CS304 Object Oriented Programming Final Term

CS304 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 information

OBJECT ORIENTED PROGRAMMING USING C++ CSCI Object Oriented Analysis and Design By Manali Torpe

OBJECT 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 information

What are the characteristics of Object Oriented programming language?

What are the characteristics of Object Oriented programming language? What are the various elements of OOP? Following are the various elements of OOP:- Class:- A class is a collection of data and the various operations that can be performed on that data. Object- This is

More information

CS304 Object Oriented Programming

CS304 Object Oriented Programming 1 CS304 Object Oriented Programming 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?

More information

Short Notes of CS201

Short 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 information

CS201 - Introduction to Programming Glossary By

CS201 - 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 information

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year

Object Oriented Programming. Assistant Lecture Omar Al Khayat 2 nd Year Object Oriented Programming Assistant Lecture Omar Al Khayat 2 nd Year Syllabus Overview of C++ Program Principles of object oriented programming including classes Introduction to Object-Oriented Paradigm:Structures

More information

Interview Questions of C++

Interview 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 information

Inheritance, and Polymorphism.

Inheritance, 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 information

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak

OBJECT ORIENTED PROGRAMMING. Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PROGRAMMING Ms. Ajeta Nandal C.R.Polytechnic,Rohtak OBJECT ORIENTED PARADIGM Object 2 Object 1 Data Data Function Function Object 3 Data Function 2 WHAT IS A MODEL? A model is an abstraction

More information

Programming, numerics and optimization

Programming, numerics and optimization Programming, numerics and optimization Lecture A-4: Object-oriented programming Łukasz Jankowski ljank@ippt.pan.pl Institute of Fundamental Technological Research Room 4.32, Phone +22.8261281 ext. 428

More information

Data Structures using OOP C++ Lecture 3

Data Structures using OOP C++ Lecture 3 References: th 1. E Balagurusamy, Object Oriented Programming with C++, 4 edition, McGraw-Hill 2008. 2. Robert L. Kruse and Alexander J. Ryba, Data Structures and Program Design in C++, Prentice-Hall 2000.

More information

JAVA: A Primer. By: Amrita Rajagopal

JAVA: A Primer. By: Amrita Rajagopal JAVA: A Primer By: Amrita Rajagopal 1 Some facts about JAVA JAVA is an Object Oriented Programming language (OOP) Everything in Java is an object application-- a Java program that executes independently

More information

Polymorphism Part 1 1

Polymorphism Part 1 1 Polymorphism Part 1 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid

More information

C++ Important Questions with Answers

C++ Important Questions with Answers 1. Name the operators that cannot be overloaded. sizeof,.,.*,.->, ::,? 2. What is inheritance? Inheritance is property such that a parent (or super) class passes the characteristics of itself to children

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 43 Dynamic Binding (Polymorphism): Part III Welcome to Module

More information

Chapter 1 Getting Started

Chapter 1 Getting Started Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different

More information

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017 Overview of OOP Dr. Zhang COSC 1436 Summer, 2017 7/18/2017 Review Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in square brackets: l = [1, 2, "a"] (access by index, is mutable

More information

Data Structures (list, dictionary, tuples, sets, strings)

Data Structures (list, dictionary, tuples, sets, strings) Data Structures (list, dictionary, tuples, sets, strings) Lists are enclosed in brackets: l = [1, 2, "a"] (access by index, is mutable sequence) Tuples are enclosed in parentheses: t = (1, 2, "a") (access

More information

Introduction Of Classes ( OOPS )

Introduction 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 information

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT I INTRODUCTION TO OOP AND FUNDAMENTALS OF JAVA 1. Define OOP. Part A Object-Oriented Programming (OOP) is a methodology or paradigm to design a program using classes and objects. It simplifies the

More information

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. OOPs Concepts 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8. Type Casting Let us discuss them in detail: 1. Data Hiding: Every

More information

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language

Chapter 11. Categories of languages that support OOP: 1. OOP support is added to an existing language Categories of languages that support OOP: 1. OOP support is added to an existing language - C++ (also supports procedural and dataoriented programming) - Ada 95 (also supports procedural and dataoriented

More information

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR 603203 DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS QUESTION BANK (2017-2018) Course / Branch : M.Sc CST Semester / Year : EVEN / II Subject Name

More information

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

Government 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 information

Fast Introduction to Object Oriented Programming and C++

Fast 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 information

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity. OOPS Viva Questions 1. What is OOPS? OOPS is abbreviated as Object Oriented Programming system in which programs are considered as a collection of objects. Each object is nothing but an instance of a class.

More information

CSC1322 Object-Oriented Programming Concepts

CSC1322 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 information

1. Write two major differences between Object-oriented programming and procedural programming?

1. Write two major differences between Object-oriented programming and procedural programming? 1. Write two major differences between Object-oriented programming and procedural programming? A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do:

More information

EL2310 Scientific Programming

EL2310 Scientific Programming (pronobis@kth.se) Overview Overview Wrap Up Introduction to Object Oriented Paradigm More on and Members Operator Overloading Last time Intro to C++ Differences between C and C++ Intro to OOP Today Object

More information

Instantiation of Template class

Instantiation of Template class Class Templates Templates are like advanced macros. They are useful for building new classes that depend on already existing user defined classes or built-in types. Example: stack of int or stack of double

More information

OBJECT ORIENTED PROGRAMMING

OBJECT ORIENTED PROGRAMMING Classes and Objects So far you have explored the structure of a simple program that starts execution at main() and enables you to declare local and global variables and constants and branch your execution

More information

AN OVERVIEW OF C++ 1

AN 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 information

Lecture Notes on Programming Languages

Lecture Notes on Programming Languages Lecture Notes on Programming Languages 85 Lecture 09: Support for Object-Oriented Programming This lecture discusses how programming languages support object-oriented programming. Topics to be covered

More information

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming Overview of OOP Object Oriented Programming is a programming method that combines: a) Data b) Instructions for processing that data into a self-sufficient object that can be used within a program or in

More information

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1

What is Polymorphism? Quotes from Deitel & Deitel s. Why polymorphism? How? How? Polymorphism Part 1 Polymorphism Part 1 What is Polymorphism? Polymorphism refers to a programming language s ability to process objects differently depending on their data type or class. Number person real complex kid adult

More information

CS11 Introduction to C++ Fall Lecture 7

CS11 Introduction to C++ Fall Lecture 7 CS11 Introduction to C++ Fall 2012-2013 Lecture 7 Computer Strategy Game n Want to write a turn-based strategy game for the computer n Need different kinds of units for the game Different capabilities,

More information

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1

Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Introduction to C++ Introduction to C++ Dr Alex Martin 2013 Slide 1 Inheritance Consider a new type Square. Following how we declarations for the Rectangle and Circle classes we could declare it as follows:

More information

CS-202 Introduction to Object Oriented Programming

CS-202 Introduction to Object Oriented Programming CS-202 Introduction to Object Oriented Programming California State University, Los Angeles Computer Science Department Lecture III Inheritance and Polymorphism Introduction to Inheritance Introduction

More information

COP 3330 Final Exam Review

COP 3330 Final Exam Review COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time

More information

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms

CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING C ++ Basics Review part 2 Auto pointer, templates, STL algorithms CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms AUTO POINTER (AUTO_PTR) //Example showing a bad situation with naked pointers void MyFunction()

More information

CS201 Some Important Definitions

CS201 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 information

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++

I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination. June, 2015 BCS-031 : PROGRAMMING IN C ++ No. of Printed Pages : 3 I BCS-031 BACHELOR OF COMPUTER APPLICATIONS (BCA) (Revised) Term-End Examination 05723. June, 2015 BCS-031 : PROGRAMMING IN C ++ Time : 3 hours Maximum Marks : 100 (Weightage 75%)

More information

Cpt S 122 Data Structures. Course Review Midterm Exam # 2

Cpt S 122 Data Structures. Course Review Midterm Exam # 2 Cpt S 122 Data Structures Course Review Midterm Exam # 2 Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Midterm Exam 2 When: Monday (11/05) 12:10 pm -1pm

More information

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak!

1/29/2011 AUTO POINTER (AUTO_PTR) INTERMEDIATE SOFTWARE DESIGN SPRING delete ptr might not happen memory leak! //Example showing a bad situation with naked pointers CS 251 INTERMEDIATE SOFTWARE DESIGN SPRING 2011 C ++ Basics Review part 2 Auto pointer, templates, STL algorithms void MyFunction() MyClass* ptr( new

More information

Increases Program Structure which results in greater reliability. Polymorphism

Increases Program Structure which results in greater reliability. Polymorphism UNIT 4 C++ Inheritance What is Inheritance? Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the

More information

Lecture 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) 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 information

Friend Functions, Inheritance

Friend Functions, Inheritance Friend Functions, Inheritance Friend Function Private data member of a class can not be accessed by an object of another class Similarly protected data member function of a class can not be accessed by

More information

C++ (Non for C Programmer) (BT307) 40 Hours

C++ (Non for C Programmer) (BT307) 40 Hours C++ (Non for C Programmer) (BT307) 40 Hours Overview C++ is undoubtedly one of the most widely used programming language for implementing object-oriented systems. The C++ language is based on the popular

More information

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.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 information

Object-Oriented Programming for Scientific Computing

Object-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 information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova You reuse code by creating new classes, but instead of creating them from scratch, you use existing classes that someone else has built and debugged. In composition

More information

CS6301 PROGRAMMING AND DATA STRUCTURES II QUESTION BANK UNIT-I 2-marks ) Give some characteristics of procedure-oriented language. Emphasis is on doing things (algorithms). Larger programs are divided

More information

Object Oriented Pragramming (22316)

Object Oriented Pragramming (22316) Chapter 1 Principles of Object Oriented Programming (14 Marks) Q1. Give Characteristics of object oriented programming? Or Give features of object oriented programming? Ans: 1. Emphasis (focus) is on data

More information

CS24 Week 3 Lecture 1

CS24 Week 3 Lecture 1 CS24 Week 3 Lecture 1 Kyle Dewey Overview Some minor C++ points ADT Review Object-oriented Programming C++ Classes Constructors Destructors More minor Points (if time) Key Minor Points const Motivation

More information

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples:

Data type of a pointer must be same as the data type of the variable to which the pointer variable is pointing. Here are a few examples: Unit IV Pointers and Polymorphism in C++ Concepts of Pointer: A pointer is a variable that holds a memory address of another variable where a value lives. A pointer is declared using the * operator before

More information

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

CE221 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 information

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

1. 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 information

G52CPP C++ Programming Lecture 13

G52CPP 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 information

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance Contents Topic 04 - Inheritance I. Classes, Superclasses, and Subclasses - Inheritance Hierarchies Controlling Access to Members (public, no modifier, private, protected) Calling constructors of superclass

More information

Chapter 1: Object-Oriented Programming Using C++

Chapter 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 information

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT

Jayaram college of Engineering and Technology, Pagalavadi. CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT CS2203 Object Oriented Programming Question Bank Prepared By: S.Gopalakrishnan, Lecturer/IT Two Mark Questions UNIT - I 1. DEFINE ENCAPSULATION. Encapsulation is the process of combining data and functions

More information

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017

Inheritance. OOP components. Another Example. Is a Vs Has a. Virtual Destructor rule. Virtual Functions 4/13/2017 OOP components For : COP 3330. Object oriented Programming (Using C++) http://www.compgeom.com/~piyush/teach/3330 Data Abstraction Information Hiding, ADTs Encapsulation Type Extensibility Operator Overloading

More information

Chapter 8. Operator Overloading, Friends, and References. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 8. Operator Overloading, Friends, and References. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 8 Operator Overloading, Friends, and References Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Basic Operator Overloading Unary operators As member functions Friends

More information

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2)

Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Software Paradigms (Lesson 3) Object-Oriented Paradigm (2) Table of Contents 1 Reusing Classes... 2 1.1 Composition... 2 1.2 Inheritance... 4 1.2.1 Extending Classes... 5 1.2.2 Method Overriding... 7 1.2.3

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 603 203 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK B.E. - Electrical and Electronics Engineering IV SEMESTER CS6456 - OBJECT ORIENTED

More information

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University)

JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli (An approved by AICTE and Affiliated to Anna University) Estd: 1994 JAYARAM COLLEGE OF ENGINEERING AND TECHNOLOGY Pagalavadi, Tiruchirappalli - 621014 (An approved by AICTE and Affiliated to Anna University) ISO 9001:2000 Certified Subject Code & Name : CS 1202

More information

CS201 Latest Solved MCQs

CS201 Latest Solved MCQs Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance

CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance CS107 Handout 37 Spring 2007 May 25, 2007 Introduction to Inheritance Handout written by Julie Zelenski, updated by Jerry. Inheritance is a language property most gracefully supported by the object-oriented

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming 1. What is object-oriented programming (OOP)? OOP is a technique to develop logical modules, such as classes that contain properties, methods, fields, and events. An object

More information

Department of Computer science and Engineering Sub. Name: Object oriented programming and data structures Sub. Code: EC6301 Sem/Class: III/II-ECE Staff name: M.Kavipriya Two Mark Questions UNIT-1 1. List

More information

More About Classes. Gaddis Ch. 14, CS 2308 :: Fall 2015 Molly O'Neil

More About Classes. Gaddis Ch. 14, CS 2308 :: Fall 2015 Molly O'Neil More About Classes Gaddis Ch. 14, 13.3 CS 2308 :: Fall 2015 Molly O'Neil Pointers to Objects Just like pointers to structures, we can define pointers to objects Time t1(12, 20, true); Time *tptr; tptr

More information

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat

Kapil Sehgal PGT Computer. Science Ankleshwar Gujarat Classes Chapter 4 Classes and Objects Data Hiding and Encapsulation Function in a Class Using Objects Static Class members Classes Class represents a group of Similar objects A class is a way to bind the

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Object-Oriented Programming

Object-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 information

Pointers and References

Pointers and References Steven Zeil October 2, 2013 Contents 1 References 2 2 Pointers 8 21 Working with Pointers 8 211 Memory and C++ Programs 11 212 Allocating Data 15 22 Pointers Can Be Dangerous 17 3 The Secret World of Pointers

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. QUIZ How

More information

OBJECT ORİENTATİON ENCAPSULATİON

OBJECT ORİENTATİON ENCAPSULATİON OBJECT ORİENTATİON Software development can be seen as a modeling activity. The first step in the software development is the modeling of the problem we are trying to solve and building the conceptual

More information

Concepts of Programming Languages

Concepts of Programming Languages Concepts of Programming Languages Lecture 10 - Object-Oriented Programming Patrick Donnelly Montana State University Spring 2014 Patrick Donnelly (Montana State University) Concepts of Programming Languages

More information

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS JAN 28,2011 MC100401285 Moaaz.pk@gmail.com Mc100401285@gmail.com PSMD01 FINALTERM EXAMINATION 14 Feb, 2011 CS304- Object Oriented

More information

C++ for Java Programmers

C++ for Java Programmers Basics all Finished! Everything we have covered so far: Lecture 5 Operators Variables Arrays Null Terminated Strings Structs Functions 1 2 45 mins of pure fun Introduction Today: Pointers Pointers Even

More information

POINTERS - Pointer is a variable that holds a memory address of another variable of same type. - It supports dynamic allocation routines. - It can improve the efficiency of certain routines. C++ Memory

More information

Object-Oriented Design (OOD) and C++

Object-Oriented Design (OOD) and C++ Chapter 2 Object-Oriented Design (OOD) and C++ At a Glance Instructor s Manual Table of Contents Chapter Overview Chapter Objectives Instructor Notes Quick Quizzes Discussion Questions Projects to Assign

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #12 Apr 3 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline Intro CPP Boring stuff: Language basics: identifiers, data types, operators, type conversions, branching

More information

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University

Lecture 3. COMP1006/1406 (the Java course) Summer M. Jason Hinek Carleton University Lecture 3 COMP1006/1406 (the Java course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments 1 (graded) & 2 3 (available now) & 4 (tomorrow) a quick look back primitive data types

More information

EL2310 Scientific Programming

EL2310 Scientific Programming Lecture 14: Object Oriented Programming in C++ (fpokorny@kth.se) Overview Overview Lecture 14: Object Oriented Programming in C++ Wrap Up Introduction to Object Oriented Paradigm Classes More on Classes

More information

Lecture 14: more class, C++ streams

Lecture 14: more class, C++ streams CIS 330: / / / / (_) / / / / _/_/ / / / / / \/ / /_/ / `/ \/ / / / _/_// / / / / /_ / /_/ / / / / /> < / /_/ / / / / /_/ / / / /_/ / / / / / \ /_/ /_/_/_/ _ \,_/_/ /_/\,_/ \ /_/ \ //_/ /_/ Lecture 14:

More information

CSE 303: Concepts and Tools for Software Development

CSE 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 information

A brief introduction to C++

A 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 information

Object-Oriented Programming, Iouliia Skliarova

Object-Oriented Programming, Iouliia Skliarova Object-Oriented Programming, Iouliia Skliarova CBook a = CBook("C++", 2014); CBook b = CBook("Physics", 1960); a.display(); b.display(); void CBook::Display() cout

More information

Quiz Start Time: 09:34 PM Time Left 82 sec(s)

Quiz Start Time: 09:34 PM Time Left 82 sec(s) Quiz Start Time: 09:34 PM Time Left 82 sec(s) Question # 1 of 10 ( Start time: 09:34:54 PM ) Total Marks: 1 While developing a program; should we think about the user interface? //handouts main reusability

More information

Evolution of Programming Languages

Evolution 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 information

CS105 C++ Lecture 7. More on Classes, Inheritance

CS105 C++ Lecture 7. More on Classes, Inheritance CS105 C++ Lecture 7 More on Classes, Inheritance " Operator Overloading Global vs Member Functions Difference: member functions already have this as an argument implicitly, global has to take another parameter.

More information

CPSC 427: Object-Oriented Programming

CPSC 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 information

Object-Oriented Programming (OOP) Fundamental Principles of OOP

Object-Oriented Programming (OOP) Fundamental Principles of OOP Object-Oriented Programming (OOP) O b j e c t O r i e n t e d P r o g r a m m i n g 1 Object-oriented programming is the successor of procedural programming. The problem with procedural programming is

More information

CGS 2405 Advanced Programming with C++ Course Justification

CGS 2405 Advanced Programming with C++ Course Justification Course Justification This course is the second C++ computer programming course in the Computer Science Associate in Arts degree program. This course is required for an Associate in Arts Computer Science

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

CS250 Final Review Questions

CS250 Final Review Questions CS250 Final Review Questions The following is a list of review questions that you can use to study for the final. I would first make sure that you review all previous exams and make sure you fully understand

More information

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli

Learning Objectives. C++ For Artists 2003 Rick Miller All Rights Reserved xli Identify and overcome the difficulties encountered by students when learning how to program List and explain the software development roles played by students List and explain the phases of the tight spiral

More information

QUIZ. How could we disable the automatic creation of copyconstructors

QUIZ. How could we disable the automatic creation of copyconstructors QUIZ How could we disable the automatic creation of copyconstructors pre-c++11? What syntax feature did C++11 introduce to make the disabling clearer and more permanent? Give a code example. Ch. 14: Inheritance

More information