University of Toronto
CSC148F--Introduction to Computer Science, Fall 1996
Assignment 0: Divisibility by 11

Due electronically:  Thursday 26 September, 6:00 pm
This assignment is worth 1 mark towards your grade in this course. Part marks will count.

Introduction

This is a warm-up assignment to get everyone going, particularly students who aren't familiar with the Turing programming language. This assignment should be straightforward for all CSC148 students. If you don't find it so, then you might need more programming experience before taking 148; consider changing to CSC108.

The problem

Imagine that you want a Turing program that determines whether a given integer is divisible by 11. This can be easily accomplished using ``mod 11'', but only if the integer is small enough to be stored in a Turing int. What if the integer is, say, 50 decimal digits long? This is more than a Turing int can hold. (You can print out maxint to see the largest int Turing can hold on your system.) Some other representation for the integer will be required. There are many possibilities. One of the simplest is to use an array of ints, each of which stores a single digit of the integer to be tested, with the most significant digit stored in array position 1. Along with this, the number of digits must be stored.

Now the problem is how to test for divisibility by 11, because mod only works on ints. The following method can be used:

Think about why this method is correct. We will include an explanation in the solution to the assignment.  

Your task is to write a program that reads in a series of positive integers and uses the representation and method described above to determine, for each, whether or not it is divisible by 11. Each integer will be on a separate line, and may be up to 50 digits long. Integers will not be prefixed by a ``+'' sign or leading zeros. You may assume that there are no errors in the input, such as illegal characters, or integers greater than 50 digits in length. The output will be a single line for each integer, giving the appropriate one of these messages:
The number number is divisible by 11.
The number number is not divisible by 11.
 

How to write your program

We have already written parts of the program for you. You must use this exact code as your starting point. To save typing, our starter code is available online through the course web page located at http://www.cs.utoronto.ca/ tex2html_wrap_inline89 dianeh/148.html

(You will also find there an example of an input file and the output that it should produce.) Make your own copy of the starter code using your web browser. (With Netscape, you can use the ``Save As'' command under the ``File'' pull-down menu.) Then edit the program and insert the missing pieces in the places marked by >> and <<.  

You must use our starter code, and you must not make any alterations to it. In particular, do not change the subprogram headers and do not change the input or output statements. Do not add prompts for the input.  

How to hand in your assignment

For this assignment, your solution will be marked by a computer program, which will put it through a thorough set of test cases. We will not tell you what these tests are. Because the assignment is simple, the marking scheme will be tough. You should therefore test your code very thoroughly before handing it in.  

Because this assignment is to be marked by a program, you will hand it in electronically rather than on paper. Name the file containing your completed program a0.t. When you are convinced of the correctness of your code, hand it in electronically using the ``Hand in (submit)'' command, found under the ``File Utilities'' icon. You will asked to choose which file to hand it, which in this case is a0.t.

If you hand in a solution more than once, we will have only a copy of your most recent version; our copy of the older ones will be erased.

The program that will mark your assignment is not terribly clever, and can only compare your program's output character for character with what we tell it is the correct output. If your output is different in any way from the expected output, it will be considered wrong, and your mark will be zero. For this reason, we are providing, among other things, the statements that perform input and output. If you modify these in any way, or add other input or output statements (for example, if you add prompts) your mark will be zero. In addition, you must use the file name a0.t when you hand in your assignment, or your mark will be zero.  

Some useful advice

Students who are already familiar with Turing should need only a couple of hours to complete this assignment. Students who are not familiar with Turing will need extra time to learn the details of the Turing language and programming environment.  

The most effective way to get this assignment done quickly is to write your program out on paper and simulate it by hand before you go near a computer, in order to get rid of as many errors as possible.  

Even if you plan to develop your program at home, you will have to use one of our PCs to hand in your final program. Make sure you log in and get comfortable with our computers well before the due date.  

Try to get your assignment finished early. The computers are likely to be very crowded near the due date.  

About future assignments

This assignment is unusual in comparison to the rest of the assignments in CSC148. First, it is far less difficult than the assignments to come. Second, you will hand it in electronically, whereas future assignments will generally be handed in on paper. Finally, only the correctness of your code will be evaluated. Future programs will be evaluated also for programming style, documentation, and testing, and will require a report. These aspects may be worth as much as 75% of future programming assignments.


About this document ...

This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.

The command line arguments were:
latex2html -split 0 -no_navigation a0.

The translation was initiated by Diane Horton on Sun Sep 8 15:00:47 EDT 1996


Diane Horton
Sun Sep 8 15:00:47 EDT 1996