CSE test 3

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

class

defines a new type that can group data and functions to form an object.

Which of the following statements will not produce a syntax error?

- Declaring an object to be const will produce syntax error -defining a const member function that modifies a data member of the object -Invoking a non-const member function on a const object -declaring a constructor to be const

constructor

A constructor has the same name as the class. A constructor function has no return type, not even void. Ex: Restaurant::Restaurant() {...} defines a constructor for the Restaurant class. If a class has no programmer-defined constructor, then the compiler implicitly defines a default constructor having no statements.

inline member function

A member function's definition may appear within the class definition putting function def into class

Returning references to non-const, private data:

Allows private member variables to be modified, thus breaking encapsulation.

Variables defined inside a member function of a class have

Block scope

Static member functions

Can access only other static member functions and static data members

Which statement about operator overloading is false?

Certain overloaded operators can change the number of arguments they take.

ClassName.cpp

Contains member function definitions. #include <iostream> using namespace std; #include "StoreItem.h" void StoreItem::SetWeightOunces(int ounces) { weightOunces = ounces; } void StoreItem::Print() const { cout << "Weight (ounces): " << weightOunces << endl; }

ClassName.h

Contains the class definition, including data members and member function declarations. #ifndef STOREITEM_H #define STOREITEM_H class StoreItem { public: void SetWeightOunces(int ounces); void Print() const; private: int weightOunces; }; #endif

static data members of a certain class:

Have class scope

Which of the following is not true of a constructor and destructor of the same class?

They are both able to have default arguments true- They both have the same name aside from the tilde ~ character They are both usually created once per object created

private data members:

Variables that member functions can access but class users cannot. Private data members appear after the word "private:" in a class definition.

this

Within a member function, the implicitly-passed object pointer is accessible via the name this. In particular, a member can be accessed as this->member. The -> is the member access operator for a pointer, similar to the "." operator for non-pointers

overload

a constructor by defining multiple constructors differing in parameter types. A variable declaration can have arguments. The constructor with matching parameters will be called.

A class' public member functions

indicate all operations a class user can perform on the object.

abstract data type (ADT)

is a data type whose creation and update are constrained to specific well-defined operations. A class can be used to implement an ADT.

A linked list

is a list wherein each item contains not just data but also a pointer—a link—to the next item in the list. Comparing vectors and linked lists: Vector: Stores items in contiguous memory locations. Supports quick access to i'th element via v.at(i), but may be slow for inserts or deletes on large lists due to necessary shifting of elements. Linked list: Stores each item anywhere in memory, with each item pointing to the next item in the list. Supports fast inserts or deletes, but access to i'th element may be slow as the list must be traversed from the first item to the i'th item. Also uses more memory due to storing a link for each item.

Abstraction

means to have a user interact with an item at a high-level, with lower-level internal details hidden from the user (aka information hiding or encapsulation). Ex: An oven supports an abstraction of a food compartment and a knob to control heat. An oven's user need not interact with internal parts of an oven.

Assume that t is an object of class Test, which has member functions a(), b(), c() and d(). If the functions a(), b() and c() all return references to an object of class Test (using the dereferenced this pointer) and function d() returns void, which of the following statements will not produce a syntax error:

t.a().b().d();


Set pelajaran terkait

Diet and Nutrition Module 2 Chapter 7 Energy Metabolism

View Set

Chapter 1: Introduction to Sociology

View Set

American Literature Proctored Exam

View Set

Business Finance Final Exam (Chapter 5)

View Set

Abdomen/Lower Limb/Etc: Lev Quiz

View Set

Principles of Accounting Module 6

View Set