Unlock access to all the studying documents.
View Full Document
Copyright Cengage Learning. Powered by Cognero.
1. You can declare struct variables when you define a struct.
2. In structs, you access a component by using the struct name together with the relative position of the
component.
3. To access a structure member (component), you use the struct variable name together with the member name; these
names are separated by a dot (period).
4. You can use an assignment statement to copy the contents of one struct into another struct of the same type.
Copyright Cengage Learning. Powered by Cognero.
{
string name;
int ID;
double gpa;
}
int struct studentType
{
ID;
}
struct studentType
{
int ID = 1;
};
13. Consider the following struct definition:
struct rectangleData
{
double length;
double width;
double area;
double perimeter;
};
Which of the following variable declarations is correct?
rectangleData myRectangle;
rectangleData rectangle = new rectangleData();
Copyright Cengage Learning. Powered by Cognero.
14. Typically, in a program, a struct is defined ____ in the program.
before the definitions of all the functions
after the definitions of all the functions
15. An array name and index are separated using ____.
16. The syntax for accessing a struct member is structVariableName____.
17. Consider the following statements:
struct rectangleData
{
double length;
double width;
double area;
Copyright Cengage Learning. Powered by Cognero.
double perimeter;
};
rectangleData bigRect;
Which of the following statements correctly initializes the component length of bigRect?
18. In C++, the ____ symbol is an operator, called the member access operator.
19. Consider the following statements:
struct rectangleData
{
double length;
double width;
double area;
double perimeter;
};
rectangleData bigRect;
Which of the following statements is valid in C++?
perimeter = 2 * (length + width);
Copyright Cengage Learning. Powered by Cognero.
20. Consider the following statements:
struct personalInfo
{
string name;
int age;
double height;
double weight;
};
struct commonInfo
{
string name;
int age;
};
personalInfo person1, person2;
commonInfo person3, person4;
Which of the following statements is valid in C++?
21. Consider the following statements:
struct studentType1
{
string name;
int ID;
double gpa;
Copyright Cengage Learning. Powered by Cognero.
};
studentType1 student1, student2;
struct studentType2
{
string name;
int ID;
double gpa;
};
studentType2 student3, student4;
Which of the following statements is valid in C++?
student1.ID = student3.ID;
22. You can assign the value of one struct variable to another struct variable of ____ type.
23. To compare struct variables, you compare them ____.
Copyright Cengage Learning. Powered by Cognero.
26. Consider the following statements:
struct rectangleData
{
double length;
double width;
double area;
double perimeter;
};
rectangleData bigRect;
Which of the following statements is valid in C++?
cin >> bigRect.length >> width;
27. A struct variable can be passed as a parameter ____.
either by value or by reference
Copyright Cengage Learning. Powered by Cognero.
supplierType supplier;
string modelNo;
double cost;
};
applianceType applianceList[25];
Which of the following statements correctly initializes the cost of each appliance to 0?
applianceList.cost[25] = 0;
for (int j = 1; j < 25; j++)
applianceList.cost[j] = 0;
for (int j = 0; j < 25; j++)
applianceList.cost[j] = 0;
34. Consider the following statements:
struct supplierType
{
string name;
int supplierID;
};
struct paintType
{
supplierType supplier;
string color;
string paintID;
};
paintType paint;
What is the data type of paint.supplier?