The quiz is open notes, open book, and you are permitted to use your linux
accounts to write/check practice code if desired. For example, you could
use the following to edit, compile, and check code in a quest1.cpp
file:
gedit quest1.cpp &
g++ quest1.cpp -o quest1x
./quest1x
There are two questions and you have 60 minutes to complete the quiz.
The quiz must be completed as a completely individual exercise: you cannot
request or accept help from any other source (human or ai) other than the
course instructor, and you cannot give help to anyone else for the quiz.
If you finish early you can leave or stay and work quietly while others
finish their quizzes.
Question 1: structs and arrays
Suppose we have the following struct, used to keep track of the amount of cash someone has:
struct CashCarried {
string name; // name of person carrying the cash
float cash; // amount of cash they're carrying
};
Complete the sumCash function below that takes an array of CashCarried structs
and computes and returns the total cash carried by everyone listed in the array
(add up all the cash fields and return the result). The N parameter
specifies how many entries there are in the array.
float sumCash(CashCarried people[], int N)
Question 2: checking a struct
Based on the same CashCarried struct as in question 1,
the checkEntry function below checks the validity of a struct
and returns true if it is valid, false otherwise.
The rules for validity are:
(i) the length of the name must be at least 3 characters (checkable with .length())
(ii) the cash amount cannot be negative.
Complete the checkEntry function.
bool checkEntry(CashCarried entry)