CMPS 1063 Data Structures & ADTs

advertisement
CMPS 1063 Data Structures & ADTs
Lab 2 Using Array of Structs
1. Start a C++ project called lab2.
2. Type your name and lab2 in a comment at the top.
3. Include typical include statements and include string (or you can use array of
chars)
4. Declare a global constant MAXGUESTS to have the value of 25.
5. Declare a struct type named ResponseInfo that has three fields: name, attending
(bool) and numGuests (int).
6. Declare a type for an array of ResponseInfo with MAXGUESTS elements. (I
called it GuestList).
7. Declare (and comment) and define a function called getResponseInfo. It should
return a ResponseInfo struct. (It will get the data from the keyboard in response
to prompts.)
8. Declare (and comment) and define a function called computeTotalAttending. It
should receive the array and an integer number n (indicating the number of
response cards to process) and sum the number of guests attending for the n items.
9. Start a main.
10. Declare a variable of the type struct you did in step 5.
11. Write a for loop that will call getResponseInfo 5 times and store the returning
value in the array with one assignment statement.
12. Now write a call to computeTotalAttending, passing the array and the number 5.
13. Write a statement to display the total number of guests attending.
14. Add your system (“pause”) statement.
15. Compile and run it.
16. Demo this to your lab instructor.
17. After, sign the roster.
Download