|
| (Friday, October 31, 2003)
| Note that the due time for assignment 3 has been changed to Monday.
Also remember that the midterm is Monday.
Here are some things to expect on the midterm:
-
You may be given the code for a small program and be asked to find the
errors in the code. Errors could be incompatible types in expressions,
missing constructors, memory leaks, improper use of pointers, failure
to allocate space, use of pointers after the space is freed or recovered
from the stack, etc., etc.
-
Make sure you understand declarations, types, and expressions well.
You could be presented with various declarations and asked for the type of
expressions involving those variables. E.g., given int **p, the
type of (*p) is int *, i.e. pointer to int.
-
Review the right-left rule so that you
could create or analyze declarations involving arrays, pointers, and functions.
-
Know where copy constructors are used and the difference between initialization
and assignment.
-
Know the syntax of defining methods and overloaded operators for a class.
There could be questions that ask you to write some small methods for a
simple class definition.
-
Know that the type of this in a method of a class Foo is
pointer to Foo. If the method is constant, then this is
a pointer to a constant Foo. Know the syntax for declaring a method
to be constant.
-
Know the syntax for parameters passed by reference to a function, and how
call by reference differs from the call by value.
|
|
| (Monday, October 27, 2003)
| This Wednesday's office hour will be held at Room 100 from 10AM to 12PM. Welcome to come in! [Zhen Wu]
|
|
| (Monday, October 27, 2003)
| Here's some code to help you get started on the Rational class for
problem 3-2:
Start of Rational.h:
// Encapsulation of a rational number - a quotient of two integers
#include
class Rational {
public:
// Constructor defaults both arguments
Rational(int numerator = 0, int denominator = 1);
// Query methods for Rational components
...
// Member arithmetic operations
Rational & operator ++ (); // prefix
Rational operator ++ (int); // postfix
...
// Comparison operations
...
private:
// Data to store the value
...
};
// Formatted output
ostream & operator << (ostream & out, const Rational & r);
// Non member arithmetic operations
Rational operator + (const Rational & lop, const Rational & rop);
...
Some things to notice about this approach:
-
Although the driver code makes it look like there should be at least
four constructors, a constructor as shown will work for the three
cases no arguments, one argument, or two arguments. Is a copy
constructor necessary?
-
Does your implementation need a destructor?
-
The prototype for the output operator is given. Output operators
are necessarily defined as non-member functions (if they were member
functions, they would have to be members of the ostream class).
-
Prototypes for increment, both postfix and prefix, are given. The
integer argument to postfix increment is ignored, and only serves
to distinguish its signature from prefix.
-
A non-member prototype for addition is given - why do you think
we would implement this as a non-member function rather than a
member function?
-
The problem states (and the driver shows) that Rationals appear to
be in lowest terms. You can choose how you want to implement this.
You'll probably want to use a greatest common divisor algorithm somewhere.
|
|
| (Saturday, October 18, 2003)
| For examples of some ways to declare and use pointers to functions,
see func_pointer.c.
|
|
| (Wednesday, October 15, 2003)
| Here's some advice and hints on Assignment 2:
-
Your code should compile with the Solaris C++ compiler. For example,
if you put the driver code in ilisttest.c, the first problem would compile
as
% CC -o ilisttest ilisttest.c ilist.c
-
Hint for problem 2 - think of the two dimensional array as an array of arrays.
This means that you could set up a table of pointers, with a pointer to
each row. However, the space for the rows does not need to be allocated
separately for each row. You can allocate one big chunk for all the integers
and then set up your table with pointers to where each row starts in that
single big chunk. This will make it easier to de-allocate the space.
-
For problem 4, think of a three dimensional array as an array of two
dimensional arrays, and make use of the work you have done for two dimensional
arrays.
|
|
| (Wednesday, October 15, 2003)
| The lab session for homework2 will be held at this Friday, Oct 17. From 4:30 to 5:30 PM at Room 100 Deschutes hall. If you have any question about the homework and want to work with me on the lab, welcome to come in! [Zhen Wu]
|
|
| (Monday, October 13, 2003)
| There will be a dynamic (not regular) lab hour at Room 100 (Computer Room) normally several days before the due date of homework. I will announce the exact time on this page in the future. You are all welcomed! [Zhen Wu]
|
|
| (Monday, October 13, 2003)
| Assignment1 has been graded and returned to you. If you have any doubt or
think that I made a mistake, feel free to contact me! [Zhen Wu]
|
|
| (Wednesday, October 8, 2003)
| Assignment 1 is now due on Thursday, October 9 at 1 PM. This gives you
an extra 24 hours to refine your solutions. Enjoy!
|
|
| (Tuesday, October 7, 2003)
| Here are a few more hints and clarifications on the first assignment problems:
-
Problem 1: The constraint about a single printf is that your source should have
just one printf statement. The statement may be in a loop and thus executed
many times. It should be a relatively simple statement - the idea is not
to be passing ten or fifty integer values as separate arguements to the printf.
Hint: consider using the conditional operator ? :.
-
Problem 2: Again the constraint is on a single output statement, i.e., cout
should appear just once in the program source.
-
Problems 3,4,5: You don't need to make these work for negative numbers, but
feel free to do so.
|
|
| (Monday, October 6, 2003)
| Here's some remarks to help you get started on problem 3 of the first
assignment. You could start with the following skeleton of code, which contains a main function to deal with command line arguments and call the functions you
are to write.
// Convert a string of hexadecimal chars to an int
int hexStringToInt(const char *s) {
int result = 0;
...
return result;
}
// Print out the integer value (without using printf %d
void intToDec(int num) {
... // Do some printing
// Consider making the function recursive as a way
// to get digits ordered right
}
// Numbers in hexadecimal are given on command line
int main(int argc, char *argv[]) {
for (int i = 1; i < argc; ++i) {
int num = hexStringToInt(argv[i]);
intToDec(num);
printf(" (printf gives %d)", num);
putchar('\n');
}
return 0;
}
In intToDec, you can use putchar to print single characters.
|
|
| (Monday, September 29, 2003)
| Welcome to CIS 399, C/C++ and Unix!
|
|