|
|
 |
|
|
|
|
BookName bookOut [NUMBER_OF_BOOKS ];
PersonName borrower [NUMBER_OF_BOOKS];
BookName bookIn;
PersonName name; |
|
|
|
 |
|
|
|
|
mark the following statements valid or invalid. (Assume the header file string.h has been included.) |
|
|
|
 |
|
|
|
|
a. cout << bookIn;
b. cout << bookOut;
c. for (i = 0; i < NUMBER_OF_BOOKS; i++)
cout << bookOut[i] << endl;
d. if (bookOut[3] > bookIn)
cout << bookIn;
e. for (i = 0; i < NUMBER_OF_BOOKS; i++)
if (strcmp(bookIn, bookOut[i]) == 0)
cout << bookIn << '' << borrower[i] << endl;
f. bookIn = "Don Quixote"
g. cout << name[2]; |
|
|
|
|
|
|
|
|
10. Write code fragments to perform the following tasks, using the declarations given in Exercise 9. Assume that the books listed in bookOut have been borrowed by the person listed in the corresponding position of borrower. |
|
|
|
|
|
|
|
|
a. Write a code fragment to print each book borrowed by name. |
|
|
|
|
|
|
|
|
b. Write a code fragment to count the number of books borrowed by name. |
|
|
|
|
|
|
|
|
c. Write a code fragment to count the number of copies of bookIn that have been borrowed. |
|
|
|
|
|
|
|
|
d. Write a code fragment to count the number of copies of bookIn that have been borrowed by name. |
|
|
|
|
|
|
|
|
Programming Warm-Up Exercises |
|
|
|
|
|
|
|
|
1. Write a C++ value-returning function Index that searches an int array list for a value item and returns its place in the array. There are length values in list. If item is not in the array, Index should return -1. |
|
|
|
|
|
|
|
|
2. Write a C++ value-returning function Count that counts the occurrences of a value item, of simple type ItemType, in an unsorted array numList. There are length items in numList. |
|
|
|
|
|
|
|
|
3. Write a C++ value-returning function that receives two int arrays (arr1 and arr2) of length length. This function should return the product of all components of arr2 for which the corresponding components of arr1 are negative. |
|
|
|
|
|
|
|
|
4. Write a C++ value-returning function Found that searches a float array list for a float value greater than the value of item. If such a value is found, the function returns TRUE; otherwise, FALSE is returned. The number of components in list is passed as a parameter. |
|
|
|
|
|
|
|
|
5. Rewrite SearchOrd to give it an additional formal parameter overflow. If length is greater than or equal to MAX_LENGTH, overflow is TRUE, an appropriate error message is printed, and the search is not made. Otherwise, overflow is FALSE. The constant MAX_LENGTH may be accessed globally. Change the function documentation to reflect this change. |
|
|
|
|
|