This message is a test of the mailing list for my cs1323 class. If you are not in this class, please let me know and I will remove you from the list. (If you are in the class, there's no need to reply.)
Available on the Web; see http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html (also linked from the main page at http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/info.html).
(I'm going to Cc my reply to the whole class, since probably others will be interested as well.)
>> I'm not quite clear on how to get the iostream/fstream functions to round >> off. I think I must have missed something from when you gave the example on >> the board in today's class, as what I have in my notes doesn't seem to work. >> If you have time, would you mind sending me that example again?There are two separate issues here: (1) rounding and (2) printing with exactly two decimal places. The magic incantation to get the "<<" operator to print with exactly two decimal places is as follows (thanks again to Stephanie for looking this up!):
cout.setf(ios::showpoint); cout.setf(ios::fixed); cout.precision(2);As it turns out, this also solves the rounding problem as well -- I just looked this stuff up in Stroustrup's book _The C++ Programming Language_, and it explicitly says that when floating-point numbers are printed in this format, they are rounded. So this part of the assignment (rounding) is easier than I meant for it to be.
FYI: I've revised/simplified the class Web site, home page at http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/index.html. In particular, there's now an "announcements" page that records/archives all the messages I send to the class mailing list (except trivial ones).
Available on the Web; see http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
If possible, try to at least skim through the problem description before Friday's class; we can then talk if necessary about any questions.
>> I had aquestion about one of the functions. What s a selector and what is >> it suppossed to do?
The person who wrote this code uses the following terminology for functions designed to operate on recursively-defined data types such as a Seq list or a natural number:
A "constructor" (doesn't have to be a C++ constructor -- add1() is a constructor for the type "natural") creates an instance of the data type.
A "predicate" distinguishes among the cases of the recursive definition -- here, iszero() distinguishes between the case "zero" and the case "one plus another natural number".
A "selector" deconstructs a non-base-case instance of the data type into its component parts. In the Seq class, there are two of these, hd() and tl(). Here there's just one, sub1(). So, if natural number m is defined as "one plus natural number n", sub1(m) "deconstructs" m by producing n.
If the above makes no sense to you, don't worry about it -- it's an interesting way of looking at recursively-defined data structures but not essential for this assignment.
Anyway, sub1(n) is supposed to produce n-1. It's okay to assume that n is not zero. Putting in an "assert(!iszero(n))" would be a nice touch.
Clearer? I'm going to Cc this to the rest of the class since this seems like it might of general interest.
I'm guessing that since at least a couple of you had problems with this assignment, perhaps others are as well, so -- some last-minute advice:
The add1(), sub1(), and iszero() functions can/should be written
using the Seq
If you're having trouble seeing what to do, look at the hint below,
and/or we can talk about the assignment in class tomorrow. This is
not an easy assignment, but the difficulty is in getting the right
perspective on things rather than in writing tons of code.
Hint -- how to add two non-negative integers recursively:
For any of you who are printing out the PDF or PostScript versions
of homework assignments rather than browsing the HTML versions
online: The HTML versions contain hyperlinks to source code, example
programs, etc.; the PDF and PostScript versions don't. One student
understandably found this confusing, so I have updated the PDF and
PostScript versions to indicate where the hyperlinks are and where
they point.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
I recommend starting to read the assignment early; there is rather
a lot to read, and I suspect some of you will have questions even
after reading.
And for the record -- we'll have exam 1 on Wednesday, February 21,
rather than the date on the syllabus.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
A solution to hw3 will be available before the exam.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
As mentioned in class -- I'm extending the deadline for hw3 until
11:59pm today (Monday). I'll post a sample solution for this
assignment tomorrow.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
It's due next Friday.
Just FYI, this one should require less time and effort than preceding
homeworks, so it's worth fewer points.
The due date for homework 4 is extended to Monday (at 5pm).
To confirm what I said in class today: The new due date/time for
Homework 4 is next Wednesday (March 7) at 5pm.
Also, please start reading chapters 3 and 4. Chapter 3 you can skim,
but parts of it may be useful in doing Homework 4 (as may parts
of chapter 2). Chapter 4 discusses pointers and dynamic memory
allocation, which we'll start talking about / reviewing next week.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
It's due the Friday after spring break.
Note that in this assignment you have the option of earning up to
20 points' worth of extra credit. The extra-credit points make
it possible to have a "points earned" score for this homework that
is greater than the "points possible". For example, if you scored
only 20 out of 40 points on homework 3, but you did all the optional
work for homework 4, resulting in a score of 60 out of 40 points,
your average for the two homeworks would be (20+60)/(40+40) (points
earned divided by points possible), i.e., 100%.
For any of you who read this message and want to start working on
the assignment over spring break (which you don't have to do, but
you could): I plan to be here over spring break, so if you send me
e-mail the odds of getting a prompt reply are good.
Just to confirm what we decided in class today: Exam 2 will be April
4, rather than the March 30 date in the syllabus. That will let
us finish the material on dynamic memory allocation and pointers,
including doing another homework on the topic (it will be assigned
this coming Monday and due the following Monday, April 2).
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
It's due next Monday.
Also, please read chapter 5 of the textbook, which discusses linked
lists.
I just mailed out scores for homework 4. Everyone did very well on
this assignment -- scores ranged from 33 to 39, out of 40. Way to go!
A comment about the constructors for this class: The no-parameters
constructor doesn't have to do anything at all, and the copy constructor
can be very simple:
I've posted a sample solution, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
I've added the "deque" class and the latest revision of the
"dll" class (with iterators) to the sample programs Web page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/SamplePrograms/,
with some clarifications/corrections to what was said in class:
(*) In the deque class, we defined two versions of several of
the member functions, e.g., front() -- one "const" and one not.
I'm not sure I adequately explained why in class, so to try again:
These functions return a reference, which means that a calling
program could change the data that the return value points to.
Sometimes that's what we want (e.g., d.front() = 'a'); sometimes
it's not (e.g., trying to print d.front() in a function in which d
is a "const" parameter). So, we provide a second version of these
functions, with a return type of "const item_type &", indicating
that a calling program is not allowed to modify the data pointed
to by the return value. (It's similar to the difference between a
normal pass-by-reference parameter and a "const" pass-by-reference
parameter.) I hope this clarifies a bit; our textbook discusses
this briefly in chapter 6.
(*) The operator++ and operator-- functions I wrote on the board in
class today (for the dll iterator class) were not quite correct:
The postfix versions of these operators actually have one "int"
parameter, whose only purpose is to tell the compiler which one
is which.
Today's venture into defining iterators will *not* be part of the
material covered on Exam 2.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
It's due next Monday.
The writeup is somewhat long, but the actual amount of code you must
write is modest.
Available on the Web, linked from the assignments page at
http://www.cs.trinity.edu/~bmassing/CS1321_2001spring/assignments.html.
It's due a week from Friday.
Please try to have a look at the writeup before the next class meeting;
we can then discuss any questions (about what you are to do, or how to
do it) in class.
m + n is m
m + n can be computed as (m + (n-1)) + 1
(and then the m + (n-1) can be computed with
a recursive call, and we have functions to
add/subtract one)
Subject: cs1321 homeworks 1 and 2 updated (PDF and PostScript versions)
Subject: cs1321 homework 3
Subject: cs1321 sample solutions -- hw1 and hw2 so far
Subject: cs1321 exam 1 review sheet
Subject: cs1321 hw3 deadline extension
Subject: cs1321 sample solutions -- hw3
Subject: cs1321 homework 4
Subject: cs1321 homework 4 deadline extension
Subject: cs1321 -- confirming homework extension, new reading
Subject: cs1321 homework 5
Subject: cs1321 exam 2 date change confirmation/reminder
Subject: cs1321 homework 6
Subject: cs1321 hw4 scores / a comment
MVector(const MVector & c) { v = c.v; }
(One of you realized this; the others didn't.) Since this is the
default behavior if you don't provide these constructors, you might
think you could just leave them out, and in fact you *could* leave
out the copy constructor, but the compiler won't let you omit the
no-parameters constructor if you provide a different constructor,
as happens here (the one with a "size" parameter).
Subject: cs1321 sample solutions -- hw5
Subject: cs1321 exam 2 review sheet
Subject: cs1321 programs from class
Subject: cs1321 sample solutions -- hw6
Subject: cs1321 homework 7
Subject: cs1321 homework 7