CSC 136 Final Exam

0.0(0)
studied byStudied by 8 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/119

flashcard set

Earn XP

Description and Tags

Zhang please give me a god damn A

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

120 Terms

1
New cards
To access a structure member (component), you use the struct variable name together with the member name; these names are separated by a dot (period).
True
2
New cards
You can use an assignment statement to copy the contents of one struct into another struct of the same type.
True
3
New cards
Relational operations can be used on struct variables.
False
4
New cards
A function can return a value of the type struct.
True
5
New cards
A struct is typically a ____ data structure.
heterogeneous
6
New cards
The components of a struct are called the ____ of the struct.
members
7
New cards
Which of the following struct definitions is correct in C++?
struct studentType{ \n int ID; \n };
8
New cards
Consider the following struct definition: \n struct rectangleData{ \n double length; \n double width; \n double area; \n double perimeter; \n };
rectangleData myRectangle;
9
New cards
Typically, in a program, a struct is defined ____ in the program.
before the definitions of all the functions
10
New cards
The syntax for accessing a struct member is structVariableName____.
.memberName
11
New cards
You can assign the value of one struct variable to another struct variable of ____ type.
the same
12
New cards
Consider the following statements: \n struct rectangleData{ \n double length; \n double width; \n double area; \n double perimeter; \n }; \n rectangleData bigRect; \n Which of the following statements correctly initializes the component length of bigRect?
bigRect.length = 10;
13
New cards
\
Consider the following statements: \n struct rectangleData{ \n double length; \n double width;double area; \n double perimeter; \n }; \n rectangleData bigRect; \n Which of the following statements is valid in C++?
cin >> bigRect.length;
14
New cards
struct personalInfo{ \n string name; \n int age; \n double height; \n double weight; \n }; \n struct commonInfo{ \n string name; \n int age; \n }; \n personalInfo person1, person2; \n commonInfo person3, person4; \n Which of the following statements is valid in C++?
person2 = person1;
15
New cards
Consider the following statements: \n struct studentType1{ \n string name; \n int ID; \n double gpa; \n }; \n studentType1 student1, student2; \n struct studentType2 \n {string name; \n int ID; \n double gpa; \n }; \n studentType2 student3, student4; \n Which of the following statements is valid in C++?
student1.ID = student3.ID;
16
New cards
\
A struct variable can be passed as a parameter ____.
either by value or by reference
17
New cards
Consider the following statements: \n struct supplierType{ \n string name; \n int supplierID; \n }; \n struct applianceType{ \n supplierType supplier; \n string modelNo; \n double cost; \n }; \n applianceType applianceList\[25\]; \n Which of the following best describes applianceList?
It is an array of structs.
18
New cards
A class is an example of a structured data type.
True
19
New cards
In C++, class is a reserved word and it defines only a data type.
True
20
New cards
If the heading of a member function of a class ends with the word const, then the function member cannot modify the private member variables, but it can modify the public member variables.
False
21
New cards
Given this declaration: \n class myClass{ \n public:void print(); \n //Output the value of x; \n MyClass(); \n private:int x; \n }; \n myClass myObject; \n The following statement is legal. \n myObject.x = 10;
False
22
New cards
If an object is declared in the definition of a member function of the class, then the object can access both the public and private members of the class.
True
23
New cards
If an object is created in a user program, then the object can access both the public and private members of the class.
False
24
New cards
As parameters to a function, class objects can be passed by reference only.
False
25
New cards
The public members of a class must be declared before the private members.
False
26
New cards
The components of a class are called the ____ of the class.
members
27
New cards
Which of the following class definitions is correct in C++?
class studentType{ \n public: \n void setData(string, double, int); \n private: \n string name; \n };
28
New cards
If a member of a class is ____, you cannot access it outside the class.
private
29
New cards
A class and its members can be described graphically using a notation known as the ____ notation.
UML
30
New cards
The word ____ at the end of several the member functions in the accompanying figure class clockType specifies that these functions cannot modify the member variables of a clockType object.
Const
31
New cards
A ____ sign in front of a member name on a UML diagram indicates that this member is a public member.
\+
32
New cards
In C++, the ____ is called the member access operator.
.
33
New cards
In C++, you can pass a variable by reference and still prevent the function from changing its value by using the keyword ____ in the formal parameter declaration.
const
34
New cards
A member function of a class that only accesses the value(s) of the data member(s) is called a(n) ____ function.
accessor
35
New cards
To guarantee that the member variables of a class are initialized, you use ____.
constructors
36
New cards
Consider the accompanying class and member functions definitions. How many constructors are present in the class definition?
two
37
New cards
How many destructors can a class have?
one
38
New cards
A destructor has the character ____, followed by the name of the class.
\~
39
New cards
What does ADT stand for?
Abstract Data Type
40
New cards
Which of the following is true about classes and structs?
By default, all members of a struct are public and all members of a class are private.
41
New cards
In multiple inheritance, the derived class has more than one base class.
True
42
New cards
The private members of a base class can be directly accessed by a derived class.
False
43
New cards
A derived class cannot directly access public members of a base class.
False
44
New cards
If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list.
True
45
New cards
A call to the base class's constructor is specified in the heading of the definition of a derived class constructor.
True
46
New cards
A derived class can directly access the protected members of the base class.
True
47
New cards
If inheritance is private, all members of the base class, including private members, become private members of the derived class.
False
48
New cards
Inheritance is an example of a(n) ____ relationship.
is-a
49
New cards
Classes can create new classes from existing classes. This important feature ____.
encourages code reuse
50
New cards
____ is a "has-a" relationship.
composition
51
New cards
The new classes that we create from existing classes are called ____ classes.
derived
52
New cards
Existing classes, from which you create new classes, are called ____ classes.
Base
53
New cards
consider the following class definition:class dClass: \n bClass{ \n //class members list \n }; \n The class dClass is derived from the class bClass using the ____ type of inheritance.
private
54
New cards
Which of the following is a valid definition of the derived class bClass?
class bClass: \n public aClass{ \n //... \n };
55
New cards
Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass?
class bClass: \n public aClass{ \n //... \n };
56
New cards
Which of the following is true about a derived class?
A derived class can redefine any public member function of the base class.
57
New cards
To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters.
redefine
58
New cards
If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class.
overloaded
59
New cards
If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class, you use the statement ____.
classB::functionName();
60
New cards
The following is a legal C++ enumeration type: \n enum colorType{BLUE, GREEN, PINK, YELLOW,RED};
True
61
New cards
The following is a valid C++ enumeration type: \n enum places {1ST, 2ND,3RD,4TH};
False
62
New cards
No arithmetic operations are allowed on the enumeration type.
True
63
New cards
A function cannot return the value of an enumeration type.
False
64
New cards
A function cannot return the value of an enumeration type.
False
65
New cards
Consider the declaration: \n enum sports {BASKETBALL, FOOTBALL, HOCKEY, BASEBALL, SOCCER}; \n which of the following statements is true?
FOOTBALL
66
New cards
enum courses {ALGEBRA, BASIC, PASCAL, PHILOSOPHY, ANALYSIS}; \n courses registered; \n registered = ALGEBRA; \n cout << registered << endl;
0
67
New cards
Which of the following statements declares the studentGrade variable?
enum grades {A, B, C, D, F} studentGrade;
68
New cards
A pointer variable is a variable whose content is a memory address.
True
69
New cards
In C++, pointer variables are declared using the reserved word pointer.
False
70
New cards
In the statement \n int\* p, q; \n p and q are pointer variables.
False
71
New cards
Variables that are created during program execution are called static variables.
False
72
New cards
Given the declaration \n int \*p; \n The statement \n p = new int\[50\]; \n dynamically allocates an array of 50 components of type int and p contains the base address of the array.
True
73
New cards
A memory leak is an unused memory space that cannot be allocated.
True
74
New cards
If p is a pointer variable, the statement p = p + 1; is valid in C++.
True
75
New cards
In C++, you declare a pointer variable by using the ____ symbol.
\*
76
New cards
In C++, ____ is called the address of operator.
&
77
New cards
Which of the following can be used to initialize a pointer variable?
nullptr
78
New cards
The C++ operator ____ is used to create dynamic variables.
new
79
New cards
The C++ operator ____ is used to destroy dynamic variables.
delete
80
New cards
Which of the following arithmetic operations is allowed on pointer variables?
increment
81
New cards
Given the declaration int \*a;, the statement a = new int\[50\]; dynamically allocates an array of 50 components of the type ____.
int
82
New cards
An array created during the execution of a program is called a(n) ____ array.
dynamic
83
New cards
In a ____ copy, two or more pointers of the same type point to the same memory.
shallow
84
New cards
In a ____ copy, two or more pointers have their own data.
deep
85
New cards
A class ____ automatically executes whenever a class object goes out of scope.
destructor
86
New cards
The ____ constructor is executed when an object is declared and initialized by using the value of another object.
copy
87
New cards
Which of the following would be appropriate syntax for the heading of a copy constructor for a class called rulerType?
rulerType(const rulerType& myRuler)
88
New cards
Operator functions typically return void.
False
89
New cards
In C++, operator is a reserved word.
True
90
New cards
A friend function does not have access to the private data members of the class.
False
91
New cards
Most operator functions can either be member functions or nonmember functions of a class.
True
92
New cards
The name of the function to overload the operator
operator
93
New cards
Every object of a class maintains a (hidden) pointer to itself, and the name of this pointer is ____.
this
94
New cards
A(n) ____ function is a nonmember function that has access to all members of the class.
friend
95
New cards
The general form of the functions to overload the binary operators as member functions of a class is returnType operator#(____ className&) const;.
const
96
New cards
Which of the following function prototypes overloads the != operator for the class rectangleType?
bool operator!=(const rectangleType&) const;
97
New cards
The general syntax to overload the stream extraction operator >> for a class is ____.
friend istream& operator>>(istream&, className&);
98
New cards
The return type of the function to overload the operator >> must be a reference to a(n) ____ object.
istream
99
New cards
The general syntax for the function prototype to overload the assignment operator = for a class is ____.
const className& operator=(const className&);
100
New cards
To overload the pre-increment (++) operator for a class, if the operator function is a member of that class, it must have ____ parameter(s).
no