1408 C++

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

In OOP terminology, an object's member variables are often called its ________, and its member functions are sometimes referred to as its behaviors, or ________.

attributes, methods

When a structure is passed ________ to a function, its members are not copied.

by reference

The process of object-oriented analysis can be viewed as the following steps:

Identify objects, then define objects' attributes, behaviors, and relationships

What is the output of the following program? #include <iostream> using namespace std; class TestClass { public: TestClass(int x) {cout << x << endl;} TestClass() {cout << "Hello!"<< endl;} }; int main() { TestClass test; return 0; }

Hello!

True/False: A struct can contain members with varying data types.

True

True/False: An array name is a pointer constant because the address stored in it cannot be changed during runtime.

True

True/False: Any mathematical operations that can be performed on regular C++ variables can be performed on structure members.

True

True/False: C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.

True

Look at the following structure declaration. struct Employee { string name; int idNum; }; In this declaration, idNum is:

a member

A pointer variable is designed to store ________.

a memory address any legal C++ value

Which of the following statements outputs the value of the gpa member of element 1 of the student array?

cout << student[1].gpa;

Use the delete operator only on pointers that were ________.

created with the new operator

To help prevent memory leaks from occurring in C++ 11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used.

smart pointer

This allows you to access structure members.

dot operator

Which of the following assigns a value to the hourlyWage member of employee[2]?

employee[2].hourlyWage = 100.00;

A declaration for an enumerated type begins with the ________ key word.

enum

Look at the following declaration. enum Tree { OAK, MAPLE, PINE}; What is the value of the following relational expression? OAK > PINE

false

A function may return a pointer, but the programmer must ensure that the pointer ________.

still points to a valid object after the function ends

This type of member function may be called from a statement outside the class.

public

If a local variable and a global variable have the same name within the same program, the ________ resolution operator must be used.

scope

This is required after the closing brace of the structure declaration.

semicolon

The following statement: cin >> *num3;

stores the keyboard input into the variable pointed to by num3

Dynamic memory allocation occurs ________.

when a new variable is created at runtime

This directive is used to create an "include guard," which allows a program to be conditionally compiled. This prevents a header file from accidentally being included more than once.

#ifndef

The ________ and ________ operators can be used to increment or decrement a pointer variable.

++,--

When you dereference an object pointer, use the ________.

-> operator

Look at the following declaration. enum Tree { OAK, MAPLE, PINE}; In memory, what value will the MAPLE enumerator be stored as?

1

What will the following code output? int *numbers = new int[5]; for (int i = 0; i <= 4; i++) *(numbers + i) = i; cout << numbers[2] << endl;

2

What will the following code output? int number = 22; int *var = &number; cout << *var << endl;

22

What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() {cout << val << endl;} public: TestClass(int x) {val = x;} }; int main() { TestClass test(77); return 0; }

77

________ can be used as pointers.

Array Names

A function ________ return a structure.

may

What will the following code output? int number = 22; int *var = &number; cout << var << endl;

the address of the number variable

The constructor function always has the same name as ________.

the class

If you are using an older compiler that does not support the C++ 11 standard, you should initialize pointers with ________.

the integer 0, or the value NULL

To dereference a structure pointer, the appropriate operator is ________.

the structure pointer operator, ->

Which of the following is an example of a C++ primitive data type? A) unsigned short int B) long double C) unsigned char D) All of these E) None of these

All of these

You may use a pointer to a structure as a ________. A) function parameter B) structure member C) function return type D) All of these E) None of these

All of these

Which of the following statements is not valid C++ code? A) int ptr = &num1; B) int ptr = int *num1; C) float num1 = &ptr2; D) All of these are valid. E) All of these are invalid.

All of these are invalid

What does the following statement do? double *num2;

Declares a pointer variable named num2

True/False: A destructor function can have zero to many parameters.

False

True/False: More than one destructor function may be defined for a class.

False

True/False: The constructor function may not accept arguments.

False

True/False: The following if statement correctly determines whether the two variables' members contain the same data: o an int variable.

False

True/False: With pointer variables you can access, but you cannot modify, data in other variables.

False

True/False: You cannot directly assign an enumerator tLook at the following structure declaration. struct Circle { double centerX; double centerY; double radius; }; Assume that circle1 and circle2 are variables of the Circle type, and their members have been initialized.

False

True/False: You must declare all data members of a class before you declare member functions.

False

True/False: You must use the private access specification for all data members of a class.

False

The constructor function's return type is ________. A) int B) float C) char D) structure pointer E) None of these

None of these

The name of the structure is referred to as its ________. A) data type B) argument C) parameter D) tag E) None of these

None of these

When you pass a pointer as an argument to a function, you must ________. A) declare the pointer variable again in the function call B) dereference the pointer variable in the function prototype C) use the #include<func_ptr.h> statement D) not dereference the pointer in the function's body E) None of these

None of these

If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do?

Output the dereferenced value pointed to by p

What will the following statement output? cout << &num1;

The memory address of the variable called num1

Assuming ptr is a pointer variable, what will the following statement output? cout << *ptr;

The value stored in the variable whose address is contained in ptr.

True/False: If you do not declare a destructor function, the compiler will furnish one automatically.

True

True/False: In C++ 11, the nullptr key word was introduced to represent the address 0.

True

True/False: In C++ 11, you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.

True

True/False: It is possible for a structure to contain as a member a pointer to its own structure type.

True

True/False: It is possible for a structure variable to be a member of another structure variable.

True

True/False: Object-oriented programming is centered around the object, which encapsulate together both the data and the functions that operate on the data.

True

True/False: One purpose that destructor functions are often used for is to free memory that was allocated by the object.

True

True/False: The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.

True

True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.

True

True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.

True

Look at the following structure declaration. struct Employee { string name; int idNum; }; In this declaration, Employee is:

a tag

A pointer variable may be initialized with ________.

a valid address in the computer's memory any non-zero integer value

Data types that are created by the programmer are known as ________.

abstract data types(ADT)

This describes only the general characteristics of an object.

abstraction

The contents of pointer variables may be changed with mathematical statements that perform ________.

addition and subtraction

Every byte in the computer's memory is assigned a unique ________.

address

The ________, also known as the address operator, returns the memory address of a variable.

ampersand(&)

When this is placed in front of a variable name, it returns the address of that variable.

ampersand(&)

Members of a(n) ________ union have names, but the union itself has no name.

anonymous

The following statement: int *ptr = new int;

assigns an address to the variable named ptr

Look at the following statement: sum += *array++; This statement ________.

assigns the dereferenced pointer's value, then increments the pointer's address

A structure ________ contain members of the same data type.

can

When a member function is defined outside of the class declaration, the function name must be qualified with the ________.

class name, followed by the scope resolution operator

A ________ is a member function that is automatically called when a class object is ________.

constructor, created

Which statement displays the address of the variable num1?

cout << &num1;

A class is a(n) ________ that is defined by the programmer.

data type

In a procedural program, you typically have ________ stored in a collection of variables, and a set of ________ that perform operations on the data.

data, functions

Objects are created from abstract data types that encapsulate ________ and ________ together.

data, functions

Before a structure can be used, it must be ________.

declared

If an anonymous union is declared globally (outside all functions), it must be ________.

declared static

If Circle is a structure, the statement: Circle *pcirc = nullptr;

declares a structure pointer called pcirc initialized with a null pointer

When a constructor function accepts no arguments, or does not have to accept arguments because of default arguments, it is called a(n) ________.

default constructor

Assuming that Rectangle is a class name, the statement: Rectangle *BoxPtr;

defines a Rectangle pointer variable called BoxPtr

Which of the following statements deletes memory that has been dynamically allocated for an array?

delete [] array;

This is automatically called when an object is destroyed.

destructor function

Members of a class object are accessed with the ________.

dot operator

Passing a structure as a constant reference parameter to a function ________.

guarantees not to result in changes to the structure's members

Class declarations are usually stored here.

in their own header files

With pointer variables, you can ________ manipulate data stored in other variables.

indirectly

When the body of a member function is defined inside a class declaration, it is said to be ________.

inline

The statement: int *ptr = nullptr; has the same meaning as ________.

int* ptr = nullptr;

With an enumerated data type, the enumerators are stored in memory as ________.

integers

Not all arithmetic operations may be performed on pointers. For example, you cannot ________ or ________ a pointer.

multiply, divide

Assume that myCar is an instance of the Car class, and that the Car class has a member function named accelerate. Which of the following is a valid call to the accelerate member function?

myCar.accelerate();

The destructor function's return type is ________.

nothing. destructors have no return type

In C++ 11, the ________ key word was introduced to represent the address 0.

nullptr

A class may have this many default constructor(s).

only one

If you do not declare an access specification, the default for members of a class is ________.

private

This type of member function may be called only from a function that is a member of the same class.

private

This is used to protect important data.

private access specifier

Examples of access specifiers are the key words:

private and public

Look at the following statement: int *ptr; In this statement, what does the word int mean?

ptr is a pointer variable that will store the address of an integer variable.

Look at the following code: int numbers[3] = {1,2,3}; int *ptr; ptr = numbers+1; After this code executes, which of the following statements is true?

ptr will hold the address of numbers[1].

In C++ 11 you can use a new type of enum, known as a(n) ________, (also known as an enum class) to have multiple enumerators with the same name, within the same scope.

strongly typed enum

A C++ class is similar to one of these.

structure

Objects in an array are accessed with ________, just like any other data type in an array.

subscripts

If Circle is a structure tag, the statement: Circle doSomething(Circle c2) can be the header line for a function that ________.

takes a Circle structure as a parameter, does something, and returns a Circle structure

When you work with a dereferenced pointer, you are actually working with ________.

the actual value of the variable whose address is stored in the pointer variable

A structure pointer contains ________.

the address of a structure variable

If a variable uses more than one byte of memory, for pointer purposes its address is ________.

the address of the first byte of storage

When the less than ( < ) operator is used between two pointer variables, the expression is testing whether ________.

the address of the first variable comes before the address of the second variable in the computer's memory

What is the output of the following program? #include <iostream> using namespace std; class TestClass { private: int val; void showVal() {cout << val << endl;} public: TestClass(int x) {val = x;} }; int main() { TestClass test(77); test.showVal(); return 0; }

the program will not compile

A good reason to pass a structure as a constant reference is ________.

to prevent changes to the structure members

This is like a structure, except all members occupy the same memory area.

union

Look at the following statement. booklist[2].publisher[3] = 't'; This statement ________.

will store the character 't' in the fourth element of the publisher member of booklist[2]

For the following code, which statement is not true? class Point { Private: double y; double z; public: double x; };

z is available to code that is written outside the class.


संबंधित स्टडी सेट्स

FCC GROL Element 3 (Part 1 and 2)

View Set

Med Surg - Chapter 50 - Care of Patients with Musculoskeletal Problems

View Set

MGMT363 - Chapter 6 (SmartBook Questions Only)

View Set

Правила чтения буквы Kk в английском языке

View Set

chp 6 mktg, Chapter 7 - Consumer Buying Behavior, MKTG 351: Test 2 Review - Chapter 9, chp 11 mktg

View Set

Checkpoint 4 CHEM 1101 memorization

View Set

Series 65 Unit 15 Checkpoint Exam

View Set