MULTIPLE CHOICE. Choose the one alternative that best completes the statement or
ID: 3694879 • Letter: M
Question
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
1) Consider the following structure declaration:
1)
struct registered { string title;
int isbn;
int quantity; float price;
};
How many members are in this structure declaration?
A)
0
B)
3
C)
4
D)
5
2) Consider the following structure declaration:
2)
struct registered {
string title;
int isbn;
int quantity; float price;
};
How many variables of type "registered" are declared in this structure?
A)
0
B)
1
C)
3
D)
4
3) Consider the following structure declaration:
3)
struct registered {
string title;
int isbn;
int quantity; float price;
} chem1, maht3, prog2;
How to initial the title of chem1?
cout << "Enter the title of chem1 " << endl; cin >> chem1.title;
cout << "Enter the title of chem1 " << endl; getline(cin, chem1.title);
cout << "Enter the title of chem1 " << endl;getline(cin, chem1 -> title);
cout << "Enter the title of chem1 " << endl; cin >> prog2.title;
1
4) Consider the following structure declaration: 4)
struct point { char c; int x; int y;
};
How to initialize the point M (3, 4) and display it as: coordinates of M are 3 and 4 passing the argument by value?
A) void display (point & p)
{ cout << " Coordinates of point " << p.c << " are " << p.x << " and " << p.y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 4; display(s); system("pause");
return 0;}
B) void display (point * k)
{ cout << " Coordinates of point " << k -> c << " are " << k -> x << " and " << k -> y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 8; display(&s); system("pause");
return 0;}
void display (point * k)
{ cout << " Coordinates of point " << (*k).c << " are " << (*k).x << " and " << (*k).y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 9; display(&s); system("pause");
return 0;}
D) void display (point p)
{ cout << " Coordinates of point " << p.c << " are " << p.x << " and " << p.y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 4; display(s); system("pause");
return 0;}
2
5)
struct point {
char c;
5)
int x;
int y; };
void display (point * k)
{ cout << " Coordinates of point " << (*k).c
<< " are " << (*k).x
<< " and " <<
(*k).y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 4; display(&s);
system("pause");
return 0;}
In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by
A)
value
B)
reference
C)
address
D)
void
6)
struct point {char c; int x;
int y; };
6)
void display (point * k)
{ cout << " Coordinates of point " << k -> c
<< " are " << k -> x
<< " and " << k ->
y << " ";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 4; display(&s);
system("pause");
return 0;}
In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by
A)
value
B)
reference
C)
address
D)
void
7)
struct point { char c;
7)
int x;
int y; };
void display (point & p)
{ cout << " Coordinates of point " << p.c << " are " << p.x << " and " << p.y << "
";}
int main()
{ point s; s.c = 'M'; s.x = 3; s.y = 4; display(s);
system("pause");
return 0;}
In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by
A)
value
B)
reference
C)
address
D)
void
3
8) Consider the following code:
8)
struct song { string singer; string album; int year; float price; } Thriller;
song *psong; psong = &Thriller; string mystr;
What is psong in the snippet above?
A)
a variable
B)
a pointer pointing to singer
C)
a pointer pointing to album
D)
a pointer pointing to Thriller
9) When initializing the members of this structure using pointer, which of the following format do
9)
you advise?
cin >> Thriller.year;
getline (cin, mystr);
(stringstream) mystr >> psong -> year;
cin >> year;
getline (cin, Thriller.year)
SHORT ANSWER. Write the word or phrase that best completes each statement or answers the question.
10)
What is the difference between these two expressions:
10)
expression 1: psong -> year
expression2: (*psong).year
TRUE/FALSE. Write 'T' if the statement is true and 'F' if the statement is false.
11)
The header file needed to use getline ()is <string>
11)
12)
Thre header file to use stringstream is <iostream>
12)
4
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
1) Consider the following structure declaration:
1)
Explanation / Answer
Answer 1- Option C - There are 4 members in the structure declaration.
string title;
int isbn;
int quantity;
float price;
Answer 2- Option A - There are 0 members in the structure declaration of type REGISTERED.
string title;
int isbn;
int quantity;
float price;
Answer 3- To initialize the member variable title of chem1
cout << "Enter the title of chem1 " << endl; cin >> chem1.title;
Answer 4- OPTION D - to initialize the point M (3, 4) and display it as: coordinates of M are 3 and 4 passing the argument by value
void display (point p)
{
cout << " Coordinates of point " << p.c << " are " << p.x << " and " << p.y << " ";
}
int main()
{
point s;
s.c = 'M';
s.x = 3;
s.y = 4;
display(s);
system("pause");
return 0;
}
Answer 5- OPTION B - In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by reference.
Answer 6- OPTION B - In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by reference.
Answer 7- OPTION A - In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by Value.
Answer 8- OPTION D - psong in the snippet above is a pointer pointing to Thriller.
Answer 9 OPTION A - When initializing the members of this structure using pointer, I advise to use
cin >> Thriller.year;
Answer 11 - TRUE, The header file needed to use getline() is <string>
Answer 12 - TRUE, The header file to use stringstream is <iostream>
displayed (as: coordinates of M are 3 and 4) passing the argument by reference.
Answer 6- OPTION B - In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by reference.
Answer 7- OPTION A - In the code snippet above, the structure point M is initialized (3, 4) and
displayed (as: coordinates of M are 3 and 4) passing the argument by Value.
Answer 8- OPTION D - psong in the snippet above is a pointer pointing to Thriller.
Answer 9 OPTION A - When initializing the members of this structure using pointer, I advise to use
cin >> Thriller.year;
Answer 11 - TRUE, The header file needed to use getline() is <string>
Answer 12 - TRUE, The header file to use stringstream is <iostream>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.