Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 11 Starting out with C++ Structured Data


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


 

Chapter Eleven

MULTIPLE CHOICE

1. This describes only the general characteristics of an object.
a. initialization
b. abstraction
c. detailed specification
d. initiation
e. None of these

2. Which of the following is an example of a C++ primitive data type?
a. unsigned short int
b. long double
c. unsigned char
d. All of these
e. None of these

3. This is required after the closing brace of the structure declaration.
a. square bracket
b. period
c. semicolon
d. colon
e. None of these

4. Look at the following statement.

bookList[2].publisher[3] = ‘t’;

This statement…
a. is illegal in C++.
b. will change the publisher’s name of the second book in bookList to ‘t’.
c. will store the character ‘t’ in the fourth element of the publisher member of booklist[2].
d. will ultimately result in a runtime error.
e. None of these.

5. When a structure is passed _________to a function, its members are not copied.
a. by reference
b. by value
c. Neither of these

6. Passing a structure as a constant reference parameter to a function:
a. can potentially result in changes to the structure’s members.
b. guarantees not to result in changes to the structure’s members.
c. will always change the structure’s members.
d. All of these
e. None of these

7. This is like a structure, except all members occupy the same memory area.
a. array
b. union
c. structure pointer
d. array of pointers
e. None of these

8. Members of a(n) ________ union have names, but the union itself has no name.
a. anonymous
b. dereferenced
c. organized
d. declared
e. None of these

9. If Circle is a structure tag, the statement

Circle doSomething(Circle c2)

can be the header line for a function that
a. determines and returns the area of a circle
b. takes a Circle structure as a parameter, does something, and returns a Circle structure
c. operates on a constant reference to a Circle structure
d. takes two Circle parameters and does something
e. None of these

10. Which of the following assigns a value to the hourlyWage member of employee[2]?
a. employee[2]->hourlyWage = 50.00;
b. employee2.hourlyWage = 7.50;
c. hourlyWage[2].employee = 29.75
d. employee[2].hourlyWage = 100.00;
e. None of these

11. You may use a pointer to a structure as a
a. function parameter.
b. structure member.
c. function return type.
d. All of these.
e. None of these

12. If an anonymous union is declared globally (outside all functions), it must be:
a. empty
b. declared static
c. explicitly declared “global”
d. initialized and used outside any function
e. None of these

13. Data types that are created by the programmer are known as:
a. variables
b. abstract data types (ADT)
c. functions
d. parameters
e. None of these

14. Before a structure can be used, it must be
a. declared
b. deallocated
c. initialized
d. All of these
e. None of these

15. The name of the structure is referred to as its
a. data type
b. argument
c. parameter
d. tag
e. None of these

16. This allows you to access structure members.
a. structure access operator
b. dot operator
c. #include directive
d. getmember function
e. None of these

17. A function ___________ return a structure.
a. may
b. may not
c. will always
d. cannot possibly
e. None of these

18. A structure pointer contains:
a. The address of a structure variable
b. The dereferenced address of a structure tag
c. The name and address of the structure tag
d. The address of a structure tag
e. None of these

19. To dereference a structure pointer, the appropriate operator is:
a. the ampersand, &
b. an asterisk, *
c. the structure pointer operator, ->
d. the dereference operator, <-
e. None of these

20. If a is a structure variable and p, a pointer, is a member of the structure, what will the following statement do?

cout << *a.p;

a. Output the dereferenced value pointed to by p
b. Result in a compiler error
c. Output the address stored in p
d. Output the value stored in a
e. None of these

21. A structure _____________ contain members of the same data type.
a. cannot
b. can
c. shouldn’t
d. None of these

22. Which of the following statements outputs the value of the gpa member of element 1 of the student array?

a. cout << student1.gpa;
b. cout << firstStudent.gpa;
c. cout << student[1].gpa;
d. cout << student1->gpa;
e. None of these

23. If Circle is a structure tag, the statement Circle *pcirc;
a. declares a structure variable called *pcirc
b. declares a structure pointer called pcirc
c. is illegal in C++
d. initializes a Circle pointer
e. None of these

24. A good reason to pass a structure as a constant reference is:
a. to prevent changes to the structure members
b. to ensure changes to the structure members
c. to slow down the function’s execution, preventing errors
d. to speed up the function’s modification of the structure members
e. None of these

25. A declaration for an enumerated type begins with this key word.
a. enumerated c. enum
b. enum_type d. ENUM

26. With an enumerated data type, the enumerators are stored in memory as
a. strings c. characters
b. integers d. doubles

27. Look at the following declaration.

enum Tree { OAK, MAPLE, PINE };

In memory, what value will the MAPLE enumerator be stored as?

a. “MAPLE” d. 1
b. 2 e. 1.0
c. ‘M’

28. Look at the following declaration.

enum Tree { OAK, MAPLE, PINE };

What is the value of the following relational expression?

OAK > PINE

a. true c. This is an error. You cannot compare enumerators with relational operators.
b. false

29. Look at the following structure declaration.

struct Employee
{
string name;
int idNum;
};

In this declaration, Employee is

a. a member c. a tag
b. an array d. None of these

30. Look at the following structure declaration.

struct Employee
{
string name;
int idNum;
};

In this declaration, idNum is

a. a member c. a tag
b. an array d. None of these

TRUE/FALSE

1. True/False: A struct can contain members with varying data types.

2. True/False: Any mathematical operations that can be performed on regular C++ variables can be performed on structure members.

3. True/False: Structure variables may be passed as arguments to functions.

4. True/False: The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.

5. True/False: The expression s->m; indicates that s is a structure pointer and m is a structure member.

6. True/False: A function cannot modify the members of a structure.

7. True/False: If a function is legally prototyped to return an integer value, it can return a structure member that is an integer data type.

8. True/False: You can define any number of union variables, but each variable can only store the value of one member at a time.

9. True/False: When a programmer creates an abstract data type, he or she can decide what values are acceptable for the data type, as well as what operations may be performed on the data type.

10. True/False: It is possible to output the contents of all members of a structure variable using a cout << statement followed by the name of the structure variable. 

11. True/False: It is possible for a structure variable to be a member of another structure variable. 

12. True/False: The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.

13. True/False: It is possible for a structure to contain as a member a pointer to its own structure type.

14. True/False: An anonymous union declaration actually creates the member variables in memory.

15. True/False: A union can only have one member.

16. The names of the enumerators in an enumerated data type must be enclosed in quotation marks.

17. You cannot directly assign an integer value to an enum variable.

18. You cannot directly assign an enumerator to an int variable.

19. Look at the following structure declaration.

struct Circle
{
double centerX;
double centerY;
double radius;
};

Assume that circle1 and circle2 are variables of the Circle type, and their members have been initialized. Is it true or false that the following if statement correctly determines whether the two variables’ members contain the same data:

if (circle1 == circle2)

20. The following union declaration appears on a system uses 4-byte ints and 8-byte doubles.

union Numbers
{
int integerNumber;
double doubleNumber;
};

Numbers myNumber;
myNumber.integerNumber = 1;

True or False: After this code executes, the myNumber variable will occupy 4 bytes of memory.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!