Topic 9: Streams Graded Quiz 4
Question 1
Correct2.50 points out of 2.50Flag question
Question text
Which of the following will correctly read from the istream inFS to the string item?Select one:a. item >> inFS;b. item << inFS;c. inFS << item;d. inFS >> item;
Feedback
The correct answer is: inFS >> item;
Question 2
Correct2.50 points out of 2.50Flag question
Question text
Which of the following lines contains a syntax error?
class Person {
public:
void SetNames(string n, string ln)
{ name = n; lastName = ln; }
void PrintName() const;
private:
string name;
string lastName;
};
void Person::PrintName() const {
name = name + lastName;
cout << name << endl;
return;
}
int main() {
Person p;
p.SetNames(“Travis”, “Jones”);
p.PrintName();
return 0;
} Select one:a. void SetNames(string n, string ln)b. name = name + lastName;
c. p.SetNames(“Travis”, “Jones”);d. p.PrintName();
Feedback
The correct answer is: name = name + lastName;
Question 3
Correct2.50 points out of 2.50Flag question
Question text
Which preprocessor directive prevents a file from being included multiple times?Select one:a. #ifndef
b. #includec. #defined. #guard
Feedback
The correct answer is: #ifndef
Question 4
Correct2.50 points out of 2.50Flag question
Question text
Which of the following will NOT cause the double pi = 3.14159; to output “3.1416”?Select one:a. cout << fixed << setprecision(5) << pi; << endl;
b. cout << setprecision(5) << pi;c. cout << showpoint << setprecision(5) << pi;d. All of the above cause output to be “3.1416”.
Feedback
The correct answer is: cout << fixed << setprecision(5) << pi; << endl;
Question 5
Incorrect0.00 points out of 2.50Flag question
Question text
Which of the following lines contains a syntax error?
int main() {
ostringstream ageOSS;
int myAge = 22;
ageOSS << “I am “ << myAge << “ years old.”;
cout << ageOSS.str();
return 0;
}Select one:a. ostringstream ageOSS;b. ageOSS << “I am “ << myAge << “ years old.”;
c. cout << ageOSS.str();d. None of the above.
Feedback
The correct answer is: None of the above.
Question 6
Correct2.50 points out of 2.50Flag question
Question text
Which of the following choices appropriately fills in the blank?
A read from cin will read characters from ____________________.Select one:a. a buffer
b. the system’s keyboard directlyc. the system’s input devices directlyd. the hard disk
Feedback
The correct answer is: a buffer
Question 7
Correct2.50 points out of 2.50Flag question
Question text
Which of the following choices appropriately fills in the blank?
Characters written to cout are placed into a(n) _________.Select one:a. fileb. directoryc. buffer
d. hard disk
Feedback
The correct answer is: buffer
Question 8
Correct2.50 points out of 2.50Flag question
Question text
In the member function SetRadius, which of the following is the assignment statement using the ‘this’ pointer?
class Circle {
public:
void SetRadius(double radius);
double GetRadius() const;
private:
double r;
};
void Circle::SetRadius(double radius) {
r = radius;
return;
}Select one:a. r = this->radius;b. radius = r->this;c. this->r = radius;
d. this->r = this->radius;
Feedback
The correct answer is: this->r = radius;
Question 9
Correct2.50 points out of 2.50Flag question
Question text
What is the output of the following code?
class Person {
public:
Person() { name = “John”; }
void SetName(string n) { name = n; }
void PrintName() const
{ cout << name << “ “; }
private:
string name;
};
int main() {
Person p1;
p1.PrintName();
p1.SetName(“Travis”);
p1.PrintName();
return 0;
}Select one:a. Travisb. John Johnc. Travis Travisd. John Travis
Feedback
The correct answer is: John Travis
Question 10
Correct2.50 points out of 2.50Flag question
Question text
Which of the following lines contains a syntax error?
struct datedm {
int day;
string month;
};
int main() {
datedm date;
date->month = “July”;
date.day = 27;
// main program
return 0;
}Select one:a. struct datedm {b. datedm date;c. date->month = “July”;
d. date.day = 27;
Feedback
The correct answer is: date->month = “July”;
Question 11
Correct2.50 points out of 2.50Flag question
Question text
Which of the following defines a member function PrintSchedule of the class Schedule, returning nothing, and having one int parameter named year?Select one:a. void Schedule.PrintSchedule(int year) { /* Function code */ }b. void Schedule::PrintSchedule(int year) { /* Function code */ }
c. Schedule::PrintSchedule(int year) { /* Function code */ }d. void Schedule->PrintSchedule(int year) { /* Function code */ }
Feedback
The correct answer is: void Schedule::PrintSchedule(int year) { /* Function code */ }
Question 12
Correct2.50 points out of 2.50Flag question
Question text
Which of the following calls the function Sum by passing in two timehm structs (t1 and t2) and storing the result in a timehm struct t3?Select one:a. t3 = timehm.Sum(t1, t2);b. t3 = timehm->Sum(t1, t2);c. timehm = Sum(timehm, timehm);d. t3 = Sum(t1, t2);
Feedback
The correct answer is: t3 = Sum(t1, t2);
Question 13
Correct2.50 points out of 2.50Flag question
Question text
What is the output of the following code?
int main() {
vector<int> nums;
int i = 0;
nums.push_back(4);
nums.push_back(3);
nums.push_back(2);
nums.push_back(1);
for(i = 0; i < nums.size(); ++i) {
cout << nums.at(i) << ” “;
}
return 0;
}Select one:a. 4 3 2 1
b. 1 2 3 4c. 0 1 2 3d. 3 2 1 0
Feedback
The correct answer is: 4 3 2 1
Question 14
Correct2.50 points out of 2.50Flag question
Question text
Which of the following lines contains a syntax error?
struct person {
double heightInCM;
double weightInKG;
string fullName;
} Select one:a. struct person {b. double heightInCM;c. string fullName;d. }
Feedback
The correct answer is: }
Question 15
Correct2.50 points out of 2.50Flag question
Question text
What is the output of the last cout statement in the following code, assuming the user first enters “Travis” then presses enter, then enters “The grass is always greener” then presses enter.
int main() {
string name;
string favQuote;
cout << “Enter your name: “;
getline(cin, name);
cout << “Enter your favorite quote: “;
cin >> favQuote;
cout << name << ” likes the quote: ” << favQuote;
return 0;
}Select one:a. Travis likes the quote: The
b. Travis likes the quote: The grass is always greenerc. The grass is always greener likes the quote: Travisd. No output. Error in code.
Feedback
The correct answer is: Travis likes the quote: The
Question 16
Correct2.50 points out of 2.50Flag question
Question text
Which of the follow will NOT cause double change = 0; to output “0.00”?Select one:a. cout << fixed << setprecision(2) << change;b. cout << setprecision(3) << change;
c. cout << showpoint << setprecision(3) << change;d. All of the above cause output to be “0.00”.
Feedback
The correct answer is: cout << setprecision(3) << change;
Question 17
Correct2.50 points out of 2.50Flag question
Question text
Given the following class definition, which of the following is an illegal Pet variable declaration?
class Pet {
Pet();
Pet(string name);
Pet(string breed, string name);
Pet(int age, string name);
// rest of class code
};Select one:a. Pet myPet(7, “Momo”);b. Pet myPet(3);
c. Pet myPet(“Tempura”);d. Pet myPet;
Feedback
The correct answer is: Pet myPet(3);
Question 18
Correct2.50 points out of 2.50Flag question
Question text
If a program does not have “using namespace std;” but does have “#include <iostream>”, then which of the following is the beginning of a valid cout statement?Select one:a. coutb. std->coutc. std::cout
d. namespace::cout
Feedback
The correct answer is: std::cout
Question 19
Correct2.50 points out of 2.50Flag question
Question text
Which of the following is the declaration of a vector called person of type height which is a struct with two integer data members ft and in?Select one:a. vector<height> person;
b. vector<height(int ft, int in)> person;c. vector<height<int, int>> person;d. height<vector<int,int>> person;
Feedback
The correct answer is: vector<height> person;
Question 20
Correct2.50 points out of 2.50Flag question
Question text
What is the output of the following code given the program was called using the command-line:
a.out infile.txt outfile.txt auxfile.dat
int main(int argc, char* argv[]) {
cout << argv[2];
return 0;
}Select one:a. infile.txtb. outfile.txt
c. infile.txt outfile.txt auxfile.datd. None of the above.
Feedback
The correct answer is: outfile.txt
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"
