Please send questions to
st10@humboldt.edu .
A few random examples typed up during the Final Exam Review
(in the 10 am lab, after the bad projection connector was replaced!)
--------------------------------------------------------------------
(posted on request)
const int NUM_WIDGETS = 6;
string widget_names[NUM_WIDGETS];
say you have a function handle_strings with the signature:
// signature: handle_strings: string[] int -> bool
I can call handle_strings with argument widget_names
as in the example below:
cout << boolalpha << handle_strings(widget_names, NUM_WIDGETS)
<< endl;
******DYNAMIC ARRAY ALLOCATION EXAMPLE
boa *many_boas;
int num_boas;
cout << "how many boas? " << endl;
cin >> num_boas;
many_boas = new boa[num_boas];
// now, can just use many_boas like a typical array!
for (int i=0; i<num_boas; i++)
{
cout << many_boas[i].get_color() << endl;
}
delete [ ] many_boas; // use [ ] to free a
// dynamically-allocated array's
// memory!!!
*************************************
// CONSIDER the following function header:
double oddity(double *p1,
double& p2,
double my_array[],
int array_size)
// here is the signature for oddity:
// signature: oddity: double* double& double[] int -> double
*************************************
consider the headers:
void do_it(int val1, string name)
int do_that()
If I asked:
Write a C++ statement including a reasonable call to
the function do_it
do_it(13, "Carol");
Write a C++ statement including a reasonable call to
the function do_that
cout << do_that() << endl;
int quant = do_that();