Need to be answered in 30 min. Please help!! The usual purpose of a constructor
ID: 640015 • Letter: N
Question
Need to be answered in 30 min. Please help!!
The usual purpose of a constructor is to initialize the member variables of a class.
Select one:
a. TRUE
b. FALSE
Question 2
Not yet answered
Marked out of 2.00
Flag question
Question text
The following code:
Student s; Customer c;
Grapefruit g = s + c;
calls the operator+ defined as:
Grapefruit operator+ ( Customer c, Student s );.
Select one:
a. FALSE
b. TRUE
Question 3
Not yet answered
Marked out of 2.00
Flag question
Question text
In C++, programmers can use a class to create a large number of variables of that type.
Select one:
a. FALSE
b. TRUE
Question 4
Not yet answered
Marked out of 2.00
Flag question
Question text
In C++, a class constructor gets invoked whenever a variable of a that defined class is declared.
Select one:
a. TRUE
b. FALSE
Information
Flag question
Information text
The next few questions deal with the class definition (.h file) shown below. The class Blockbuster represents a popular Hollywood movie.
#include <string>
using namespace std;
namespace cs52 {
class Blockbuster{
public:
Blockbuster( int length, string title, string star );
friend bool equal( const Blockbuster & b1, const Blockbuster & b2 );
int getLength();
string getTitle();
string getPlace();
void setTitle( string title );
void setPlace( string place );
void setLength( int length );
private:
int my_Length; // feature length in minutes
string my_Title; // feature title
string my_Star; // leading actor or actress
};
}
Question 5
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the following statements is a valid way to create a Blockbuster object?
Select one:
a. std::Blockbuster b( 100, "Rambo", "Sylvester Stallone" );
b. cs52::Blockbuster b( 100, "Rambo", "Sylvester Stallone" );
c. std::Blockbuster b( 100, "Rambo" );
d. cs52::Blockbuster b;
Question 6
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the following parts of your program have access to the member variable my_Title directly without calling a method?
Select one:
a. All of the above choices have access to the variable my_Title directly without calling a method
b. Methods within classes other than Blockbuster
c. Only methods within the class Blockbuster itself
d. Driver code like void main() {...}
Question 7
Not yet answered
Marked out of 2.00
Flag question
Question text
What is the correct function definition when the function equal gets implemented in Blockbuster's implementation (.cpp) file?
Select one:
a. bool Blockbuster::equal(const Blockbuster & b1, const Blockbuster & b2)
b. bool friend Blockbuster::equal(const Blockbuster & b1, const Blockbuster & b2)
c. friend bool Blockbuster::equal(const Blockbuster & b1, const Blockbuster & b2)
d. bool equal(const Blockbuster & b1, const Blockbuster & b2)
Question 8
Not yet answered
Marked out of 2.00
Flag question
Question text
Sally the Programmer intends to write a method body of the setter method:
void Blockbuster::setTitle( string title )
Which of the following would be the correct implementation?
Select one:
a. my_Title = title;
b. myTitle( );
c. title = my_Title;
d. return( my_Title );
Question 9
Not yet answered
Marked out of 2.00
Flag question
Question text
Suppose you decide to overload the << operator in the class Blockbuster. What is the valid function declaration for the operator << that belongs in the class definition (.cpp) file above?
Select one:
a. ostream& operator <<(ostream& outs, const Blockbuster & b)
b. ostream& Blockbuster::operator <<(ostream& outs, const Blockbuster & b)
c. ostream operator <<(const Blockbuster & b)
d. void ostream& operator <<(ostream& outs, const Blockbuster & b)
Information
Flag question
Information text
The next few questions deal with the class definition (.h file) shown below. The class SummerVacation represents a trip taken somewhere.
#include <string>
using namespace std;
class SummerVacation {
void pack();
public:
int getLength();
double getCost();
string getPlace();
SummerVacation( int length, string place, double cost );
private:
void relax();
int my_Length;//days traveled
string my_Place; //place traveled to
double my_Cost; //how much was spent
};
Question 10
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the statements below is true about the constructor of the class SummerVacation?
Select one:
a. None of the above is correct about the constructor of the class SummerVacation
b. The class SummerVacation provides multiple, overloaded constructor methods
c. The constructor for the class SummerVacation requires exactly one argument
d. There is only one public constructor for the class SummerVacation
Question 11
Not yet answered
Marked out of 2.00
Flag question
Question text
In the class SummerVacation, how many private methods variables does it define?
Select one:
a. 2
b. 1
c. 4
d. 3
Question 12
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the statements below is true about the method relax?
Select one:
a. It is a public method of the class SummerVacation.
b. It is a method that requires an argument be passed by the calling code.
c. It is a private method of the class SummerVacation.
d. It is a method which can be called from driver code.
e. None of the above is correct about the method relax.
Question 13
Not yet answered
Marked out of 2.00
Flag question
Question text
In the class SummerVacation, how many constructors does it define?
Select one:
a. 4
b. 0
c. 1
d. 2
Question 14
Not yet answered
Marked out of 2.00
Flag question
Question text
In the class SummerVacation, how many private member variables does it define?
Select one:
a. 3
b. 5
c. 4
d. 0
Question 15
Not yet answered
Marked out of 2.00
Flag question
Question text
In the class SummerVacation, how many public member variables does it define?
Select one:
a. 1
b. 0
c. 2
d. 3
Question 16
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the statements below is true about the method getCost?
Select one:
a. It is a mutator method of the class SummerVacation.
b. It is an accessor method of the class SummerVacation.
c. It is a method which cannot be called from driver code.
d. It is a method that requires an argument be passed by the calling code.
e. None of the choices listed here is correct about the method getCost.
Question 17
Not yet answered
Marked out of 2.00
Flag question
Question text
Every object shares just a single copy of the member variable's defined by its class.
Select one:
a. FALSE
b. TRUE
Question 18
Not yet answered
Marked out of 2.00
Flag question
Question text
Lacking a public or private declaration, members or methods in a class will be treated as if they were marked private.
Select one:
a. FALSE
b. TRUE
Question 19
Not yet answered
Marked out of 2.00
Flag question
Question text
Default-valued parameter arguments do not need to be passed when invoking the function that defines their value.
Select one:
a. FALSE
b. TRUE
Question 20
Not yet answered
Marked out of 2.00
Flag question
Question text
In this course, we compared a class many times to the everyday things we interact with. In this way, we compared a class member variable to
Select one:
a. the brand (supplier) who made it
b. the data (properties) things have
c. the driver (consumer) who used it
d. the actions (verbs) things do
Question 21
Not yet answered
Marked out of 2.00
Flag question
Question text
A class' constructors are all defined to return void.
Select one:
a. TRUE
b. FALSE
Question 22
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the statements below is correct about cin?
Select one:
a. cin is an Object
b. cin is a Class
c. cin is a Namespace
d. cin is a Method of an Object
Question 23
Not yet answered
Marked out of 2.00
Flag question
Question text
In this course, we compared a class many times to the everyday things we interact with. In this way, we compared int main() code which interacts with a class and its methods to
Select one:
a. the brand (supplier) who made it
b. the data (properties) things have
c. the driver (consumer) who used it
d. the actions (verbs) things do
Question 24
Not yet answered
Marked out of 2.00
Flag question
Question text
The mutator ("setter") methods of a class are typically marked with the const modifier.
Select one:
a. FALSE
b. TRUE
Question 25
Not yet answered
Marked out of 2.00
Flag question
Question text
In the declaration:
int myArray[ 10 ];
is a valid array declaration in C++.
Select one:
a. FALSE
b. TRUE
Question 26
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the following are correct in describing the statement: #include "SodaCan.h" and what it does?
Select one:
a. All of the choices above are correct
b. this statement performs textual substitution
c. this is a preprocessor command that is found at the top of other C++ files
d. this statement is used by any file that wants to work with the classes declared inside that FlashDrive.h file
Question 27
Not yet answered
Marked out of 2.00
Flag question
Question text
Within a single class definition (.h file), the public and private access modifiers can be listed only one time.
Select one:
a. TRUE
b. FALSE
Question 28
Not yet answered
Marked out of 2.00
Flag question
Question text
Which of the statements below is correct about std?
Select one:
a. std is a Class
b. std is a Namespace
c. std is an Object
d. std is a Method of an Object
Question 29
Not yet answered
Marked out of 2.00
Flag question
Question text
The accessor ("getter") methods of a class are typically marked with the const modifier.
Select one:
a. TRUE
b. FALSE
Question 30
Not yet answered
Marked out of 2.00
Flag question
Question text
The methods of a class represents the "actions" that thing knows how to perform.
Select one:
a. TRUE
b. FALSE
Question 31
Not yet answered
Marked out of 2.00
Flag question
Question text
In this course, we compared a class many times to the everyday things we interact with. In this way, we compared a class method to
Select one:
a. the data (properties) things have
b. the actions (verbs) things do
c. the driver (consumer) who used it
d. the brand (supplier) who made it
Sally The Programmer is working to improve the Mailbox class we have been working with in this course. She decides to make a parameterless constructor so that driver code can conveniently say:
Mailbox m;
and have everything still compile and work properly. In her implementation of the parameterless constructor, she writes:
Mailbox::Mailbox() {
// empty...
}
What is wrong with her approach and what would you recommend she do to avoid potential problems?
Path: p
Font family Font size ParagraphPath: p
Explanation / Answer
1)a
2)a
3)b
4)a
5)b
6)c
7)d
8)a
9)b
10)a
11)a
12)c
13)d
14)a
15)b
16)b
17)a
18)b
19)b
20)a
21)b
22)a
23)c
24)b
25)b
26)a
27)a
28)b
29)b
30)a
31)b
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.