1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.

Slides:



Advertisements
Similar presentations
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.
Advertisements

1 Pointers Lecture Introduction Pointers  Powerful, but difficult to master  Simulate pass-by-reference  Close relationship with arrays and.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Kernighan/Ritchie: Kelley/Pohl:
1 Pointers A pointer variable holds an address We may add or subtract an integer to get a different address. Adding an integer k to a pointer p with base.
Pointers and Strings. Introduction Pointers –Powerful, but difficult to master –Simulate call-by-reference –Close relationship with arrays and strings.
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Road Map Introduction to object oriented programming. Classes
Lesson 6 - Pointers Outline Introduction Pointer Variable Declarations and Initialization Pointer Operators Calling Functions by Reference Using the const.
 2006 Pearson Education, Inc. All rights reserved Midterm review Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Arrays.
 2006 Pearson Education, Inc. All rights reserved Pointers.
Classes: A Deeper Look Systems Programming.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Review of C++ Programming Part II Sheng-Fang Huang.
Classes Mark Hennessy Dept. Computer Science NUI Maynooth C++ Workshop 18 th – 22 nd Spetember 2006.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
Pointer Data Type and Pointer Variables
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
 2006 Pearson Education, Inc. All rights reserved Arrays.
More C++ Classes Systems Programming. C++ Classes  Preprocessor Wrapper  Time Class Case Study –Two versions (old and new)  Class Scope and Assessing.
CS212: Object Oriented Analysis and Design Lecture 6: Friends, Constructor and destructors.
 2007 Pearson Education, Inc. All rights reserved C Pointers.
CS212: Object Oriented Analysis and Design Lecture 12: Operator Overloading-II.
 2006 Pearson Education, Inc. All rights reserved Classes: A Deeper Look, Part 2.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Pointers and Dynamic Memory Allocation Copyright Kip Irvine 2003, all rights reserved. Revised 10/28/2003.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
1 Pointers and Strings Chapter 5 2 What You Will Learn...  How to use pointers Passing arguments to functions with pointers See relationship of pointers.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Object Oriented Programming Elhanan Borenstein Lecture #3 copyrights © Elhanan Borenstein.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 12 - Templates Outline 12.1Introduction 12.2Function Templates 12.3Overloading Template Functions.
 2000 Deitel & Associates, Inc. All rights reserved Introduction Pointers –Powerful, but difficult to master –Simulate call-by-reference –Close.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
C++ Programming Lecture 17 Pointers – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 7 - Pointers Outline 7.1Introduction 7.2Pointer.
Computer Organization and Design Pointers, Arrays and Strings in C Montek Singh Sep 18, 2015 Lab 5 supplement.
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 14: Pointers.
1 Classes II Chapter 7 2 Introduction Continued study of –classes –data abstraction Prepare for operator overloading in next chapter Work with strings.
CPS120: Introduction to Computer Science Lecture 16 Data Structures, OOP & Advanced Strings.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Chapter 1 C++ Basics Review (Section 1.4). Classes Defines the organization of a data user-defined type. Members can be  Data  Functions/Methods Information.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 26 Clicker Questions December 3, 2009.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
Pointers in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Programming Fundamentals1 Chapter 7 INTRODUCTION TO CLASSES.
Chapter 7 Pointers Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
C++ for Engineers and Scientists Second Edition Chapter 12 Pointers.
Pointers and Dynamic Arrays
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
CISC181 Introduction to Computer Science Dr
8 Pointers.
CS212: Object Oriented Analysis and Design
Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes
Pointers, Dynamic Data, and Reference Types
CISC181 Introduction to Computer Science Dr
7 Arrays.
CISC181 Introduction to Computer Science Dr
More C++ Classes Systems Programming.
SPL – PS2 C++ Memory Handling.
Presentation transcript:

1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009

If a class is named MyClass, what must theconstructors be named? (a) Initializer (b) MyClass (c)Any name the programmer wishes except the name of the class (d)~MyClass (e)None of the above. 2

Referencing elements outside the array bounds (a) can result in changes to the value of an unrelated variable (b) is impossible because C++ checks to make sure it does not happen (c) is a syntax error (d) enlarges the size of the array 3

True/False Pointer variables are just memory addresses and can be assigned to one another without regard to type. 4

True/False Pointer variables are just memory addresses and can be assigned to one another without regard to type. Answer: False Explanation: A pointer variables, like everything else in C++ is typed, and that typing is enforced strongly. A pointer variable of type double* cannot normally hold a pointer value of type int* for example. 5

Strings cannot (a) be initialized using string literals (b) grow or shrink dynamically (c) be initialized with initializer lists (d) be treated as arrays of characters 6

Three of the following expressions have the same value. Which of the following’s value is different from the others? (a) *&Ptr (b) &*Ptr (c) *Ptr (d) Ptr 7

An array name is (a) a nonconstant pointer to nonconstant data (b) a nonconstant pointer to constant data (c) a constant pointer to nonconstant data (d) a constant pointer to constant data 8

A class may contain multiple constructors if (a) they have different names. (b) they have different argument lists. (c) they have the same argument list. (d) they have different return types. 9

Classes do not have the property of (a) encapsulating data. (b) information hiding. (c) containing both data and functions. (d) usually knowing how other classes are implemented. 10

Assuming that t is an array and tPtr is a pointer to that array, what expression refers to the address of the fourth element? (a) *( tPtr + 3 ) (b) tPtr[ 3 ] (c) &t[ 3 ] (d) *( t + 3 ) 11

Which of the following is not true of a constructor and destructor of the same class? (a) they both have same name aside from the tilde (~) character. (b) they are both called once per object (in general). (c) they both are able to accept default arguments. (d) both are called automatically, even if not defined in the class. 12

Which of the following is not a valid way to pass arguments to a function in C++? (a) call-by-reference with reference arguments (b) call-by-value (c) call-by-reference with pointer arguments (d) call-by-value with pointer arguments 13

In the following program segment #ifndef X rest of program #endif (a) will evaluate the rest of the program if X is already defined. (b) will evaluate the rest of the program if X is not already defined. (c) will evaluate the rest of the program regardless of whether X is defined. (d) will cause a syntax error. 14

The get and set functions of a class (a) are implicitly defined in the class. (b) are private member functions. (c) cannot modify private data. (d) must be implemented by the programmer. 15

Member access specifiers (public and private) can appear (a) in any order and multiple times. (b) in any order (public first or private first) but not multiple times. (c) in any order and multiple times, if they have brackets separating each type. (d) outside a class definition. 16

Which of the following is false about a function being passed an array? (a) it knows the size of the array it was passed (b) it is passed the address of the first element in the array (c) it is able to modify the values stored in the array (d) the array name is passed as an argument 17

Which of the following operations does not produce a string? (a) char string1[] = “test”; (b) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’, ‘\0’ }; (c) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’ }; (d) char string1[] = “ ”; 18

Comparing pointers and performing arithmetic on them is meaningless unless (a) they point to members of the same array (b) you are trying to compare and perform arithmetic on the values to which they point (c) they point to arrays of equal size (d) they point to different locations 19

A default constructor (a) is a constructor with all default arguments (b) is the constructor generated by the compiler when one is not provided by the programmer (c) does not perform any initialization (d) both (b) and (c) 20

What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number <= 1 ) return 1; else return number * mystery( number – 1 ); } (a) 1 (b) 24 (c) 0 (d) 4 21

True/False There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new. 22

True/False There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new. Answer: True Explanation: Pointer variables are usually local variables. Memory allocated on the free store using the new operator remains allocated whether you use it or even have a pointer pointing to it. If the pointer that points to the allocated memory dies with the end of a function or a block, the memory allocated is locked away so that no one can use it until the program terminates. 23

All of the following could cause a fatal execution-time error except (a) dereferencing a pointer that has not been assigned to point to a specific address (b) dereferencing a pointer that has not been initialized properly (c) dereferencing a 0 pointer (d) dereferencing a nonpointer 24

Classes cannot (a) be derived from other classes. (b) initialize data members in the class definition. (c) be used to model attributes and behaviors of objects. (d) include objects from other classes as members. 25

Which of the following is not a property of structs? (a) structs reserve space in memory when they are defined. (b) structs are built using elements of other data types. (c) Members of a struct must have unique names. (d) Structure variables are declared like other variables, except the structure name is used as the type. 26

Member function definitions (a) always require the binary scope operator (::). (b) only require the binary scope operator when being defined outside of the scope of their class. (c) can use the binary scope operator anywhere, but become public functions. (d) must use the binary scope operator in their function prototype. 27

When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to (a) int a (b) int &a (c) int * a (d) int * const a 28

By default, class variables declared without an access modifier (a) can be modified by functions outside the class. (b) cannot be modified except by private functions of other classes. (c) can only be modified by private functions inside that class. (d) can be modified by any function inside that class or by friends of the class. 29

A recursive function is a function that (a) returns a double (b) takes 3 arguments (c) calls itself (d) is inside of another function 30

Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? (a) 2003 (b) 2006 (c) 2012 (d)

The type of function a client would use to check the balance of his bank account would be (a) an access function. (b) a predicate function. (c) a utility function. (d) a constructor. 32

Which of the following can have a pointer as an operand? (a) ++ (b) *= (c) % (d) / 33

True/False The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*) double* p1, p2, p3; 34

True/False The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*) double* p1, p2, p3; Answer: False Explanation: This declares one pointer variable, p1, and two double variables, p2 and p3. The * binds more closely to the variable, not to the type. In spite of this, the usually style puts the asterisk against the type. 35

Pointers may be assigned to which of the following? (a) all integer values (b) an address (c) NULL (d) both (b) and (c) 36

Constructors are not (a) required to be explicitly defined. (b) called automatically when an object is initialized. (c) able to be overloaded. (d) member functions. 37

A pointer can not be assigned to (a) another pointer of the same type (b) a pointer to void (c) a pointer of a type other than its own type and void (d) any other pointer by using the cast operator 38