Getting Better Grades On Programming Projects Arthur G. Werschulz Department of Computer and Information Sciences Fordham University XXXXXXXXXX February 9, 2020 Many of the computer science courses at...

1 answer below »
Please see the file proj2-python.pdf


Getting Better Grades On Programming Projects Arthur G. Werschulz Department of Computer and Information Sciences Fordham University [email protected] February 9, 2020 Many of the computer science courses at Fordham University involve computer programming assignments. These assignments will go a long way towards helping you to internalize the ideas that the text and the lectures are trying to transmit. As a result, your grade in these courses will either directly or indirectly be affected by how well you do on the programming assignments. In some (usually lower-level) classes, I grade your projects according to the following standards: • documentation: 20% • correctness: 40%, which may be further broken down as – correctness of the algorithm: 20% – correctness of the program: 20% • input and output quality: 20% • program style: 20% In other (usually upper-level) classes, I use the grading standards • correctness: 60% • overall style (including documentation, I/O, and program style): 40% The class syllabus and/or website will let you know which set of standards I’m using for any particular course. Some of these may seem self-explanatory; some may not. After reading this document, I hope that you’ll have a better idea of what each of these categories mean, which should help you to get better grades on these assignments. Before we start, a couple of general comments: 1. This document is primarily intended for people writing C++ programs. However, the main principles are pretty much language independent. 2. I highly recommend that you use the emacs text editor to create your programs. Admittedly, emacs has a somewhat steep learning curve, but the end results are worth it. In particular, emacs has language-dependent modes that can help with many tasks, such as automatically indenting your program code, 1 not to mention providing a simple development environment. It’s also worth mentioning that emacs is free software that runs on many different platforms, including Unix-like operating systems (most importantly, Linux and MacOS), as well as Microsoft Windows (and DOS), Android, 1This will certainly keep you from unnecessarily losing points under the “program style” rubric. 1 /********************************************************************** * * Programming Project #42: The Traveling Salesperson Problem * * This program solves the Traveling Salesperson Problem in polynomial * time. * * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi * ipsum nibh, tempor eu ultrices ut, mattis a tortor. Ut risus sem, * molestie at molestie ac, varius eu dolor. Donec feugiat elit vel * lacus ultrices aliquet. * * Author: Harry Q. Bovik * Date: 30 February 9872 * **********************************************************************/ Figure 1: Typical block header and Nokia’s Maemo.2 This means that you can use emacs (along with your own customizations) pretty much anywhere. To aid people encountering emacs for the first time, I have gathered together a bunch of handy resources, which may be found at http://www.dsm.fordham.edu/ agw/resources/emacs-resources.html. Perhaps the best way to get started is with the built-in emacs tutorial, as described on the page mentioned above. 1 Documentation Many programmers consider documentation to be a pain. However, a program needs to be understandable to all those who might read it. This includes both other people (the poor souls who have to maintain your code after you leave or are assigned to other projects) and you (when you’re asked to modify the code after being away from it for six months). So we insist that you adhere to a consistent documentation style. 1. Your solution to a particular assignment will consist of one or more computer files. Each file should start with a block comment, which should look something like Figure 1. In more detail: • The first line should give the project number and its title. • This should be followed by a description of what the program does. For clarity’s sake, use a one-line description, followed by a more detailed description (if necessary). • At the end, give your name, email address, and the date that the program was completed. If you’re using the emacs editor, you can create a row of 70 asterisks by typing the keystroke3 “C-u 70 *”. Also note that you should put a blank between the asterisk that starts a line and the content of the line, which improves readability. 2. Every function should be preceded by a descriptive comment. (This includes the member functions of a class.) For the main() function, you can simply say 2emacs also runs on a bunch of other platforms that you probably haven’t heard about, such as various other Unix-like systems (e.g., BSDs, Solaris, AIX, and HP-UX), along with OpenVMS. 3C-something means “control-something”, and M-something means “meta-something”. 2 http://www.dsm.fordham.edu/~agw/resources/emacs-resources.html // read chars from cin and compose a Token void Token_stream::get() { ... } // put a Token back into the buffer of a Token_stream void Token_stream::putback(Token t) { ... } // iteratively compute the n-th Fibonacci number Fib_type fib(int n) { ... } // is num a prime number? bool is_prime(int num) { ... } // precondition: n >= 0 // return value: base raised to the power n // throws Illegal_exponent if n < 0="" int="" pow(int="" base,="" int="" n)="" {="" ...="" }="" precondition:="" data="" is="" sorted="" (in="" increasing="" order)="" return="" value:="" if="" (data[i]="=" target)="" for="" some="" i="" in="" the="" range="" [0..data.size()),="" return="" value="" is="" i="" otherwise="" (i.e.,="" target="" not="" contained="" in="" data)="" return="" value="" is="" -1="" int="" binary_search(const="">& data, double target) { ... } Figure 2: Examples of function documentation. (The function bodies are compressed to save space.) // the usual main() function int main() { . . . } The documentation of the other functions should make the following information clear to the reader: • what the function does • the purpose of its parameters, and • the function’s return value, if any. Sometimes it will be a good idea to be a bit more pedantic, giving the following information: • the function’s preconditions and postconditions, and • exceptions that the function throws. See Figure 2 for some examples of function documentation. Sometimes functions are defined in one place, but declared in another place. Why? • If your program is contained in one source file, you might want to put all the declarations at the beginning of the file, before the main() function. This allows somebody who’s reading the program to see main() as soon as possible, which (in turn) allows her to see the high-level logic of the program as soon as possible. 3 • If your program is contained in several files, you will probably have header files (such as “foo.h”) and implementation files (such as “foo.cc”). You should not put the documentation in both places, since it’s pretty hard to keep them in synch with each other. If your instructor doesn’t tell you where the documentation should go, you should choose one or the other, but be consistent (i.e., don’t document one function at its point of declaration, but another at its point of definition). 3. You should document every important variable, unless you’re 100% sure that its name unambiguously gives this information to the reader. For example, you might be surprised to learn that int length; may not be sufficiently self-documenting; you might need to do something like int length; // length of a furrow, in pixels instead. I would not recommend the verbose name int furrow_length_in_pixels; simply to avoid placing a comment. But if you’re using several different lengths, you might want to use int furrow_length; // in pixels and if you’re using different units for the same length, you might consider // furrow lengths int length_pixels; int length_microns; Consistency and common sense should guide you here. 4. Don’t document unimportant variables. The main problem here is to figure out which variables are unimportant. For example, loop control variables are often (but not always!) unimportant, so it’s fairly likely that you can write for (int i = 0; i < blivit.size(); i++) { . . . } 5. you should use loop invariants to document loops. 6. do not include useless documentation. in particular, i don’t want to see code translated into english, such as // add a to b, giving c c = a + b; 7. do not include incorrect documentation, such as // add a to b, giving c a = b + c; 8. finally, note that documentation is a form of communication. one thing that it communicates is your level of professionalism. thus, you will lose points for misspellings and for ungrammatcial usage. 4 2 correctness your program needs to be correct. at the bare minimum, it should produce the correct output for any sample input data sets that i give you. failure to check your program against any and all such data sets will cause you to lose points. the odds are pretty good that this is the extent to which i’ll check your programs; however, i reserve the right to run your programs against other data sets. i will assess the correctness of both the algorithm and the program, each having an equal weight. roughly speaking, correctness of the algorithm will mean that the general idea underlying your program is correct, whereas correctness of the program will mean that all the details are correct. if you find that you can only implement (say) 80% of the program features, don’t despair. i am quite happy to give partial credit. please don’t fall into the trap of spending hours of time working on that final 20%, the end result being that you fall behind in your work on the other assignments. a warning: correctness only counts for a portion (40% or 60%, depending) of your grade. however, i reserve the right to give a zero to a program that does not (at least partially) solve the problem described in the project handout. in other words, you can’t turn in a “hello, world!” program and expect to get a 40% (or 60%). by the way, i will often give you a preliminary version of a program (perhaps a “stub version”) that you are suppose to extend in some way or another; if you simply submit this original version, even with beautiful documentation and style, you can expect to get a zero. having said all this, let me give you one final word here: relax.4 most people tend to get a near-perfect score on the correctness portion of their programming assignments. 3 input and output quality it should be easy for a user to submit input to your program; it should be easy for her to read the results that your program produces. i will often provide you with an input and/or output format, as follows: • blivit.size();="" i++)="" {="" .="" .="" .="" }="" 5.="" you="" should="" use="" loop="" invariants="" to="" document="" loops.="" 6.="" do="" not="" include="" useless="" documentation.="" in="" particular,="" i="" don’t="" want="" to="" see="" code="" translated="" into="" english,="" such="" as="" add="" a="" to="" b,="" giving="" c="" c="a" +="" b;="" 7.="" do="" not="" include="" incorrect="" documentation,="" such="" as="" add="" a="" to="" b,="" giving="" c="" a="b" +="" c;="" 8.="" finally,="" note="" that="" documentation="" is="" a="" form="" of="" communication.="" one="" thing="" that="" it="" communicates="" is="" your="" level="" of="" professionalism.="" thus,="" you="" will="" lose="" points="" for="" misspellings="" and="" for="" ungrammatcial="" usage.="" 4="" 2="" correctness="" your="" program="" needs="" to="" be="" correct.="" at="" the="" bare="" minimum,="" it="" should="" produce="" the="" correct="" output="" for="" any="" sample="" input="" data="" sets="" that="" i="" give="" you.="" failure="" to="" check="" your="" program="" against="" any="" and="" all="" such="" data="" sets="" will="" cause="" you="" to="" lose="" points.="" the="" odds="" are="" pretty="" good="" that="" this="" is="" the="" extent="" to="" which="" i’ll="" check="" your="" programs;="" however,="" i="" reserve="" the="" right="" to="" run="" your="" programs="" against="" other="" data="" sets.="" i="" will="" assess="" the="" correctness="" of="" both="" the="" algorithm="" and="" the="" program,="" each="" having="" an="" equal="" weight.="" roughly="" speaking,="" correctness="" of="" the="" algorithm="" will="" mean="" that="" the="" general="" idea="" underlying="" your="" program="" is="" correct,="" whereas="" correctness="" of="" the="" program="" will="" mean="" that="" all="" the="" details="" are="" correct.="" if="" you="" find="" that="" you="" can="" only="" implement="" (say)="" 80%="" of="" the="" program="" features,="" don’t="" despair.="" i="" am="" quite="" happy="" to="" give="" partial="" credit.="" please="" don’t="" fall="" into="" the="" trap="" of="" spending="" hours="" of="" time="" working="" on="" that="" final="" 20%,="" the="" end="" result="" being="" that="" you="" fall="" behind="" in="" your="" work="" on="" the="" other="" assignments.="" a="" warning:="" correctness="" only="" counts="" for="" a="" portion="" (40%="" or="" 60%,="" depending)="" of="" your="" grade.="" however,="" i="" reserve="" the="" right="" to="" give="" a="" zero="" to="" a="" program="" that="" does="" not="" (at="" least="" partially)="" solve="" the="" problem="" described="" in="" the="" project="" handout.="" in="" other="" words,="" you="" can’t="" turn="" in="" a="" “hello,="" world!”="" program="" and="" expect="" to="" get="" a="" 40%="" (or="" 60%).="" by="" the="" way,="" i="" will="" often="" give="" you="" a="" preliminary="" version="" of="" a="" program="" (perhaps="" a="" “stub="" version”)="" that="" you="" are="" suppose="" to="" extend="" in="" some="" way="" or="" another;="" if="" you="" simply="" submit="" this="" original="" version,="" even="" with="" beautiful="" documentation="" and="" style,="" you="" can="" expect="" to="" get="" a="" zero.="" having="" said="" all="" this,="" let="" me="" give="" you="" one="" final="" word="" here:="" relax.4="" most="" people="" tend="" to="" get="" a="" near-perfect="" score="" on="" the="" correctness="" portion="" of="" their="" programming="" assignments.="" 3="" input="" and="" output="" quality="" it="" should="" be="" easy="" for="" a="" user="" to="" submit="" input="" to="" your="" program;="" it="" should="" be="" easy="" for="" her="" to="" read="" the="" results="" that="" your="" program="" produces.="" i="" will="" often="" provide="" you="" with="" an="" input="" and/or="" output="" format,="" as="" follows:="">
Answered Same DayMar 24, 2021

Answer To: Getting Better Grades On Programming Projects Arthur G. Werschulz Department of Computer and...

Arun Shankar answered on Mar 27 2021
135 Votes
TM.py
#!/usr/bin/python2
"""
CISC 5200 (Computer Language Theory)
Spring, 2020
Project 2: A Turing Machine Emulator
This file describes a class TM that impleme
nts a Turing machine
The program does no error-checking on the input file.
Author:
Date: 26 March, 2020
"""
import sys
class Table_entry:
"""
Constructor of the Table_entry class. Takes a raw_string
as argument, and then processes it to store the new state, new_char and direction in the object as attributes.
"""
def __init__(self, raw_string):
s = raw_string[1:-1]
spl = s.split(",")
self.new_state = int(spl[0])
self.new_char = spl[1]
self.direction = spl[2]
"""
This method returns a string representation of a table entry
"""
def __str__(self):
return str(self.new_state)+","+self.new_char+","+self.direction
class TM:
"""
Constructor of the class TM.
"""
def __init__(self, ifs):
print "Constructor of the TM"
s = ifs.read()
s = s.replace("\n"," ");
spl = s.split(" ")
self.__num_states = int(spl[0])
self.__sigma = spl[1]
self.__gamma = spl[2]
self.__delta = []
# get the state table3
count=3
for i in range(1,self.__num_states+1):
for j in self.__gamma:
tup = spl[count]
te = Table_entry(tup)
self.__delta.append((i,j,te))
count=count+1
pass
"""
This method just describes the Turing machine
on the console. It prints the number of states, the
transition...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here