YOUR NAME:
CSCI 159 Quiz 5 (F24N01/02) Monday lab
The quiz is closed book, closed notes, no electronics permitted, and to be completed as a
strictly individual exercise. You are permitted one double-sided 8.5" x 11" sheet of notes.
There are two questions, worth a total of 10 marks. Attempt both questions, answering directly on the exam paper.
Note that when a code segment is requested you are only expected to put the requested lines of code,
not the rest of a larger program it would be part of. If a complete program is requested, on
the other hand, you should provide the entire program (#includes, int main, etc).
Question 1: structs [5 marks]
(i) Provide a definition for a struct type named UserInfo that has two
fields, both of type string, named uName and uContact.
(ii) Write a function named fillUser that takes one parameter of type
UserInfo, passed by reference, and fills the uName and uContact fields with text
obtained through cin.
(iii) Write a function named prtUser that takes one parameter of type
UserInfo and displays the uName and uContact fields.
Question 2: arrays of structs [5 marks]
Suppose we have a struct definition as shown below, and getText() and getNumber() functions that
each get and return a suitable string/float value from the user.
Write the fillAll function below so that it makes appropriate use of the getText and getNumber functions
to fill in both fields of each struct in the array.
struct StoredData {
string name;
float result;
};
// fills the name and result fields of each of the first N elements of the array
void fillAll(StoredData arr[], int N);