|
|
|
|
|
|
|
6. A sparse matrix is a matrix (two-dimensional array) in which the great majority of elements are zero. It is inefficient to store these as two-dimensional arrays because most of the elements do not contain any useful information. Instead, the elements that are not equal to zero should be stored as an array of structs where the first two members of the struct contain the row and column number and the third member contains the element. For example, this matrix |
|
|
|
|
|
|
|
|
would be stored as follows: |
|
|
|
 |
|
|
|
|
Write a C++ program that reads a sparse matrix and converts it into an array of structs of this form. The program should then output the structs (properly labeled). |
|
|
|
|
|
|
|
|
1. In both case studies, we represented a person's area code as an int value. Printing an int area code works fine for North American phone numbers, where area codes are greater than 200. But international area codes may start with a zero. Our programs would print an area code of 052 as 52. Suggest two ways of accommodating international area codes so that leading zeros are printed. |
|
|
|
|
|
|
|
|
2. Change the Campaigning for a Candidate case study so that the sentinel line consists of 15 Zs onlyno first name, area code, or phone number. Specifically, rewrite the GetRecords function so that input of the first name, area code, and phone number are not attempted if the last name is all Zs. |
|
|
|
|
|
|
|
|
3. Recode the MergeLists program so that the sentinel records are not stored in any arrays in memory. Function GetRecords should input data until the sentinel record is encountered, returning both the list and its length. Thereafter, whenever a list is passed as a parameter to a function, its length should be passed also. |
|
|
|
|
|