Constructors, friends, operators
including some notes.
But not yet destructors.
11/12/01 - Class on 11/12/01
We have seen what we can say about program fragments. For example,
about the prototype of a function, or an expression, or a variable declaration.
We have started using Visual C++.
Often when transfering files from Visual C++ to Unix we find
extra characters, that appear as ^M.
Here is a program
that eliminates such characters.
We have started talking about classes, private vs. public members.
Why constructors and defined operators.
We have introduced the idea that it might be good to split programs into
multiple files, where each file contains code with a specific well-defined
purpose.
We have seen structures and classes and their purpose.
We have introduced the idea that it might be good to split programs into
multiple files, where each file contains code with a specific well-defined
purpose.
Program Understanding: precondition and postcondition of
a function. The precondition states all that we assume to be true
when we call the function. The postcondition tells us what becomes true after
the function returns.
We have started working with files. We have seen that we need to
include fstream, that we need to connect ifstreams to the files we
want to read from, and to connect ofstream to files we want to write to.
Streams associated to files feel much like cin and cout.
An example of use of files is a program that
copies a file.
We know basic methods on streams [in addition to the methods and operators
we used for cin and cout, we have seen open, close, fail, eof].
Reviewed the enumeration types and the switch statement.
Continued with arrays.
We have played with comma expressions, things like, assuming we have
already defined and initialized integer variables x(1), y(2), z(3), w:
x = y++,4; w = (y += 2), (z = 3);
then the final values of x, y, z, and w are respectively 2, 5, 3, 5.
Of course, you should never write such obscure code.
How do we estimate the time it takes to carry out
some action: the Big-O notation: O(n) for linear search,
O(n2) for selection sorting).
Program Understanding: Loop Invariants.
10/09/01 - Class on 10/08
Started on arrays (one dimension): their components are accessed
by subscripting; they can be assigned; they can be compared (on the
basis of their addresses); they are passed by address, the address of
their first element; the order of an array must be a number known
at compile time; we can initialize an array with an aggregate (something
like {7, 11, 4, 2}).
Specified and implemented a function to find the position of the
largest element in an array; same for the value.
Specified and implemented a function to do a linear search
on an array.
Specified and implemented a selection sort function.
Continued discussion of string functions, including substr and
getline.
09/24/01 - Class on 09/24
We have worked through much of chapter 7 (More Flow of
Control - without enums or switches). We have seen more loops, seen
how to convert for loops to while loops. We have studied break and
continue.
We have seen a variety of character functions such as toupper and tolower.
We have knowledge by example of what classes and their instances are.
We have discussed strings and remarked
that strings, as all objects, are passed to functions by default by value.
We have introduced the getline, rand, and sleep functions.
We have discussed how to document a program: problem statement, analysis,
algorithms and design, implementation and testing.
We have seen that functions can have or not parameters, return or not
values, for a total of four cases.
We have seen a first case of scope: local vs global identifiers.
09/10/01 - Class on 09/10
We should be able to write small programs consisting of a single file, main program
plus one or more functions. The functions can have parameters and return a value.
We have sort of done the first two chapters of the Savitch textbook.
We have talked briefly of functions, as in chapters 3 and 4. But we have
to do much more on this.
We have used in a very primitive way strings and input and output streams.
But we have no clue as to what they are (classes? instances?).
We have reviewed the primitive data types. We know various integer types,
real types, booleans, and characters. We know about overflow and roundoff
errors. We know conversion between booleans and integers, and between
integers and characters.
By now we know the mechanics for using the NOVA (Windows NT)
and snowhite (Unix) accounts and for creating, compilining, executing, mailing
C++ programs.
The Savitch textbook is in the bookstore.
We have a TA Bekezela Mathuthu, we can find her office room and
contact hours by going to the web page of the syllabus for the course.
Last monday we did the first chapter.
Today we have quickly gone over the second chapter.
We sort of know what are predefined data types,
some declarations (variable declarations, constant declarations,
simple functions),
executable statements (assignment, input, output, function call, conditionals,
loops, return, break, continue). We need to go carefully again over this
material.
But we are in the position to write significant programs.
We have done a simple homework (printing out our initials in capital letters)
and we are working on a more complex problem (determining if a number is a prime).
When uncertain, we try simple programs, we talk with our colleagues, we ask the TA,
we ask the teacher. And of course we first read the book.
I have ditributed accounts for Nova, the Microsoft system, and for
snowhite, the Unix system. We have seen how to:
Log into Nova
Launch the browser.
Telnet to and log on snowhite.
A few unix commands (man, ls, pwd, mkdir, cd, more).
We have used pico to create a text file containing the Hello World program.
We have compiled the program using the g++ compiler, and executed the resulting
a.out executable file.
You have used the pine mail program to send me your program.
next week Monday is holiday (labor Day). Wednesday we will start on a
quick tour of the C++ language and of the structure of a program.
08/29/01 - Class on 08/27
We have gone over the syllabus in its various aspects, objectives of the course,
people involved, text book, grading, etc.
We have discussed what is a computer system, with its CPU, main memory, secondary storage,
bus, input, and output. We have done this mentioning things like bytes, kilobytes,
megabytes, gigabytes, megahertz, nanoseconds, ..
We have said that any entity we define in a program has an address in
memory and occupies space. The function sizeof gives the size of
objects in bytes.
We have seen what is a compiler, how we develop a very simple C++ program, the "Hello World"
program, how we compile and run it.
We have looked at the first homework.
08/20/01 - Before Class on 08/27
This is hard to do, since probably you will not look here until
after the first day of class. But if you can, try to review what you
learned in previous programming classes. Start reading the first
chapter of the textbook.