CS250 Final Review Questions

Similar documents
CS250 Final Review Questions

CS250 Final Review Questions

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

Midterm Exam 5 April 20, 2015

Short Notes of CS201

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

CS201 - Introduction to Programming Glossary By

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

CS201- Introduction to Programming Current Quizzes

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

Object Oriented Programming. Solved MCQs - Part 2

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


PIC10B/1 Winter 2014 Exam I Study Guide

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

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

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

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

Programming, numerics and optimization

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

CS201 Some Important Definitions

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

CSE 303: Concepts and Tools for Software Development

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

G52CPP C++ Programming Lecture 13

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

Common Misunderstandings from Exam 1 Material

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

Inheritance, and Polymorphism.

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

Vectors of Pointers to Objects. Vectors of Objects. Vectors of unique ptrs C++11. Arrays of Objects

pointers & references

Objectives. INHERITANCE - Part 1. Using inheritance to promote software reusability. OOP Major Capabilities. When using Inheritance?

INHERITANCE - Part 1. CSC 330 OO Software Design 1

C++ Important Questions with Answers

CISC 2200 Data Structure Fall, C++ Review:3/3. 1 From last lecture:

OBJECT ORIENTED PROGRAMMING

CS 247: Software Engineering Principles. ADT Design

Introduction to Programming Using Java (98-388)

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

Polymorphism. Miri Ben-Nissan (Kopel) Miri Kopel, Bar-Ilan University

CSCE 110 PROGRAMMING FUNDAMENTALS

VIRTUAL FUNCTIONS Chapter 10

C++ (classes) Hwansoo Han

Absolute C++ Walter Savitch

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:

Note 12/1/ Review of Inheritance Practice: Please write down 10 most important facts you know about inheritance...

Come and join us at WebLyceum

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

Lecture 10: Introduction to Inheritance

! Determine if a number is odd or even. ! Determine if a number/character is in a range. ! Assign a category based on ranges (wind speed)

Fast Introduction to Object Oriented Programming and C++

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

Intro to OOP Visibility/protection levels and constructors Friend, convert constructor, destructor Operator overloading a<=b a.

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

Week 8: Operator overloading

Come and join us at WebLyceum

Suppose we find the following function in a file: int Abc::xyz(int z) { return 2 * z + 1; }

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

Chapter 15: Inheritance, Polymorphism, and Virtual Functions

CS427 Inheritance and Virtual Functions. Linked lists. 2/27. 01Replacement.cpp link! i n t GetY ( void ) { return ( y ) ; } ;

Operator overloading

Abstract Data Types (ADT) and C++ Classes

CS 376b Computer Vision

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

! Determine if a number is odd or even. ! Determine if a number/character is in a range. - 1 to 10 (inclusive) - between a and z (inclusive)

For Teacher's Use Only Q No Total Q No Q No

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

CS 115 Exam 3, Spring 2010

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

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

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

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

VALLIAMMAI ENGINEERING COLLEGE

Lecture 13: more class, C++ memory management

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

C++ Inheritance and Encapsulation

Object-Oriented Principles and Practice / C++

Polymorphism Part 1 1

6.096 Introduction to C++ January (IAP) 2009

CS24 Week 3 Lecture 1

INHERITANCE - Part 1. CSC 330 OO Software Design 1

Subtyping (Dynamic Polymorphism)

An Introduction to C++

Assumptions. History

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

CMSC 341 Lecture 10 Binary Search Trees

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

Abstraction in Software Development

Scott Gibson. Pointers & Dynamic Memory. Pre & Co Requisites. Random Access Memory. Data Types. Atomic Type Sizes

Documentation. Programming / Documentation Slide 42

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

Inheritance and aggregation

G Programming Languages - Fall 2012

2015 Academic Challenge

G52CPP C++ Programming Lecture 14. Dr Jason Atkin

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

IS0020 Program Design and Software Tools Midterm, Fall, 2004

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 17: Types and Type-Checking 25 Feb 08

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 that 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 pointer & reference variable and the differences between the two object-oriented programming operator overloading friend implicit operand & explicit operand runtime stack, heap, activation record and how they are used constructor, destructor, copy constructor 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?)

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 traversing a 2D array by rows or by columns, passing 2D arrays 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 &spt) cout << spt.x << " " << spt.y; e) Structure Variables - comparing, displaying, initializing, using a constructor with no arguments, using a constructor with arguments, returning a struct from a function 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 (); // 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)cout << Base << i << endl; ~Base()cout << Destruct Base << endl; class Der: public Base Der()cout << Der << endl; Der(int i): Base(i) cout << Der << i << endl; ~Der()cout << Destruct Der << endl; int main() Base a; Der d(2); return 0;

Polymorphism What is the difference between overloading a function, overriding, and redefining a function? 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.) Destructor 1. What is a destructor and when is a destructor called? 2. Why would you want to have a destructor? 3. When is a virtual destructor necessary?

Pointers & dynamic memory allocation 1. Dynamic Class: o Create a class that has a single pointer to double variable. o Write a constructor that dynamically allocates space for the double and initializes the double to the value passed to the constructor. o Write the appropriate copy constructor o Why must there be a copy constructor? o Do any operators need to be overloaded? o Write a set and get method for the double. o Write a method getwhole that returns the value to the left of the decimal point. o Write a method getfractional that returns the value to the right of the decimal point. 2. Write a function isstrequal that accepts two null terminated strings (type char *) and returns true if the two strings are identical; otherwise, false is returned. Use pointer notation. o What does a call to your function look like? o Write the function. 3. What is the difference between the two prototypes below? void processarray (const char *ptext); void processarray (char * const ptext); 4. Consider the interface for class Word below where mdata is NOT nullterminated. The number of actual characters contained in mdata is held in the variable mlength. class Word static const int MAX_SIZE = 256; Word (); // Set Word to size zero Word (const char *); // The char * passed to Word IS null terminated Word (const Word &); friend ostream &operator<< (ostream &, const Word &); private: char mdata[max_size]; int mlength; Implement all of the constructors and operator<<. Will the following program compile? If so, what is the output? If not, why not?

There is a difference in how C++ assigns a value for cword3 and cword4 in the code above. Explain the difference in detail. Create a Dictionary class that is able to hold up to 1024 Words. Implement a method add that accepts a Word and adds the word to the dictionary if the word isn t already in the dictionary. 5. Consider the class Point class Point Point (double = 0.0, double = 0.0); void setx (double); double getx () const; void sety (double); double gety () const; friend ostream &operator<< (ostream &, const Point &); private: double mx, my; A Polygon is an abstract class capable of holding up to 1024 points. Write the interface for Polygon that has appropriate constructor(s), an add method, an overloaded insertion operator, virtual functions draw and perimeter, and a pure virtual function area. Triangle is a concrete class that inherits from Polygon and is to have all of the functionality of a Polygon as well an implementation for area. Also, a Triangle is to have a method isright. Write the interface for Triangle. Important: Once a triangle is created, one shouldn t be able to change the triangle into something else (say a Rectangle).

Rectangle is a concrete class that inherits from Polygon and is to have all of the functionality of a Polygon as well an implementation for area. Write the interface for Rectangle. Important: Once a rectangle is created, one shouldn t be able to change the rectangle into something else. Create an array of up to 25 Polygon pointers that can point to a Triangle or a Rectangle. Assuming that the array of polygon pointers is pointing to numpolygon objects, output the area for each object.