NEWS
10.04.00 Please turn in the assignment that you have been asked to redo, or that you have not done as soon as possible
I intend to start posting the solutions from this or next week and that means that any solutions that I receive after I have posted the solutions will not be accepted. Please contact me, as soon as possible for details. But note that I will not be around for most of the break...
10.04.00 Error corrected in homework 4
Several people has drawn my attention to the example I gave for problem 2; it turns out that I had one of the W's placed incorrectly in the maze and that is the reason that the result was wrong.
09.27.00 Some more explanation about the algorithm for problem 2 of the last assignment and some comments
For problem 1:
nodepp is a pointer to a pointer to a structure tree and thus to access an element (e.g. info) you need to type (*nodepp)->info; if you type *nodepp->info then this is equivalent to *(nodepp->info) not (*nodepp)->info
by making an assignment *nodepp=<ptr> then the pointer that nodepp points to changes; this is the reason that the function insert has to take as argument a pointer to a pointer and not simply a pointer, because that way you can update the pointer to point to the new node that you inserted (if this is applicable - if you did insert a new node)
For problem 2:
POS(m,x,y) stands for a macro that you give m (the name of the matrix - it should be _vm in your code) and also the x and y coordinates of a position (square) in the matrix and it will evaluate to the integer that hold the value for that position; I gave this to help you out, since _vm is an 1D array but it stores a 2D matrix instead - just use it as follows: POS(_vm, x, y) if you need to access element (x, y) of the matrix - you need to use this in the two functions that you write
the findPath function is just there to call the fillMatrix function the first time (by inserting 0 at the source coordinates) and return the value that the matrix has at the goal coordinates
the fillMatrix function is the recursive function that I'm primarily interested in:
every time that it gets called it means that you can get at coordinates (_x, _y) of the maze in _v moves from the source coordinates
every coordinate is initialized with a very big number at the beginning
if the value that the coordinates have is bigger than the value of _v when the fillMatrix is called then that means that we can get to those coordinates in a smaller number of steps than we knew before; therefore not only do you need to update the value with the new smaller value _v, but you also need to call recursively fillMatrix for all the coordinates that you can get to from (_x, _y) in one move (step) and with value _v+1, since if you can get to (_x, _y) in _v steps then you can get to its neighbors in _v+1 steps
when all the neighbors have value less or equal to _v+1 then the recursion does not continue to them and thus in the end when we have the smallest number of steps for each position in the matrix then the function fillMatrix will start returning without calling itself any more (since the values _v that it gets called with will be bigger or equal to the values at each respective coordinate) and thus the recursion ends
09.27.00 Extra office hours on Thursday
I decided to host office hours on Thursday from 4 to 5, in order to answer questions for people, since the 4th assignment is due this Friday afternoon the latest.
09.25.00 Quiz posted on the web page
You may wish to look at the quiz page; it contains the quiz with solutions and some comments (notes).
09.25.00 All the quizzes have been graded
I'm pleased to announce that on average people did sufficiently well on the quiz this Friday. You may pick up your quiz at my office hours this week.
09.20.00 Quiz this Friday in class - Everybody must be there to take the quiz!
09.20.00 Homework 3 is now graded
I have finished grading HW3. For most of the people (in the cases that I felt that a not-fully functional code had only reasonably few errors) I debugged the code myself and made comments on the printouts. For some other people, when I felt that the code had more bugs than I was willing to debug myself or that there were things that the author of the program did not understand about C, I have asked them to come and discuss with me. Anyway, I would suggest that you come to my office hours tomorrow (Thursday, 4-5pm) and get your programs back so that you can study my corrections to your code and my comments.
09.18.00 Some comments on assignment 3
In the structure that I gave len is the length of the first group (group1)
Both groups should be strings (that is terminated with the null character), because then you can use all the string functions (e.g. printf, strcmp, strcpy, etc.)
When you try to see which of the pairs matches to the string you currently have, if two or more pairs match then the first one is the one that you should return.
e.g. if the pairs are "afg"->"01" and "a"->"4" then the string "afg04" matches to "afg", but if the pairs are "a"->"4" and "afg"->"01" then the string "afg04" matches to "a" (not "afg"), since "a" was given before "afg" when we declared the pairs...
09.18.00 Quizzes
I will make some revision and answer question on Wednesday; in addition I'm going to give a small mock quiz to get you warmed up. On Friday I will give a real quiz, so make sure you're there.
09.17.00 Homework 3 is due tomorrow
You have to email me the code of your program by midnight tomorrow (I was persuaded to extend the deadline to midnight, so that people could ask me questions at my office hours tomorrow at 3-4pm).
09.17.00 Example program using a stack (pointer and structure use)
In order to help you with your programming I have written a program using stacks (I create a stack using structures and pointers to them. Follow the link.
09.14.00 Homework 2 was completely graded
Everybody who submitted a homework should have received an email informing him/her that his/her homework was graded...
09.12.00 Homework 3 due on Monday
The 3rd homework is due on Monday (9/18); it is only one problem, but it is tricky as it is the first time that you use structures, pointers and memory allocation. Start early and come with questions to me...
09.08.00 Homework 2 is now due on Monday
I gave an extension for the second homework until Monday (9/11)... You may turn in your assignment any time before then. You may also ask me questions via email, or on my office hours.
09.08.00 The solutions for homework 1 are on the web...
I posted them some time ago.
09.07.00 About Homework 2...
I posted on the web sample runs of my program; the lines that say input are lines that you type in and the lines that say output are what the program writes... The link is accessible though the main page and also from here.
In the 3rd problem if you use scanf to read the number of lines in the beginning you need to use the following format: scanf("%d\n", &N); if you want to read the number of lines into variable N. If you do not put the \n at the end then the first fgets statement is going to read a blank line!
09.04.00 Homework 1 graded
All of homework 1 has been graded. I have notified everybody by email that his/her homework was graded when I was done with it. If somebody has not received such an email from me then you need to contact me and let me know! Also don't forget to put your info (name + student ID#) when you submit your homeworks so that I can identify you more easily!
09.04.00 Issues for the homeworks
The output for the second homework MUST BE IDENTICAL TO THE FORMAT IN THE EXAMPLES. Not even a single character (e.g. not even a space) should be wrong. This is because I'm going to compare the output of your program to my own using an automated system for this homework, so if the format is wrong this comparison will tell me that your output is wrong! Please make my life easier :-)
I want you to include your name and student ID, when you submit your programs (I use the ID for identification purposes only!); I also get the email address from your email, so you need not include that if you do not want to.
Turn in a hardcopy of your programs on Friday and email me the programs!
09.01.00 Issues related to the first homework and next homeworks
I'm going to post the solution to the first homework on Monday afternoon (after the class), so until that time you may submit solution (although any solution after today will be considered late). This will be the case with all the homeworks (due on Friday normally, or until Monday (but considered late then) and I will post solutions on Monday).
I no longer have a requirement for you to give me printout of your output, unless you want to, so that should save you some trouble. I still want you to email me the code and also a printed version of the code as well.
08.31.00 In order to print the output and related issues
One way to get the output of your program is to write the following (assuming the the name of your executable is q1sol):
q1sol > out1
This will write all the output of your program (everything that it prints on the screen, not including the things that you type yourself) on the file out1 instead of the screen. Of course this will cause problems, since if you cannot see the output on the screen you may not know what happens (e.g. for the 3rd problem you will not know if the number is higher or lower etc...) You can fix this partly, by printing the output to the standard error stream (which is also the screen), by putting in your program the following code:
fprintf( stderr, ...); where ... stands for whatever you had in the printf statement.
So if you intended to write
printf( "N=%d\n", N);
you should write
fprintf( stderr, "N=%d\n", N); instead.
Now if you give the command q1sol > out1 it will print all fprintf statements to the screen and the rest to the file.
>>> IMPORTANT NEWS <<<
I expect to receive your code by email, but I
also want to have a hardcopy (printed code) of your programs. This is
because I will return these to you with comments when I grade the
assignment.
The reason why I asked you to give me output of the program, is because that way I know that your program compiled and ran; thus if for some odd reason I cannot get it to compile as it is on two different compilers, I will be more inclined to try to do some change to it in order to make it execute properly and probably take the new version into account for grading you. I have decided however that since a lot of you had trouble getting the output for the programs, to make this part OPTIONAL BUT RECOMMENDED! Turning in a hardcopy of your code in class on Fridays (when the assignments are due) is MANDATORY. |
08.30.00 You might want to change the 3rd program as follows:
You might want to change the line that I gave about selecting the secret number at random (the previous statement should not cause problems but to a few compilers, but since a couple of people reported problems, I decided to post this change)
secretNumber = (int)( 101.0 * (double)rand() / ((double)RAND_MAX+1.0) );
08.30.00 Keeping the window open when your program runs
If you run the program and the window does not stay open after the program ends, you can add this code at the end of your program (function main):
scanf("%d", &doWait);
You also need to declare it at the beginning of main:
int doWait;
Then the program is going to wait for you to input a number at the end, before the window closes...
08.29.00 More Compiler News
You may want to use the MS Visual C++ program. Some of you suggested that MS Visual C++ is available in many labs (especially CS labs) and thus should be accessible to many students.
In order to get it to compile C code, you need to do the following:
Go to "File" > "New" (or press Ctrl+N).
Select "Win32 Console Application" from the menu and give a project name and directory and press "OK".
Select "An empty project" from the next menu and press "Finish".
Press "OK" and then you can create your C file(s) by selecting the FileView tab, left clicking on the "source files" directory icon and selecting "add files to folder". Make sure you name the file with the ".c" extension (e.g. hello.c not just hello when you need to give a name). Then ask it to put a reference and to create a file when it asks whether you want to perform these actions.
Let me know if there is a problem with this, but on my computer it seems to work fine like that.
08.28.00 Time Change
The class is going to start and finish 5 minutes later (12:25 - 1:15) than in the schedule, after an agreement between the instructor and the students of the class. This change will take effect from the next lecture (Wed. 8/30)
08.28.00 Compiler Download
I searched the web for a C compiler that you can download and the easiest to install seems to be at URL: http://www.delorie.com/djgpp/
Click on the Zip Picker link and it will guide you into what you need to download and how to install it!