CS250 Final Review Questions

Similar documents
CS250 Final Review Questions

CS250 Final Review Questions

PIC10B/1 Winter 2014 Exam I Study Guide

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

Midterm Exam 5 April 20, 2015

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

Short Notes of CS201

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

CS201 - Introduction to Programming Glossary By

CSE 303: Concepts and Tools for Software Development

Object Oriented Programming. Solved MCQs - Part 2

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

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:

CLASSES AND OBJECTS IN JAVA

Absolute C++ Walter Savitch

VIRTUAL FUNCTIONS Chapter 10

CS 11 C++ track: lecture 1

Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

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


ECE 2400 Computer Systems Programming Fall 2017 Topic 14: C++ Inheritance

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

Chapter 5 Object-Oriented Programming

Chapter 15: Inheritance, Polymorphism, and Virtual Functions

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

G Programming Languages - Fall 2012

Inheritance, and Polymorphism.

Midterm Review. PIC 10B Spring 2018

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

G52CPP C++ Programming Lecture 13

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

C++ Important Questions with Answers

CS32 - Week 4. Umut Oztok. Jul 15, Umut Oztok CS32 - Week 4

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

CS 376b Computer Vision

Passing arguments to functions by. const member functions const arguments to a function. Function overloading and overriding Templates

(12-1) OOP: Polymorphism in C++ D & D Chapter 12. Instructor - Andrew S. O Fallon CptS 122 (April 3, 2019) Washington State University

Abstract Data Types (ADTs) 1. Legal Values. Client Code for Rational ADT. ADT Design. CS 247: Software Engineering Principles

C++ Review. CptS 223 Advanced Data Structures. Larry Holder School of Electrical Engineering and Computer Science Washington State University

More C++ : Vectors, Classes, Inheritance, Templates

CS201- Introduction to Programming Current Quizzes

Programming C++ Lecture 3. Howest, Fall 2012 Instructor: Dr. Jennifer B. Sartor

Software Engineering Concepts: Invariants Silently Written & Called Functions Simple Class Example

More C++ : Vectors, Classes, Inheritance, Templates. with content from cplusplus.com, codeguru.com

C++ Inheritance and Encapsulation

CS 247: Software Engineering Principles. ADT Design

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

COMP6771 Advanced C++ Programming

Lesson Plan. Subject: OBJECT ORIENTED PROGRAMMING USING C++ :15 weeks (From January, 2018 to April,2018)

CGS 2405 Advanced Programming with C++ Course Justification

Financial computing with C++

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

ECE 449 OOP and Computer Simulation Lecture 14 Final Exam Review

C++ Constructs by Examples

Object Oriented Design Final Exam (From 3:30 pm to 4:45 pm) Name:

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

CSCI 102L - Data Structures Midterm Exam #1 Fall 2011

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

Object oriented programming. Encapsulation. Polymorphism. Inheritance OOP

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

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

Object Oriented Programming. Java-Lecture 11 Polymorphism

Why use inheritance? The most important slide of the lecture. Programming in C++ Reasons for Inheritance (revision) Inheritance in C++

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,

Come and join us at WebLyceum

POLYMORPHISM 2 PART. Shared Interface. Discussions. Abstract Base Classes. Abstract Base Classes and Pure Virtual Methods EXAMPLE

POLYMORPHISM 2 PART Abstract Classes Static and Dynamic Casting Common Programming Errors

C++ Addendum: Inheritance of Special Member Functions. Constructors Destructor Construction and Destruction Order Assignment Operator

CMSC202 Computer Science II for Majors

Distributed Real-Time Control Systems. Lecture 14 Intro to C++ Part III

Design issues for objectoriented. languages. Objects-only "pure" language vs mixed. Are subclasses subtypes of the superclass?

COMP6771 Advanced C++ Programming

CSE 333. Lecture 10 - references, const, classes. Hal Perkins Paul G. Allen School of Computer Science & Engineering University of Washington

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

EL2310 Scientific Programming

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

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

Subtyping (Dynamic Polymorphism)

CS11 Introduction to C++ Fall Lecture 7

Object-Oriented Principles and Practice / C++

Cpt S 122 Data Structures. Course Review FINAL. Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University

Lecture Notes on Programming Languages

From Java to C++ From Java to C++ CSE250 Lecture Notes Weeks 1 2, part of 3. Kenneth W. Regan University at Buffalo (SUNY) September 10, 2009

Polymorphism Part 1 1

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

Data Abstraction. Hwansoo Han

Instantiation of Template class

CS201 Some Important Definitions

Object Oriented Programming in C++

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

CSC1322 Object-Oriented Programming Concepts

Object-Oriented Concept

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

OOP THROUGH C++(R16) int *x; float *f; char *c;

G Programming Languages Spring 2010 Lecture 9. Robert Grimm, New York University

ECE 3574: Dynamic Polymorphism using Inheritance

VALLIAMMAI ENGINEERING COLLEGE

Rushikesh K Joshi. Department of Computer Science and Engineering Indian Institute of Technology Bombay

dynamically allocated memory char* x = new char; int* x = new int[n]; ???...?

Transcription:

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 you review all previous exams and make sure you fully understand everything on each of those exams. Then review your lecture notes for the course, and finally work through as many of these topics as you feel is necessary. This is not a comprehensive list of terms and examples, just what I had time to put together for you to use as a study guide. Important Terminology struct & class and the differences between the two class & object and the differences between the two public vs private vs protected pointers to static data and dynamic data array notation vs pointer notation especially pointers to string data object-oriented programming operator overloading friend implicit operand & explicit operand runtime stack, heap, activation record and how they are used constructor, destructor this, *this, this-> static variables inheritance polymorphism abstract class derived class concrete class superclass and subclass virtual function vs a pure virtual function (how are they different? when would you use one over the other?) overloading vs overriding vs redefining Arrays a) Initializing int values[] = 5, 4, 3, 2, 1; int i = 2; b) Accessing cout << values[i]++; cout << values[i++]; cout << values[++i]; c) As arguments void swap (int &i, int &j) int t = i; i = j; j = t;

swap (values[2], values[3]); swap (values[4], values[4]); d) Array manipulation - finding largest value, smallest value, exchanging elements, inserting a value into an array in an arbitrary location. Array manipulation can be code segments or as functions and may require pointer notation. e) Parallel arrays - copying one array to another, are two arrays the same, append one array on the end of another, storing related information into parallel arrays, searching and returning data in parallel arrays f) Two-dimensional arrays initializing, accessing, traversing a 2D array by rows or by columns, passing 2D arrays (or array elements) to functions, average values in a row or a column or down the diagonal Structures a) Declare struct Point double x, y; ; b) Define Point spt; c) Access spt.x = 2; d) As argument void printpoint (const Point &rspt) cout << rspt.x << " " << rspt.y; e) Structure Variables - comparing, displaying, initializing f) No unions g) Arrays of structs - loading an array of structs from a file, searching, inserting into, deleting from Classes a) Declare class Point private: double x, y; Point (double x, y); // constructor Point (); // default constructor

void setx (double); // mutator void sety (double); // mutator void printpt () const; // accessor ; b) Define Point cpt, *pcpt = new Point; c) Access cpt.setx (4.5); d) Defining Member function void Point::setX (double xcoord) x = xcoord; e) Class Variable - comparing, displaying, initializing, using a constructor with no arguments, using a constructor with arguments f) What is object-oriented programming? Inheritance Show the output of the following program: class Base Base ()cout << Base << endl; Base (int i)std::cout << Base << i << std::endl; ~Base()std::cout << Destruct Base << std::endl; ; class Der: public Base Der ()std::cout << Der << std::endl; Der (int i): Base(i) std::cout << Der << i << std::endl; ~Der ()std::cout << Destruct Der << std::endl; ; int main() Base a; Der d(2); return 0;

Polymorphism Using the three classes defined next, answer parts a c. class Automobile Automobile(); virtual string getname() const = 0; virtual string gettype() const; string getcolor() const;... ; class Car : public Automobile Car(); virtual string getname() const; virtual string gettype() const; virtual string getcolor() const; virtual void driveme();... ; class Sedan : public Car virtual string gettype() const; virtual void driveme();... ; a. What is the problem with the following statement? Automobile anauto; b. Are there any problems with the code snippet below? Why or why not? void drive (Car somecar) somecar.driveme(); int main( ) Sedan sedan; drive (sedan); return 0;

c. For the statements listed below (1-4), indicate the class from which the function will be called (i.e. Sedan, Car, or Automobile) Sedan sedan; Car car; Automobile *p1 = &sedan; Automobile *p2 = &car; cout << sedan.getcolor() << endl; // (1) cout << p1->gettype() << endl; // (2) cout << p2->getcolor() << endl; // (3) cout << car.getcolor() << endl; // (4) Operator overloading Declare a class named Triple with three private data members (floats) x, y, and z. Provide public functions for setting and getting values of all the private data members. Define a constructor that initializes the values to user-specified values or, by default, sets the values all equal to 0. Also overload the following operators: Addition so that corresponding elements are added together Output so that it displays the Triple in the form The triple is (x, y, z). Post-increment so that x and z are increased by one each. Static variables Write a class that contains two class data members numborn and numliving. The value of numborn should be equal to the number of objects of the class that have been instanced. The value of numliving should be equal to the total number of objects in existance currently (ie, the objects that have been constructed but not yet destructed.) Explain why a static member function of a class shouldn t try to access a this variable. Destructor What is a destructor and when is a destructor called? Why would you want to have a destructor? When is a virtual destructor necessary? Pointers & dynamic memory allocation Consider the following C++ program:

class Base void show () std::cout << "Base class"; ; class Derived:public Base void show () std::cout << "Derived Class"; int main () Base* b; Derived d; b = &d; b->show (); Does the above example contain any static binding? If so, what? Does the above example contain any dynamic binding? If so, what? Is show overloaded, overridden, or redefined? Explain. Make sure you know how to make show overloaded, overridden, and redefined? What is a memory leak? Create a memory leak.