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 {
|
|
|
|
|
|
| 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 | 11) |
| |
| 12) | Thre header file to use stringstream is | 12) |
| |
4
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
