C++ Programming Below are answers I got wrong on a quiz. But, sometimes answers
ID: 3776274 • Letter: C
Question
C++ Programming
Below are answers I got wrong on a quiz. But, sometimes answers that were marked wrong, were actually correct.
I need someone to verify the correct answers below. Thank you.
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 getStar();
void setTitle( string title );
void setStar( string star );
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 1. 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?
a. ostream operator <<(const Blockbuster & b)
b. ostream& operator <<(ostream& outs, const Blockbuster & b)
c. ostream& Blockbuster::operator <<(ostream& outs, const Blockbuster & b)
d. void ostream& operator <<(ostream& outs, const Blockbuster & b)
Correct Answer = b
Question 2. Which of the following statements is a valid way to create a Blockbuster object?
a. std::Blockbuster b( 100, "Rambo", "Sylvester Stallone" );
b. cs52::Blockbuster b;
c. cs 52::Blockbuster b( 100, "Rambo", "Sylvester Stallone" );
d. std::Blockbuster b( 100, "Rambo" );
Correct answer = c
Question 3. Sally the Programmer intends to write a method body of the getter method:
string Blockbuster::getTitle( )
Which of the following would be the correct implementation?
a. return( my_Title );
b. my_Title = title;
c. myTitle( );
d. title = my_Title;
Correct answer = a
Question 4. Based on the Blockbuster class shown above, can the friend function equal() be marked const?
a. No
b. Yes
c. Not enough information has been provided to answer this question
d. It depends on exactly what the method equal does
Correct answer = a
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 5. In the class SummerVacation, how many constructors does it define?
a. 3
b. 0
c. 4
d. 1
e. 2
Correct answer = d
Question 6. Which of the statements below is true about the constructor of the class SummerVacation?
a. The class SummerVacation provides multiple, overloaded constructor call
b. The constructor for the class SummerVacation requires exactly one argument
c. There is only one public constructor for the class SummerVacation
d. None of the above is correct about the constructor of the class SummerVacation
Correct answer = c
Question 7. Every object stores its own individual copy of all the member variable's defined by its class.
a. True
b. False
Correct answer = a
Question 8. The mutator ("setter") methods of a class can never be marked const.
a. True
b. False
Correct answer = a
Question 9. Lacking a public or private declaration, members or methods in a class will be treated as if they were marked private.
a. True
b. False
Correct answer = a
Question 10. For every class, C++ will supply a single, no-argument constructor whose implementation will be empty.
a.True
b. False
Correct answer = b
Question 11. In C++, programmers can use a class to create a large number of variables of that type.
a. True
b. False
Correct answer = a
Question 12. Which of the statements below is correct about cout?
a. cout is a Class
b. cout is a Method of an Object
c. cout is a Namespace
d. cout is an Object
Correct answer = d
Question 13. Which of the following are correct in describing the statement: #include "TrashCan.h" and what it does?
a. All of the choices above are correct
b. this is a preprocessor command that is found at the top of other C++ files
c. this statement performs textual substitution
d. this statement is used by any file that wants to work with the classes declared inside that Mailbox.h file
Correct answer = a
Explanation / Answer
1.c
ostream& Blockbuster::operator <<(ostream& outs, const Blockbuster & b)
2.c
cs 52::Blockbuster b( 100, "Rambo", "Sylvester Stallone" );
3.b
my_Title = title;
5.e
6.d
None of the above is correct about the constructor of the class SummerVacation
7.False
8.true
9.true
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.