www.gibmonks.com

Main Page

[Page 1102 (continued)]

### Self-Review Exercises

 22.1 Fill in the blanks in each of the following: A(n)__________is a collection of related variables under one name.The bits in the result of an expression using the__________operator are set to one if the corresponding bits in each operand are set to one. Otherwise, the bits are set to zero.The variables declared in a structure definition are called its__________.The bits in the result of an expression using the__________operator are set to one if at least one of the corresponding bits in either operand is set to one. Otherwise, the bits are set to zero.Keyword__________introduces a structure declaration.Keyword__________is used to create a synonym for a previously defined data type.Each bit in the result of an expression using the__________operator is set to one if exactly one of the corresponding bits in either operand is set to one. Otherwise, the bit is set to zero.The bitwise AND operator & is often used to__________bits (i.e., to select certain bits from a bit string while zeroing others).A structure member is accessed with either operator__________or__________.The__________and__________operators are used to shift the bits of a value to the left or to the right, respectively. 22.2 State whether each of the following is true or false. If false, explain why. Structures may contain only one data type.Members of different structures must have unique names.Keyword typedef is used to define new data types.Structures are always passed to functions by reference. 22.3 Write a single statement or a set of statements to accomplish each of the following: Define a structure called Part containing int variable partNumber and char array partName, whose values may be as long as 25 characters.Define PartPtr to be a synonym for the type Part *.Use separate statements to declare variable a to be of type Part, array b[ 10 ] to be of type Part and variable ptr to be of type pointer to Part.Read a part number and a part name from the keyboard into the members of variable a.Assign the member values of variable a to element three of array b.Assign the address of array b to the pointer variable ptr.Print the member values of element three of array b, using the variable ptr and the structure pointer operator to refer to the members. [Page 1103] 22.4 Find the error in each of the following: Assume that struct Card has been defined as containing two pointers to type charnamely, face and suit. Also, the variable c has been declared to be of type Card, and the variable cPtr has been declared to be of type pointer to Card. Variable cPtr has been assigned the address of c.```cout << *cPtr.face << endl; ```Assume that struct Card has been defined as containing two pointers to type charnamely, face and suit. Also, the array hearts[ 13 ] has been declared to be of type Card. The following statement should print the member face of element 10 of the array.```cout << hearts.face << endl; ``` ```struct Person { char lastName[ 15 ]; char firstName[ 15 ]; int age; } ``` Assume that variable p has been declared as type Person and that variable c has been declared as type Card.```p = c; ``` 22.5 Write a single statement to accomplish each of the following. Assume that variables c (which stores a character), x, y and z are of type int; variables d, e and f are of type double; variable ptr is of type char * and arrays s1[ 100 ] and s2[ 100 ] are of type char. Convert the character stored in variable c to an uppercase letter. Assign the result to variable c.Determine if the value of variable c is a digit. Use the conditional operator as shown in Figs. 22.1822.20 to print " is a " or " is not a " when the result is displayed.Convert the string "1234567" to long, and print the value.Determine whether the value of variable c is a control character. Use the conditional operator to print " is a " or " is not a " when the result is displayed.Assign to ptr the location of the last occurrence of c in s1.Convert the string "8.63582" to double, and print the value.Determine whether the value of c is a letter. Use the conditional operator to print " is a " or " is not a " when the result is displayed.Assign to ptr the location of the first occurrence of s2 in s1.Determine whether the value of variable c is a printing character. Use the conditional operator to print " is a " or " is not a " when the result is displayed.Assign to ptr the location of the first occurrence in s1 of any character from s2.Assign to ptr the location of the first occurrence of c in s1.Convert the string "-21" to int, and print the value.