Lecture 7
- Quiz 1: write a menu-driven user-interface (as a main
program) for testing a function (a test driver). Options:
- 0 = enter data
- 1 = print data
- 2 = call function
- 4 = exit
- Recap: struct in C/C++.
- Example:
struct CustRec
{
int id;
float balance;
};
- Declare variables of this type:
CustRec c1, c2;
- Initialize
- Access components.
- Arrays of records.
- Passed as parameters. IN: value is copied. Example: sorting
an array of CustRec by id or by balance.
- In-class lab (nothing to submit):
Example of a sorting program using struct and
templates in C++. Use the code of the
program for selection sort from last time. Modify it:
- To make it as readable as possible (add spaces, dividers,
your name, account, etc.), comments.
- Add to it the feature to sort not only an array of characters
and an array of integers, but also an array of CustRec, by id or
by balance. Use templates.
- Extra credit: add a menu-driven interface in the test
driver (main function) to allow the user to choose what to do
(i.e. what kind of data to sort).
- Preview of
homework 4. Use
this as a model. It is a program to
test a Seelction Sort function, done with templates and passing
functions as paramaters. ANother solution is to use the idea
discussed in class, of using a variable to tell the program how
to compare the data, in each case (and there will be lots of if's
in some functions).