Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

11... Which of the following lines contains a syntax error? class Person { publi

ID: 3877026 • Letter: 1

Question

11...

Which of the following lines contains a syntax error?

class Person {

   public:

       void PrintName() const { cout << name << endl; }

   private:

string name;

};

int main() {

   Person p;

   p.name = "Sally";

   p.PrintName();

   return 0;

}

Select one:

a. class Person {

b. void PrintName() { cout << name << endl; }

c. p.name = “Sally”;

d. p.PrintName();

12...

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 */ }

13...

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. cout

b. std->cout

c. std::cout

d. namespace::cout

14.....

Which of the following choices appropriately fills in the blank?

Characters written to cout are placed into a(n) _________.

Select one:

a. file

b. directory

c. buffer

d. hard disk

15.....

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 4

c. 0 1 2 3

d. 3 2 1 0

16...

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 directly

c. the system’s input devices directly

d. the hard disk

17....

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;

18....

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);

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;

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”.

Have to submit in the next 40 minutes.Please help asap

Explanation / Answer

11...
Which of the following lines contains a syntax error?
class Person {
public:
void PrintName() const { cout << name << endl; }
private:
string name;
};
int main() {
Person p;
p.name = "Sally";
p.PrintName();
return 0;
}
Select one:
Answer: Option c. p.name = “Sally”;
Explanation:
std::__cxx11::string Person::name is private within this context

12...

Which of the following defines a member function PrintSchedule of the class Schedule, returning nothing, and having one int parameter named year?

Select one:

Answer: Option b. void Schedule::PrintSchedule(int year) { /* Function code */ }

13...

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:

Answer: Option c. std::cout;

Explanation:

Program:

#include <iostream>

int main() {

std::cout;

return 0;

}

14.....

Which of the following choices appropriately fills in the blank?

Characters written to cout are placed into a(n) _________.

Select one:

Answer: Option c. buffer

15.....

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:

Answer: Option a. 4 3 2 1

Explanation:

Program:

#include <iostream>
#include <vector>
using namespace std;
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;
}

Output: 4 3 2 1

16...
Which of the following choices appropriately fills in the blank?
A read from cin will read characters from ____________________.
Select one:
Answer: Option a. a buffer

17....

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:
Answer: Option c. this->r = radius;

Explanation:

Program:

#include <iostream>
#include <vector>
using namespace std;
class Circle {
public:
void SetRadius(double radius);
double GetRadius() const;
private:
double r;
};
void Circle::SetRadius(double radius) {
r = radius;
this->r = radius;
return;
}
int main() {
  
return 0;
}

18...

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:
Answer: Option c. date->month = "July";
Explanation:
base operand of ‘->’ has non-pointer type ‘datedm’

19..

Which of the following will NOT cause the double pi = 3.14159; to output “3.1416”?

Select one:

ANswer: Option a. cout << fixed << setprecision(5) << pi; << endl;

Explanation:

Program:

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double pi = 3.14159;
cout << fixed << setprecision(5) << pi << endl;
return 0;
}

Output:

3.14159