< previous page page_829 next page >

Page 829
Programming Warm-up Exercises
1. a. Write a struct declaration to contain the following information about a student:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Name (string of characters)
Social security number (string of characters)
Year (freshman, sophomore, junior, senior)
Grade point average (floating point)
Sex (M, F)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Declare a struct variable of the type in part (a), and write a program segment that prints the information in each member of the variable.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Declare roll to be an array of 3000 structs of the type in part (a).
2. Write a program segment to read in a set of part numbers and associated unit costs. Keep the data sorted by part number as you read it in. Use an array of structs with two members, number and cost, to represent each pair of input values. Assume the end-of-file condition terminates the input.
3. Write a hierarchical C++ struct declaration to contain the following information about a student:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Name (up to 30 characters)
Student ID number
Credit hours to date
Number of courses taken
Course grades (a list of up to 50 elements containing an integer course ID and the letter grade)
Date first enrolled (month and year)
Year (freshman, sophomore, junior, senior)
Grade point average
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Each struct and enumeration type should have a separate type declaration.
4. a. Declare a struct type named AptType for an apartment locator service. The following information should be included:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
Landlord (a string of up to 20 characters)
Address (a string of up to 20 characters)
Bedrooms (integer)
Price (floating point)
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Declare available to be an array of up to 200 structs of type AptType.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Write a function to read values into the members of a variable of type AptType. (The struct variable should be passed as a parameter.) The order in which the data is read is the same as that of the items in the struct.
5. Using the declarations given in Exam Preparation Exercise 2, write statements to do the following:
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
a. Assign the contents of the chart member of aMap to aRef.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
b. Assign aMap to the fourth element of guide.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
c. Copy aCode to the mapCode member of the tenth element of guide.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
d. Compare the first character in aCode and the first character in the mapCode member of the second element of guide. If they are equal, then output the mapCode member and the style member of the second element of guide.

 
< previous page page_829 next page >