CSE 9A Introduction to Computer Science Using C++ Sections A and B UCSD, Fall 1996 Instructor: Walter Savitch Office: 3260 AP&M Instructor Office Hours: Thursday Sept. 26 after each class and in Friday discussion section Sept. 27 (Permanent hours will be announced during the first full week of classes and will be posted in the public directory of the course computer.) TA Office Hours: will be posted in the public directory of the course computer Section A: Lecture: Tuesday, Thursday 10:00-11:20, CENTR 105 Discussion section: Friday 1100-11:50 CSB 001 Section B: Lecture: Tuesday, Thursday 1:00-2:20, HSS 1330 Discussion section: Friday 1:00-1:50 CENTR 105 You must be enrolled in the Lecture section that you attend and that you take your exams in. You may attend either Discussion section. CSE 9 versus CSE 10: CSE 9A and B together are equivalent to CSE 10. If you have taken CSE 10, you cannot take CSE 9. If you need CSE 10 for some requirement, then CSE 9 A and B should meet that requirement. Sometimes departments are slow in recognizing this equivalence, so it may take some convincing in certain cases. The difference between the courses is that CSE 10 moves quickly, while CSE 9 A-B moves at a more normal pace and offers more practice on each topic. You can take either course. The decision is up to you. As a guide line: if you have never programmed before, then you probably should take CSE 9A-B; if you are a computer "hot shot" you should probably take CSE 10. The Computer Used in this course will be iCSE1 (also called sdcc8). You can access this machine from most, and probably all, terminal rooms on campus. Follow the instructions on the handout sheet which you receive with your account. If you have another account that gives you access to the UAPE lab, you should note that you CANNOT access this machine from the UAPE lab. To access this machine via telephone, you will need to obtain a "Basic" account. You may or may not already have a Basic account. If you are new to UCSD this term you should have already been given a Basic account. You need not worry about these Basic accounts (at least not at first), but when and if you want one, go to the Computer Center on the first floor of the AP&M building and ask about obtaining a "Basic" account. You do not need a Basic account to access the class machine from the terminal rooms on campus. To access the class computer via telephone, you need to pay something, either via UCSD or via some commercial net provider. See the following web page for details: http://www-no.ucsd.edu/RAV.html You need a web browser to access this. If this is a problem, check with the Computer Center after the first week of classes. You must have an account for this class on iCSE1 (sdcc8). Homework for this class must be turned from the account you are given for this class. Even another account on the same machine may not work for this purpose. Also, all notices for the class will be posted on this machine. Instructions for obtaining a computer account will be given at the first class meeting on Thursday Sept. 26. Prerequisite: High School Algebra. Required Texts: (available at UCSD bookstore.) Walter Savitch Problem Solving with C++ : The Object of Programming Addison-Wesley Pub. Co., 1996, ISBN# 0-8053-7440-X Kevin Reichard Unix Fundamentals: Unix Basics MIS Press, 1994, ISBN# 1-55828-362-5 (If you prefer, you may use a different Unix manual in place of the Reichard book.) Grading: You will be given a series of approximately 8 homework assignments all of which are programming assignments. There will also be one midterm and a final exam. The various items will be weighted as follows in determining your grade: Homework 35% Midterm 30% Final 35% Midterm Date: The midterm is closed book and will be at the regular class time. The midterm will be on or about Thursday October 31 1996. This date is subject to change so watch for any change of date notice. You must bring a picture ID to the midterms. YOU MUST TAKE THE MIDTERM AND THE FINAL IN THE SECTION THAT YOU ARE ENROLLED IN. YOU CANNOT GO TO ANOTHER SECTION FOR ANY OF THE EXAMS. Working in Teams: You must work alone on assignment 1. On all other assignments you may work in teams of two students. Teams must always consist of no more than two people, and both team members must be enrolled in the same section. You may form different teams for different assignments, but you cannot change team members once you start an assignment. If you prefer, you may do an assignment by yourself even if teams are allowed. Homework Grading Part 1: You will be using the "turnin" facility for turning in your home work assignments. That means that you turn in your homework from your CSE 9A computer account on iCSE1 (sdcc8); this account will have a name that begins with cs9. Note that some other account on iCSE1 (sdcc8) may not work for turning in assignments. See Assignment 1 (below) for instructions on how to use the turnin facility. Due dates always mean the assignment is due at midnight at the end of that day. Late Policy: You can always turn in your assignment (with the turnin program) up to 24 hours late and receive some (but perhaps not all) of the credit for that assignment. No homework will be accepted more than 24 hours late. The exact rules are as follows: >You can turn in two assignments up to 24 hours late and you will not be penalized for lateness on these two assignments. >If you turns in a third, fourth, etc. assignment after the deadline but at most 24 hours late, then you will receive 80% of the credit you would have receive if you had turned it in on time. Remember, it is better to turn in an assignment before the deadline, but if you miss the deadline, you will still always get some credit if you turn in the assignment within 24 hours of the deadline. No assignments will be accepted more than 24 hours late. In case of sever medical emergencies or such, see the instructor as soon as possible to discuss the situation. Homework Grading Part 2: Most or all assignments will be graded on an interview basis in which a TA will ask you to run your program, explain your program, make changes to the program, and such things. If you do not appear to fully understand your program and the assignment, then you will not get credit for the assignment even if the program is perfect. If you do the assignment in a team, then both members of the team must be present for the interview. If one member of the team seems to understand the program and the other member does not appear to understand the program, then only the one who appears to understand the program will be given credit; the team members receive separate grades for the assignment. Details on times for interviews will be given in class. Note that, even if you will be interviewed on a particular assignment, you still must turn in your assignment by the deadline using the turnin program. The details on this will be discussed in class. Also, note that different sections may have different due dates. Note that this means that if you work in a team, then both team members must be enrolled in the same section. Cheating Policies: Cheating has become a serious problem on this campus. A number of students have complained that they are being hurt by others cheating in classes. This is correct. This cheating lowers the value of honestly earned grades. Unfortunately, we have no alternative but to enforce the following very strict rules against cheating. Exams: Anybody talking during an exam will receive a zero for that exam. This may sound unreasonable. However, we have no good alternative. We can easily tell if you are talking, but we cannot listen to and evaluate everything that anybody in the room might say. Anybody found clearly cheating will receive more sever penalties as described below. Programming Assignments: You may not work in groups unless the assignment explicitly says that you may. You must write your own programs. You may discuss the homework with your class mates and seek help from whomever you wish. All that is forbidden is blatant copying. If a question arises, we reserve the right to give you an oral exam on the homework to see if you understand your answer. If you do not understand the assignment, you will receive a zero for that assignment, even if the program you have is perfect in every way. Some of your assignments will definitely be graded in this oral exam way whether or not we suspect cheating. But, if we suspect cheating, we may grade more assignments in this way. If you are caught blatantly copying we will impose more sever penalties as described below. If you are working in a team, then members of the same team may freely communicate and swap information between themselves, but the same rules apply to help from outside the team as those we just described. Penalty for Cheating: Anybody caught clearly cheating in an exam will receive an F IN THE CLASS and will be reported to their Provost's office. For example, if you are caught talking at all in an exam, then you receive a zero for that exam, no matter how innocent the talk. If we are not sure you are cheating, that is the end of that. However, if we hear you giving or receiving answers, then you receive an F for the class. Anybody caught cheating on a homework assignment will receive an zero for that assignment and an additional penalty depending on the details of the case. This additional penalty can range from an additional 10% penalty on your total homework grade all the way up to an F for the class. Note that the penalty is always more severe than just receiving a zero for the assignment in question. Getting Started with C++: Your first week will mostly be spent learning an editor and the basics of Unix, but at the same time you should be reading Chapter 1 of the Savitch text and should be writing your first C++ program. In this class we will be using the CC compiler (which will be explained in class and below) and the vi editor (which will be explained in class and which is partly explained below). Editor We will be teaching you to use the vi editor. If you have the time and inclination, you may also want to learn the emacs editor. Both are available to you and both are described in the Reichard text. The vi editor is very simple and easy to learn, and it is widely used. The emacs editor is a bit more modern and offers many more options, but is a little harder to learn. Compiler We will be using the CC compiler. This will be the official compiler for this class and all home work will be tested using this compiler. To test that you know how to compile and run a C++ program, use the editor to type the following program into a file named test.cxx (Files to be compiled should end in .cxx. Be sure to space the program as shown here.): #include int main() { cout << "HELLO\n"; return 0; } After you have typed in this program, quit the editor. At the Unix prompt type in CC test.cxx Be sure you use uppercase CC not lowercase cc! If you made a mistake when typing in the program, the compiler will say something like "Warning" or "Compilation failed". If that happens, correct your typing mistakes and try again. If you typed in the program exactly as shown, you will get back the Unix prompt with no message from the compiler. When that happens, you can run your program, by typing in the following at the Unix prompt: a.out When the program runs it will write HELLO to the screen. A Second Compiler There is second compiler that is available to you. It is called the GNU compiler. To compile your program with the GNU compiler simply use g++ in stead of CC. To compile and run the program in the file test.cxx using the GNU compiler you type the following at the Unix prompt: g++ test.cxx This compiles the program. To run the program, you then type: a.out The official compiler for this class is the CC compiler. Be sure that you check all your programs with the CC complier. However, every compiler gives different error messages and you may get more information if you compile your program with both compilers. Code From the Text All the programs in the Savitch text are available to you. You can copy them to your directory and then run them, or change them and run them, or play with them in other ways. The programs are in the directory ../public/programs In this directory you will find a subdirectory for each chapter and the programs are in these subdirectories. We will discuss subdirectories and copying programs in class. Assignment 1 Required reading: Reichard book Chapters 1, 2, 3 and those sections of Chapter 6 that cover the vi editor (or if your are using some Unix book other than Reichard read the sections on basic Unix and the section on the vi editor.) Also, Savitch text Chapter 1. Programming: Due date for both sections (midnight) Thursday October 3, 1996: Programming Projects 1, 2, and 3 in Chapter 1 of the Savitch text (page 33). First do Project 1, then modify the program from Project 1 as described in Programming Project 2, and finally modify the program from Project 2 as described in Programming Project 3. (When doing Project 3 be sure to use the program from Programming Project 2, not Programming Project 1. Even though the texts say you can use either Project 1 or Project 2, you cannot; for this assignment you must use Project 2 when doing Project 3.) The result of Programming Project 3 is the only thing you will turn in. You only turn in one program. Programming Projects 1 and 2 are only steps on the way to Programming Project 3. You will use the "turnin" program to turn in your program. This turnin program will take the file you give it and place that file in a directory where we can grade it. You can do this at any time on any day before the deadline. To turnin in an assignment with the turnin program proceed as follows: Suppose the program you want to turn in is in the file hw1.cxx. Simply type in the following (while in the same directory as the file hw1.cxx): turnin -c cs9f hw1.cxx Be sure to use all lowercase letters as shown here. Be sure to put spaces where shown. (The number of spaces does not matter). To turn in a file with a name different from hw1.cxx, simply replace the name hw1.cxx in the above example, with the name of the file you want to turn in. Note: (1): You will always be turning in a C++ program. You should compile it and test it, but when you turn it in, you only turn in the C++ program, you do not turn in the compiled object code. (We will compile your program and run it when we grade it.) (2): If you turnin two files (before the deadline), only the last one turned in will be used. So, if you decide that you did the assignment incorrectly and want to redo it, simply redo the assignment and use the turnin program again (but before the deadline). (3): To learn more about the turnin program, type the following at the Unix prompt: help turnin IMPORTANT: After you turn in your program for this or any other assignment, do not edit it or in any way modify the file that contains your homework assignment. This will ensure that we can check that you did the assignment on time if the turnin program fails. If you want to use your program, make another copy of the program using the cp command. You can safely change this second copy. Your programs will be graded (at least partly) by another program. The grading program expects your program to behave in certain ways and will reject it unless it behaves exactly as expected. Be sure to follow the instructions for input and output exactly. Otherwise, you may not receive credit for the assignment. To see what the input/output behavior of your program should be, you can run the object code in hw01.o. We have already done this assignment and compiled the program. The file hw01.o has the object code produced when we compiled our solution. You cannot see the C++ code for our solution, but you can run the object code and see how your program should behave. The following command will copy the file hw01.o to your home directory: cp ../public/assignments/hw01.o . Do not forget that final dot (period). After you copy this file to your directory, you can run the object code by typing: hw01.o The compiled version of the program you turn in should have the same input/output behavior as hw01.o. (Note: that this program is suppose to give an incorrect answer as discussed in Programming Project 3; so do not be surprised if you get an incorrect answer when you run hw01.o.) We will provide you with object code (like hw01.o) for each assignment so that you can see exactly what the input/output behaviors of your program should be. However, having the right input/output behavior is not enough to get full credit. This program and all your programs must follow the examples of the programs in the Savitch text for style. This assignment is based on the program in Display 1.8 of the Savitch text. All the programs in that text are in the directory ../public/programs So you can get a copy of the program in Display 1.8 by giving the following command from your home directory at the Unix prompt: cp ../public/programs/ch01-02/01-08.cxx . Do not forget that final dot (period). If you start with this file, that will save you some typing, but if you are unfamiliar with the text editor, you might want the practice of typing in the program yourself. Assignments 2, 3, etc. Assignment 2 will be due very soon after Assignment 1, so start early. Assignments 2, 3, and so forth will be posted in the following directory on the course computer: ../public/assignments Electronic Mail You will be taught the basics of using email (electronic mail) in this course and we will use email for some communication. You can use email to ask questions, but due to the high enrollment, we will only be able to answer certain kinds of questions by email. Please observe the following rules when sending email: > Only send email to cs9f on the course computer (from off campus cs9f@icse1.ucsd.edu). This mail will be read by one of the TAs who will either answer the mail or pass it on to the instructor (or discard the mail if it is an unreasonable question). Do not send mail meant for the instructor to wsavitch@ucsd or to any address other than cs10f; if you do, it will simply be forwarded to cs10f thereby delaying your answer. >Only use email for short clarification questions. Do not mail your programs and ask what is wrong with the program. If you cannot figure out or debug your program, make a listing and go see either a TA or the instructor. >Do not expect an immediate answer. We will try to answer all reasonable email questions within 48 hours. Do not send a message the day before the deadline and expect an answer in time to meet the deadline. Internet Access If you have a net browser, some details about this course are available at the following internet address, but you must log onto the course computer in order to get all the information you need for this course. http://www-cse.ucsd.edu/classes/fa96/cse9a_A If you do not have a net browser or even do not know what a net browser is, do not be concerned; you do not need a net browser or internet access in order to take this course.