CISC181 Introduction to Computer Science Dr

Slides:



Advertisements
Similar presentations
Chapter 4 Constructors and Destructors. Objectives Constructors – introduction and features The zero-argument constructor Parameterized constructors Creating.
Advertisements

Linked List 1. Introduction to Linked List 2. Node Class 3. Linked List 4. The Bag Class with Linked List.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Introduction to Programming Lecture 39. Copy Constructor.
1 Linked List (II) Ying Wu Electrical Engineering & Computer Science Northwestern University EECS 230 Lectures Series.
A RRAYS, P OINTERS AND R EFERENCES 1. A RRAYS OF O BJECTS Arrays of objects of class can be declared just like other variables. class A{ … }; A ob[4];
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
 2006 Pearson Education, Inc. All rights reserved Data Structures.
Linked List (I) Ying Wu Electrical & Computer Engineering Northwestern University ECE230 Lectures Series.
Review of C++ Programming Part II Sheng-Fang Huang.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Chapter 12 Data Structure Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
 2003 Prentice Hall, Inc. All rights reserved Linked Lists Upcoming program has two class templates –Create two class templates –ListNode data.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Custom Templatized Data Structures.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Pointers OVERVIEW.
 2008 Pearson Education, Inc. All rights reserved. 1 Member data stores a value of type parameter NODETYPE Member nextPtr stores a pointer to the next.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Self-Referential Classes A Self-referential class is a class that contains a reference to an object that has the same class type. –A self-referential class.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
Lecture 3 Classes, Structs, Enums Passing by reference and value Arrays.
Review of Stacks and Queues Dr. Yingwu Zhu. How does a Stack Work? Last-in-First-out (LIFO) data structure Adding an item Push operation Removing an item.
1 Chapter 17 – Data Structures Outline Introduction Self-Referential Classes Dynamic Memory Allocation Linked Lists Stacks Queues Trees.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 20 November 10, 2009.
Structs and Classes Structs A struct can be used to define a data structure type as follows: struct Complex { double real, imag;} // specifying a Complex.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 26 Clicker Questions December 3, 2009.
1 Linked Multiple Queues. 2 A real world example. Not in the book. Sometimes we have a fixed number of items that move around among a fixed set of queues.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
1 Ugly Realities The Dark Side of C++ Chapter 12.
Constructors and Destructors
Pointers and Dynamic Arrays
Learning Objectives Pointers as dada members
C++ Programming:. Program Design Including
CS505 Data Structures and Algorithms
Chapter 12 – Data Structures
5.13 Recursion Recursive functions Functions that call themselves
Linked Lists Chapter 6 Section 6.4 – 6.6
CS410 – Software Engineering Lecture #11: C++ Basics IV
Pointers Revisited What is variable address, name, value?
LinkedList Class.
This pointer, Dynamic memory allocation, Constructors and Destructor
group work #hifiTeam
Dynamic Memory Allocation
Classes with Dynamically Allocated Data
Introduction to Classes
Chapter 18: Linked Lists.
Chapter 15 Pointers, Dynamic Data, and Reference Types
[Chapter 4; Chapter 6, pp ] CSC 143 Linked Lists [Chapter 4; Chapter 6, pp ]
Chapter 15 Pointers, Dynamic Data, and Reference Types
Constructors and Destructors
Review & Lab assignments
CISC181 Introduction to Computer Science Dr
CS148 Introduction to Programming II
Stacks and Queues.
Class and Objects In a class, all the functions that operate on the data structure are grouped together in one place along with the data Like a struct.
Linked Lists.
Dynamic Memory.
Recitation Course 0520 Speaker: Liu Yu-Jiun.
Data Structures & Algorithms
CS410 – Software Engineering Lecture #5: C++ Basics III
Dynamic allocation (continued)
Data Structures and Algorithms Memory allocation and Dynamic Array
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
ENERGY 211 / CME 211 Lecture 30 December 5, 2008.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
CS148 Introduction to Programming II
More C++ Classes Systems Programming.
21 Data Structures.
Presentation transcript:

CISC181 Introduction to Computer Science Dr CISC181 Introduction to Computer Science Dr. McCoy Lecture 24 Clicker Questions November 24, 2009

int main() { CreateDestroy c1; CreateDestroy c2; return 0; } Given the class definition class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "destructor called, "; } }; What will the following program output? int main() { CreateDestroy c1; CreateDestroy c2; return 0; }

Given the class definition class CreateDestroy { public: CreateDestroy() { cout << "constructor called, "; } ~CreateDestroy() { cout << "destructor called, "; } }; What will the following program output? int main() { CreateDestroy c1; CreateDestroy c2; return 0; } (a) constructor called, destructor called, constructor called, destructor called. (b) constructor called, destructor called. (c) constructor called, constructor called. (d) constructor called, constructor called, destructor

The assignment operator (=) can be used to (a) test for equality The assignment operator (=) can be used to (a) test for equality. (b) copy the data from one object to another. (c) compare two objects. (d) copy a class.

If the line friend class A; appears in class B, and friend class B; appears in class C then (a) class A is a friend of class C. (b) class A can access private variables of class B. (c) class C can call class A’s private member functions. (d) class B can access class A’s private variables.

Linked lists allow (a) insertions and removals anywhere (b) insertions and removals only at one end (c) insertions at the back and removals from the front (d) none of the above

The __________ operator takes as an argument the type of object being allocated and returns a __________. (a) new, pointer to an object of that type (b) new, reference to an object of that type (c) new, copy of the object of that type (d) sizeof, pointer

__________ is not an advantage of linked lists when compared to arrays __________ is not an advantage of linked lists when compared to arrays. (a) Dynamic memory allocation (b) Efficient insertion and deletion (c) Direct access to any list element (d) Efficient use of memory

Which of the following is false about the new operator and the object it allocates memory for? (a) it calls the object’s constructor. (b) it returns a pointer. (c) it does not require size of the object to be specified. (d) it automatically destroys the object after main is exited.

For a non-empty linked list, select the code that should appear in a function that adds a node to the end of the list. newPtr is a pointer to the new node to be added, and lastPtr is a pointer to the current last node. Each node contains a pointer nextPtr, which is a link to a node.

Add a node to the end of the list: (a) lastPtr->nextPtr = newPtr; lastPtr = newPtr; (b) lastPtr = newPtr; lastPtr->nextPtr = newPtr; (c) newPtr->nextPtr = lastPtr; (d) lastPtr = newPtr; newPtr->nextPtr = lastPtr;

Given the line delete newPtr; what can you conclude Given the line delete newPtr; what can you conclude? (a) The memory referenced by newPtr is released only if it is needed by the system. (b) newPtr is of type void *. (c) newPtr only exists if there was an error freeing the memory. (d) newPtr still exists.

(a) insertAtBack and removeFromBack. A linked list has the functions insertAtFront, removeFromFront, insertAtBack, and removeFromBack, which perform operations on nodes exactly as their names describe. Which two functions would most naturally model the operation of a queue? (a) insertAtBack and removeFromBack. (b) insertAtBack and removeFromFront. (c) insertAtFront and removeFromFront. (d) insertAtFront and removeFromBack.

Which of the following statements will not produce a syntax error Which of the following statements will not produce a syntax error? (a) defining a const member function that modifies a data member of an object. (b) invoking a non-const member function on a const object. (c) declaring an object to be const. (d) declaring a constructor const.

The delete operator (a) can terminate the program The delete operator (a) can terminate the program. (b) can delete an entire array of objects declared using new. (c) must be told which destructor to call when destroying an object. (d) is called implicitly at the end of a program.

The code fragment Increment::Increment(int c, int i) : increment (i) { count = c; } tells you (a) Increment is a const variable. (b) Increment must be a const function. (c) increment may or may not be a destructor. (d) increment may be a const variable.

When composition (one object having another object as a member) is used (a) the host object is constructed first and then the member objects are placed into it (b) member objects are constructed first, in the order they appear in the host constructor’s initializer list (c) member objects are constructed first, in the order they are declared in the host’s class (d) member objects are constructed last, in the order they are declared in the host’s class