lab2 directory, and grab a copy of the lab 2 code. Look at it, make yourself happy with
it, compile it, and verify that it works.
README file.
double variables, rather than arrays of
int. This should be a simple change. Make sure
everything still works.
private block, but you should move it back to the
public block, and provide an implementation for it. Make sure you
read the relevant parts of the book, and review your notes. This
should be legal:
Array a(10);
Array b(10);
Array c(10);
a = b = c;
but this should not
Array a(10);
Array b(5);
a = b;
You need to decide on the appropriate behavior (and document it in
your README file).
double
argument, and assigns this value to all elements of the array when
it is created:
Array a(10, 3.14);
Make sure that you test this new functionality.
Array array(10);
array = 1.23; // Assignment operator (set all elements)
double *p = array; // double * cast operator;
cout << array << endl; // Output stream
cin >> array; // Input stream
Note that the assignment operator for this part is not the same as
the assignment operator that is parameterized by another class
instance (which you should already have). Remember to keep adding
tests for the new code as you write it.
For the functions that print out array values, do not
print spaces between the array entries. This does not make much
sense at the moment, but it will in a while. For example, if you
have an array with four entries, 1.1, 2.2, 3.3, and 4.4, your
print routines should print 1.12.23.34.4. A line like this
cout << "A" << array << "A" << endl;
should print out
A1.12.23.34.4A
int. Document any design choices in your
README.
lab2.cpp, Array.H,
and Array.cpp files. Make sure that it passes all of
the tests for the first lab. For this assignment, it is
acceptable to ignore the requirement for specific precision in the
output, since we haven't talked about stream formatting yet.
-size n, which
specifies the size of the array that you will be using.
lab2 -size 100
Will read in 100 lines from the standard input, sort them, and
write them to the standard output.
lab2 -size 100 --random
Will generate 100 random numbers, and print them to the standard
output. You will probably find atoi() useful for
this part of the assignment.
time command, and report the speed in your
README file in plain English (ie don't cut and paste
the output of time). Now, recompile the code with bounds checking
turned off, and retime the same size of array. Report this in
your README.
Since you probably don't want to look at millions of doubles, you
can send them directly to the null device, /dev/null.
This is something that looks like a file, but which eats
everything sent to it. It's also colloquially called the
"bit bucket".
lab2 --random > /dev/null
-Wall
flag.
README, and
your Makefile. As with the previous lab, make sure you
list all of your source and header files in your
Makefile. Further details on exactly how to do this will
be available shortly.
iostreams to
printf and friends. You should go though your code
and make sure that all references to the printf
functions are removed.
stdio.h. These files have been replaced with files
that start with a c and lack the .h
extension, cstdio. You should prefer these in your
code.
using namespace
std; statements in your header files, since this will
pollute any files that include them.
friend functions or not.
Remember to document your design decisions in the
README file.
lab2 --random -size 2
is the same as
lab2 -size 2 --random
assert() through your code to
catch potential problems early. Anywhere that you know bounds on
the value of a variable is a candidate for an assertion.
x =
2; assigns a value of 2 to c. Please, don't
try for humor, since it rarely improves cranky TAs moods.
| Page written by Bill Smart. |