.Open Notes on Projects for CS201 . Style See the following book's style guide .See http://horstmann.com/bigcpp/styleguide.html and follow it. . Documentation You should document who you are, what you are doing, and any help you get. Documentation should be included in the source code as far as you can. At the minimum each program must contain comments that identify who did the work and which project the program is tackling. Use the template .See ./project.cpp to get started. Keep a copy with your name to reuse in each project. . Assigned Programming Projects (P1): Program a straight forward input-calculate-output program. This may be the one you described in the first class, or it may be one of the book's exercises: 2.1, 2.2, 2.4, or 2.7 from chapter 2, or a program that does something like one of these calculations: .Table Input Output Note .Row radius of circle circumference Needs and \pi =4*atan(1). .Row radius of circle area Needs to calculate \pi =4*atan(1). .Row Base and height of a triangle area .Row Base and height of right angled triangle hypotenuse has `sqrt` (square root) .Close.Table Or any other similar calculation. Due start of class 05. Grading: The code should compile, run, do the right thing, and follow the $Style described in the book. Since this is difficult to do all at once.... most projects can be resubmitted. Start by downloading this sceleton program .See ./project.cpp and fill in the blanks. (P2): Review our comments, improve, and resubmit $P1. In particular include at least one if-statement. Typically this will only do the calculation of the output if the given data is acceptable. Due start of class 07. Graded viciously. (P3): .Key Decisions and loops. Take the marked up and graded version of $P2 and add a loop to it so that the user can solve a series of problems with a single run of your program. Due at the start of class 09. This will be graded viciously. (P4): .Key Vectors, arrays, and strings. Pick one of these exercises from the book and do your best: 2.15, 2.16, 2.18, 2.19, 2.20, 3.1, 3.2, 3.3, 3.4, or 3.5. Due start of class 11. Graded Gently -- the program should compile and run. It should have a cooment that indicates any bugs or any compile errors you haven't fixed. (P5): Correct and improve $P4. Resubmit. Graded viciously. Due in at start of class 13. (P6): .Key Writing functions and/or procedures. You must have at least one function defined in your program plus a main program that .Key tests all the functions you have written for several argument values. Attempt one(1) of these exercises from chapter 4 in book: 1,2,3,4,5,6,7,8,10,11,13,14,15*,16,19,20. There is no credit given for choosing a tough problem. Due start of class 15. Graded gently. However to get any credit I expect you to have at least two functions in you handed in program. The main program that does the test and another function that matches the table below: .Table Exercise# Function Header .Row 1 int signum(int i) .Row 2 bool prime(int n) .Row 3 bool perfect(int n) .Row 4 int c(int n, int k) .Row 5 double macexp(double x) .Row 6 double mypow(double x, double y) .Row 7 int gcd(int m, int n) .Row 8 double root(double x) .Row 10 bool variable(string t) .Row 11 void lowerUppper(string t, int & lower, int & upper) .Row 13 int substring(string t1, string t2) .Row 14 void put_romany(string t) .Row 15* bool equal(vector a, vector b) .Row 16 vector rotate(char [] a, int length, int number) .Row 19 int gcd(int m, int n) .Row 20 void putBinary(int n) .Close.Table * Note -- replace arrays by vectors in exercise 15! Hint: start by writing the main program (which will fail) first then add the function to make the main program work. (P7): Review our comments, improve, and resubmit $P6 Due start of class 17. Graded viciously. (P8): .Key Classes. In P8 your program must include a class that follows the instruction of an exercise in the book. More, in P8, include a main program that tests every member function and constructor. Select one(1) from this list of exercises from the book: .List 7.1(not the Counter in class), {Hint: at first assume that there will be boundaries and get that to work...} 7.3(includes 7.2), 7.4(start by copying the book's code .See ./code.cpp ), 7.5 (correct the formula given if it is wrong in your copy!) .See http://en.wikipedia.org/wiki/Distance#Geometry 7.7(needs `gcd`), 7.8(start by copying the book's code), 7.10(real but tough), 8.6(easy if you are happy with the sqare root of -1). .Close.List Due start of class 19. Graded gently. You may be asked to draw a UML diagram of your class in a quiz or final. (P9): Review our comments, improve, and resubmit $P8 . Due start of final. Graded viciously. There will be questions on the final that will ask you to draw a UML diagram of the class you implemented in this project. . Deadlines Projects are due at the start of the class on the due date. .Key Late work is worth zero. .Key Incomplete or incorrect work is worth something. Rushing to print out the work at the last minute and arriving late is likely to cost you all the points. . Deliverables Hand in a print out of the source code of the programs. Print, staple the pages, and hand in. No cover sheets or folders. Note: all source code should start with the identifying information. In an emergency you could send the code (ASCII/.txt) with a subject like these .As_is cs201/P1 . Start Early! Look for this file on the CS201 web site: .See ./project.cpp as a starting point. Download and/or save it. Edit in your name. Use it to get started on each project. All the projects in this class can start form this file. . Grading There is absolutely .Key no extra credit given for choosing a difficult project. Good programmers don't let their ego make things difficult for themselves: always do the simplest thing that can possibly work. The grading on projects 1, 4, 6, and 8 is gentler than on projects 2, 3, 5, 7, and 9. In 1, 4, 6, and 8 any program that has the right comments and compiles without errors can earn an A. In later projects the program must compile and run without error and the code must meet all style guidelines. .Open Advice for Project Work . Compiling and running projects .Key Compiling project code can be done by hand in a terminal window as shown in the classes or using the techniques demonstrated in the labs. Avoid using any software that costs you money. In a terminal window .Box Simple programs can be compiled run and tested with a single command on our computers: .As_is Q p1.cpp if the code is in file `p1.cpp` in your current working directory. On other systems you may have to do the steps in 'Q' by hand: .As_is g++ -o p1 p1.cpp will compile it and .As_is ./p1 will run it. You can repeat the last compilation by typing .As_is !g++ into a terminal or use the arrow keys. Or, for more complex projects with code in many files, you can create a .Key Makefile by using any UNIX editor that contains lines like this .As_is test: p1 .As_is ./p1 .As_is p1 : p1.cpp .As_is g++ -o p1 p1.cpp (be careful to use the key to indent the commands. .Close.Box Then the command .As_is make test will update `p1` and then execute it for you. . Warning -- Do It Yourself You can ask the teachers for help. Anything that looks like another student's work or a file downloaded from the Internet is likely to get a score of zero (0) for plagiarism. We have several tools that spot files copied from the Internet. Each project is matched with an examination. In the examination you will have to answer questions about your latest project. Recently, in CS201, someone desperately downloaded code from the internet that sounded like it might solve the problem. It didn't. It got zero. Again, in a recent Comp. Sci. course, one student got some code from his brother at another university and then let six friends copy it and make small changes. Six students handed in six variations of the code. It was a solution to a different problem. They all got zero. . University Policy on Plagiarism Please read page 51-52 of the catalog. . Do's and Don't's for Projects. .List Put your name and the project description as a comment in the code. Download this file .See ./project.cpp as the starting point for a project. Do the simplest thing that can possibly work. Look out and take note of any productivity and quality tips I mention in class. Put most of the documentation as comments in the code. Explain how a user uses the program -- what do they do and what do the get out of it. For complicated steps: write an algorithm (as a comment) first and then code it. Use variable and function names that say what their purpose is. Check out the links under $Style above. No spelling errors in variable names, outputs, or comments. The command `ispell filename.cpp` will help. When you get to .Key functions: use .See ./function.cpp as an outline with comments defining the function. When you get to .Key classes: use .See ./class.cpp as a model and outline. .Close.List .Key THINK. If you rush into code and patch it until it works you may score less than someone who takes time to think about the problem and possible solutions before writing the code. You can make notes using an editor. Start with: What are inputs and outputs? and/or the givens and goals? and/or the before and after conditions? How are these connected? Make notes on this analysis of the problem. What are some possible ways of solving it (designs or algorithms)? Choose one. Turn your notes into comments at the top of a program. .Key Make it Meaningful. It is up to you to use meaningful identifiers and comments that make it clear why the code is going to work. Don't hand in a separate algorithm or structure chart. Instead your file should include comments that show the design. A function definition should start with a comment saying (1) what it assumes and needs, (2) what it produces or guarantees, plus (3) a very brief algorithm. Make it clear and correct before you make it fast. Check all code before I grade it. If you have a bug: Add comments about the symptoms... remove the comments when fixed. If I find uncommented errors you will loose points. If I find things that I can't understand then you will also loose points. Most .Key Errors occur when people (1) .Key misunderstand the problem, (2) think of .Key efficiency before correctness. Real problems are not obvious and are not clearly specified. The descriptions of the programs in the book are like this. There are several different programs that will fit what the book asks you to do. I leave the interpretation of them to you yet: (1) K.I.S.S. (= Keep It Simple!). (2) Demonstrate the features and topics described in the book and course at that time. (3) If in doubt A.S.K. (= Always Seek Knowledge). (4) Document (in comments) how you interpret the problem(Analysis) . Always Seek Knowledge (ASK) I expect you to come and talk to me or other teachers about projects. You should be careful about talking to other students, however. They do not know enough to give you good advice. Also beware searching the Internet -- you'll probably find a solution to a differnt problem. . Document It As You Go Real problems don't have obvious solutions. Whether you know what the code will look like or not add a comment that says what the program must do -- you can copy the description in the book. This may give you an idea. If not think up a special case that you can see how to solve. Use comments to describe the special case and how it case is solved. Make it compile! Add a simple output to see if the algorithm will work -- nothing else. It will probably have errors. This is normal. Declare variables and recompile and test. Add initial values. Test until it runs. Add comments describing an algorithm. Write code implementing the algorithm. Test. . Divide and conquer Develop code in small iterations. Tackle one complication at a time. Test and retest. Rerun the previous tests. . Don't let the sun rise on bad code! When the current version passes all tests, look for ways to re-factor code. For example use the .Key DRY ( Don't Repeat Yourself ) rule to spot code that can be put in a loop or functions, etc. . Stop! Stop before you are about to run out of time or when it does every thing that the book asked for. . How to Fail a Programming Assignment Carol Edmondson at the University of Tasmania has documented the following techniques students have used to fail her courses: .List Don't submit the assigned work. Submit the work late. Submit the same document as your friend. Submit something you found on the web. Use Email/News/etc to invite someone else to do the work for you. Collect random pieces of code and put them in a file. Submit a program that doesn't compile without comment. Submit a program that produces a run-time error without comment. Submit a program that only works on the given tests. Submit a program that does not meet the specification without comment. .Close.List Any of the above can loose you points. .Close . Working at home with SSH access You can work at home but do not spend money on a C++ system. (1) We require work to be work with the free and standard Gnu C++ system. (2) The expensive stuff adds complications to your code for no added value. The department and the Computer Science Club can provide you with software if you ask. You can access our system by using the same system that I have in the class room and office. This is the free Windows SSH client at: .See http://ftp.ssh.com/pub/ssh/ Download and install the latest SSHWinClient-3.x.x.exe file. Connect it to .As_is jbh3-1.csci.csusb.edu and log in. You then will need to login to a lab computer like this .As_is ssh jb358-10 (you can use any of these machines from JBH3-1). You won't be able to do graphic programs or use KDE to make things easier. A key rule: .Box Tap Enter to end each command! .Close.Box The following UNIX commands work well: .Table Command Purpose .Row cat >f Upload or input a file called f. You can type in the code or copy/paste it from your machine. End with Enter and Control/D .Row cat f List the file f on your screen. .Row g++ -o p p.cpp Compile a program called p .Row ./p Execute/run a program called p in this directory(.) .Row make t Follow a recipe in `Makefile` to make t .Row cd d change working directory(folder) to d .Row pwd Print working directory .Row ls List the file names in this directory .Row file * List the files .Row mkdir d Make a directory called d .Row more f Display a file f one screen at a time .Row rm f Remove a file (dangerous....) .Row mv f n Change f's name to n, or move it to a directory .Row cp f n Copy f to file n .Row pico f Edit a file called f (easy to use but not powerful) .Row vi f Edit a file called f (powerful but not easy to use) .Row emacs f Edit a file called f (powerful and I can't use it) .Row lynx u View a web page with URL u while on JBH3-1. .Row links u View a web page with URL u. .Close.Table .Close Notes on Projects for CS201