nocomments.cpp
.superswap.cpp
.void
pointers
might be useful. For example, consider the function
swap2() from the
example #2 which was discussed
in class on Thursday, June 27. Void pointers can be used to create
a more generic version of such a function, so that it would be able
to swap data of any type. As an exercise, implement a function
int swap(void *, void *, int)which should be able to swap two data items of a fixed size, but of arbitrary type. Please write also a short
main()
function
to test your swap()
on several different data types
(say, int
, char[]
, and a class or a
structure of your own design). Your program can be as simple as
creating 3 pairs of data items of corresponding data types (as
specified above), then swapping them, and displaying the results.harmonic.cpp
.
double recursive_harm(int)
described by the following recursive definition:
recursive_harm(n) = recursive_harm(n-1) + (1/n), if n >1 recursive_harm(n) = 1, if n = 1This recursive definition calculates a series
H(n)
like
the following one, called the harmonic series:
H(n) = 1 + (1/2) + (1/3) + (1/4) + (1/5) + ... + (1/n)The function
double recursive_harm(int)
defined above
is clearly not tail recursive because the return value of
the recursive call is used in an expression which becomes the
return value of the current call. (Therefore, each activation
must remain on the stack until it gets the return value of
subsequent activations.) Please define and implement a tail
recursive function
double tailrecur_harm(int, double)
that computes H(n)
. You can use an approach like the
one presented in our example 3
(factorials.cpp) and introduce an additional parameter to keep
a tally of the total value of the series computed thus far in the
recursion. Finally, round up your explorations by implementing an
iterative (non-recursive) function
double iterative_harm(int)
that would compute H(n)
by using a simple iteration,
without any recursion at all. Please write also a short
main()
function to test your three implementations
of various ways to compute H(n)
.list.cpp
.List
class by providing
an implementation of all the methods declared in the header.
Please follow the method specifications outlined in corresponding
comments of the header file.addressbook.cpp
.addressbook
application which would allow one to
store/retrive addresses very efficiently. Start by writing a class
Address
(or a struct - it is your choice) whose instance
represents a person's mailing address. It should have separate fields
for the name, street address, city, state and ZIP code. Please do not
forget to think about what field should be used as a (unique) hash
key associated with a particular instance of Address
.
Next, write a simple main()
function which would
initialize an addressbook
and then allow user to store
an unlimited number of mailing addresses (instances of your
Address
class or struct) in it. The
addressbook
itself should be implemented as a
Chained Hash Table, i.e. it should be an instance of the
CHTbl
class of
Example #10. (You are allowed
to reimplement methods of CHTbl
as you see fit, but
you should not change the public interface of the class declared in
chtbl.h.) At a minimum your
application should allow user to enter new address, to search for a
particular person's address, and to delete a specified address.parser.cpp
.parser
application which
would use the data structures and algoritms we have discussed:
to do its work. You would also need to design and implement a method
with signature similar to this:
BiTree* parse(char[])which would build an expresion tree out of an arithmetic expression received as an input. Except for these requirements, the rest of program design decisions is left up to your imagination, skill, and amount of free time you have on your hands. Have fun!
/*
Your name
Your Student ID
Your e-mail address
I certify that the following represents my own independent work and
conforms with the guidelines of academic honesty described in the
course syllabus.
*/
Any homework submitted without this header will not be graded,
and you will receive zero credit for it.Borland C++ Builder
Microsoft Visual C++
gcc
via the UNIX prompt