CS 115: Introduction to Computer Science 1, UAE edition

Assignment 1 Common Errors

Contract

In the contract, some students used nat when num was more appropriate. num, int, and nat are different:

  • num means any number. It includes numbers such as -5.2423, 14, -123, 0, and pi.
  • int means any integer, which are numbers from the set {..., -3, -2, -1, 0, 1, 2, 3, ...}.
  • nat means natural numbers, which are numbers from the set {0, 1, 2, 3, ...}.

Many students did not include type restrictions in the contracts. For example, in question 3, the individual and synchronization scores must be between 0 and 10, a restriction of [>=0, <=10] can be included for each parameter in the contract.

Purpose

Some students did not refer to the parameters. The purpose should mention the parameters by name, and briefly describe their meaning.

Tests

Many students did not have enough tests. You should test boundary cases, as well as typical cases. For example, if a function consumes positive integers, then you should include a test where the function consumes 1, the smallest positive integer. Here are the test cases that students missed:

  • Question 1: Test where credit card is the lower cost. Test where debit is the lower cost.
  • Question 2: Test where the line has fewer characters than the line-length. Test where the line-length is the minimum line length allowed which is 2.
  • Question 3: Test where duplicate scores within at least one of the parts (individual A, individual B, synchronization). Test where all scores are different within each of the parts (individual A, individual B, synchronization).

Constants

Many students did not use constants in questions 1 and 3. Constants allow you to give names to numbers. In question 1, when someone reads your code and sees the number 5 in your function, they may wonder where it came from or what its meaning is. However, if you define it as a constant with a meaningful name, such as fee, then the reader can infer from the name fee that the value is the service charge. Similarly, in question 3, you should define the adjustment factor of 0.6 as a constant.

Helper Functions

Many students did not use helper functions. You should use helper functions to reduce repeated expressions and the amount of code in the main function. For example, in question 3, you can use a helper function to calculate the individual score, and use that helper function two or more times in your main function. When you use helper functions, give them meaningful names.

Whitespace

Please follow the whitespace rules in the Style Guide. In particular, try to avoid long lines and indent your code properly. DrRacket can indent your code for you. Click "Racket" from the menu bar and choose "Reindent All".

Valid XHTML 1.0 Strict Valid CSS!

Last modified on Wednesday, 03 October 2012, at 15:11 hours.

Course Supported by Instructional Support Group