CS 246 Howell Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

How are member functions accessed using pointers, cbv, and references?

-> (pointers) . (cbv and references)

What are the advantages of new/delete?

-New automatically allocates enough memory to hold object of specified type... no sizeof -New automatically returns a pointer to the type... no type cast needed -They can both be overloaded

Comments in C?

/* */

Comments in C++?

//

How many parameters does an overloaded unary member function have

0

How many parameters does an overloaded binary member function have

1

How many parameters does an overloaded unary friend function have

1

How many parameters does an overloaded binary friend function have

2

What library allows us to use cin and cout?

<iostream>

How does returning an object work?

A function returns a temporary object that holds the return value. The temporary copy is destroyed after the value has been returned.

What happens when the access specifier for a base class is private?

All public and protected members of the base class become private members of the derived class

What happens when the access specifier for a base class is public?

All public members of the base become public members of the derived class All protected members of the base become protected members of the derived

Overloading

An example of runtime polymorphism

What was the second method in programming

Assembly Language (1951, gibberish code)

Who invented C++

Bjarne Stroustrup in 1979 at Bell Labs in Murray Hill, New Jersey

List the disadvantage of using CBR

Call-by-reference and call-by-value code is identical

What is the GIVEN definition of an object

Data and the code to manipulate that data bound or linked together (An instance of a class)

When are copy constructors called?

During initialization (NOT assignment)

What happens when you increment an object (ob1++)?

Error unless the ++ is correctly overloaded

Who is the author of our book and what did he do?

Herbert Schildt He was on the ANSI/ISO standardization committee for C++

What was the third method in programming

High level (FORTRAN, COBOL)

What happens when we set ob1 to ob2 (ob1=ob2)

If they are of the same class, ob1 will become an exact bitwise copy of ob2.

Can derived classes inherit friend functions?

No

Can overloaded operators change precedence?

No

When we define a class is memory allocated?

No

C++ the only OO language?

No (Java, C#, etc)

What was the fifth method in programming

OOP (C++ 1989 etc)

OO, OOP, OOPL

Object Oriented, Object-Oriented Programing, Object-Oriented Programming Language

Polymorphism

One interface, multiple methods

How can we prevent damaging an object's memory?

Pass the parameter by reference Create and pass copy constructor Call by pointer

What are the three inheritance accesses

Protected, Private, Public

How are default arguments used?

So that we don't have to overload, it makes it simpler. Can go in either prototype or heading, but only in one

What was the fourth method in programming

Structural languages (Languages that include structs)

What happens when you increment a pointer to an object (p_ob1++)?

The pointer points to the next object in memory

Inheritance

The process in which one object can inherit the properties of another

List the 4 advantage(s) of using CBR

The programmer no longer needs to pass an address References offer a cleaner, more elegant interface No copy of an object is made, destructor is not called Call by references is faster than call by value

How do we use arrays of objects?

The same way as arrays of built-in types

What happens when you increment a reference?

The value of the variable is incremented (does not point to a new location)

Why do we use friend functions

To grant a non-member function access to private members.

Why do we overload operators for a class?

To increase the functionality of the class and allow it to be used in expressions

What was the first method in programming

Toggling/Switches (100101)

T/F A derived class inherit multiple base classes

True

Implenting Encapsulation

Use private and public members

When is the constructor called?

When an object comes into existence.

How does initialization happen?

When an object is created, passed, or returned to a function

Violating encapsulation

When private data members are set to public, allowing code to interfere with data

When is the deconstructor called?

When the object/function is going out of scope. They are called in reverse order after main ends.

When do we use a forward reference

When we need to use a class that does not yet exist that is already declared in another (and undefined)

C++ vs Windows programming

Windows programs are large and complex compared to C++

Do functions need to be prototyped in C++?

Yes

Can overloaded operators be inherited by derived classes?

Yes (Only the = cannot be inherited by a derived class)

Can default and non-default arguments be used?

Yes, but default arguments must have to be all the way to the right

How to use C libraries in C++?

add c in front of the library name (cstring.h instead of string.h)

What type can a data member be?

any type (programmer-defined or built-int)

How to define a class?

class class_name

How is an object created

class ob1;

What is a base class

class that defines those qualities common to all objects to be derived from the base. (Most general description)

What is a derived class

class that includes all features of the generic base class and then adds qualities specific to the derived class

How do you define a copy constructor?

class_name (const class_name &obj)

How do you define a pointer to an object?

class_name *p_ob1;

Write ob++ as an overloaded operator

classname classname :: operator++ (int notused)

How is memory allocated with new/delete malloc/free

dynamically

T/F constructors and destructors are required for classes

false

T/F friend function is a form of function overloading

false

CBR function prototype

function ( int &value )

CBP function prototype

function ( int *p_value)

CBV function heading

function ( int value)

Where do we put default arguments in program

function prototype

How to pass an object to a function using CBR (Call by reference)

function(&v)

How to pass an object to a function using CBP (Call by pointer)

function(v)

How to pass an object to a function using CBV (call by value)

function(v)

Are malloc/free operators or functions?

functions

Example of a copy constructor?

myclass (const myclass &obj)

What does ob1 - ob2 look like to the compiler?

ob1.operator - (ob2)

What does ob1 / ob2 look like to the compiler?

ob1.operator / (ob2)

What does ob1+ob2 look like to the compiler?

ob1.operator+(ob2)

Friend function parameters are usually

object(s) of the class the function is a friend of

For pointer arithmetic to work, objects must be ...

of the same type

How many classes can a function be a friend of?

one or more (no upper limit)

Are new/delete operator or functions?

operators

How to set p_ob1 to the address of ob1?

p_ob = &ob1;

what does the this* pointer point to?

points to the object that invoked a member function

Are data members public or private?

private

Are function members public or private

public

What are the two ways we can initialize an array of objects?

short hand - samp ob1[3] = {1,2,3} long hand - samp ob1[3] = {samp(1), samp(2), samp(3)}

What is the operator (::)

tells the compiler which function belongs to which class

what is encapsulation?

the mechanism that binds together code and the data it manipulates

What are the parameters of a constructor?

there is no limit

What is a copy constructor?

they are constant references, the first parameter is always a constant

What are the parameters of a destructor?

they do not have any

Do default arguments have a required order?

they go last in the declaration

How do we use friend functions when operator overloading?

to allow us to perform addition with a programmer-defined type and a built-in type

what are constructors used for?

to automatically initialize an object

T/F a constructor can be overloaded

true

What is the operator ( . )

used to invoke member functions

What is the operator (&)

used to pass by reference

What is the operator (->)

used with pointers to objects

What problem does a virtual base class solve?

virtual base classes are used to prevent multiple copies of the base class being present in an object

When can a function be on the left of an = operation?

when a function returns a reference

When do we not have to use the inline keyword?

when the function is auto-inlined


Conjuntos de estudio relacionados

International Obligations on Intellectual Property

View Set

Chapter 40: Types of Business Organizations

View Set