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:
| Input | Output | Note |
|---|---|---|
| radius of circle | circumference | Needs <cmath> and π =4*atan(1). |
| radius of circle | area | Needs <cmath> to calculate π =4*atan(1). |
| Base and height of a triangle | area | |
| Base and height of right angled triangle | hypotenuse | <cmath> has sqrt (square root) |
(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):
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):
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):
Writing functions and/or procedures.
You must have at least one function defined in your program
plus a main program that
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:
| Exercise# | Function Header |
|---|---|
| 1 | int signum(int i) |
| 2 | bool prime(int n) |
| 3 | bool perfect(int n) |
| 4 | int c(int n, int k) |
| 5 | double macexp(double x) |
| 6 | double mypow(double x, double y) |
| 7 | int gcd(int m, int n) |
| 8 | double root(double x) |
| 10 | bool variable(string t) |
| 11 | void lowerUppper(string t, int & lower, int & upper) |
| 13 | int substring(string t1, string t2) |
| 14 | void put_romany(string t) |
| 15* | bool equal(vector <int> a, vector <int> b) |
| 16 | vector rotate(char [] a, int length, int number) |
| 19 | int gcd(int m, int n) |
| 20 | void putBinary(int n) |
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):
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:
(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.
Late work is worth zero. 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
cs201/P1
Start Early!
Look for this file on the CS201 web site:
[ 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
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.
Advice for Project Work
In a terminal window
Q p1.cppif 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:
g++ -o p1 p1.cppwill compile it and
./p1will run it. You can repeat the last compilation by typing
!g++into a terminal or use the arrow keys.
Or, for more complex projects with code in many files, you can create a Makefile by using any UNIX editor that contains lines like this
test: p1
./p1
p1 : p1.cpp
g++ -o p1 p1.cpp(be careful to use the <Tab> key to indent the commands.
make testwill update p1 and then execute it for you.
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.
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.
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 Errors occur when people (1) misunderstand the problem, (2) think of 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
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:
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: [ http://ftp.ssh.com/pub/ssh/ ] Download and install the latest SSHWinClient-3.x.x.exe file. Connect it to
jbh3-1.csci.csusb.eduand log in. You then will need to login to a lab computer like this
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:
| Command | Purpose |
|---|---|
| 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 |
| cat f | List the file f on your screen. |
| g++ -o p p.cpp | Compile a program called p |
| ./p | Execute/run a program called p in this directory(.) |
| make t | Follow a recipe in Makefile to make t |
| cd d | change working directory(folder) to d |
| pwd | Print working directory |
| ls | List the file names in this directory |
| file * | List the files |
| mkdir d | Make a directory called d |
| more f | Display a file f one screen at a time |
| rm f | Remove a file (dangerous....) |
| mv f n | Change f's name to n, or move it to a directory |
| cp f n | Copy f to file n |
| pico f | Edit a file called f (easy to use but not powerful) |
| vi f | Edit a file called f (powerful but not easy to use) |
| emacs f | Edit a file called f (powerful and I can't use it) |
| lynx u | View a web page with URL u while on JBH3-1. |
| links u | View a web page with URL u. |
. . . . . . . . . ( end of section Notes on Projects for CS201) <<Contents | End>>
Abreviations