Anne
Dawson: CSCI120A_LAB8_FA04.htm
Last
updated: Wednesday 10th November 2004, 8:37 PT
This
document is subject to change without notice.
Please
report any errors or omissions in this document:
adawson@coquitlamcollege.com
Special instructions: For
this assignment you may work in teams of 2, or alone. This lab is due at the end of the lab session.
Fall 2004
Lab
Assignment 8
Step 1
Study the following program specification:
You are to write a program which numbers the lines found in a
text file. Write a program that reads text from a file and outputs each line to
the screen and also to another file preceded by a line number. Print the line number at the start of the
line and right justified in a field width of four spaces. Follow the line number with a colon, then
one space, then the line of text.
Ignore leading spaces on each line.
You may assume that the lines are short enough to fit on a single line
on the screen (i.e. normally 80 characters or less).
Note: you do not type in the code of your program until Step 4.
Your program asks the user for the name of the file to be read,
and the name of the output file to be generated.
Example 1:
test1.txt
Anne was here on Wednesday 10th November
at 8:53am
working on the computer
when she should be
walking the dog.
The dog is not very happy right now.
But tomorrow is
another day…
result1.txt
1: Anne was here on
Wednesday 10th November
2: at 8:53am
3: working on the
computer
4: when she should be
walking the dog.
5: The dog is not very
happy right now.
6: But tomorrow is another day…
Example 2:
test2.txt
Anne was here on Wednesday 10th November
at 8:53am
working on the computer
when she should be
walking the dog.
The dog is not very happy right now.
But tomorrow is
another day…
Don't forget that
quiz 2 is next week
and you
should keep an eye on the schedule
for any updates on the
format of quiz 2
It is based on the topics of weeks 8, 9 and 10
but I may change the
format of the quiz.
Good luck and enjoy the weekend!
result2.txt
1: Anne was here on
Wednesday 10th November
2: at 8:53am
3: working on the
computer
4: when she should be
walking the dog.
5: The dog is not very
happy right now.
6: But tomorrow is
another day…
7: Don't forget that
quiz 2 is next week
8: and you should keep
an eye on the schedule
9: for any updates on
the format of quiz 2
10: It is based on the topics of weeks 8, 9 and 10
11: but I may change the format of the quiz.
12: Good luck and enjoy the weekend!
Step 2
Design an algorithm (the steps to solve the problem). You should
have the algorithm approved by your instructor before going on to the next
step.
The following web page will help you design your algorithm and
pseudocode:
http://www.coquitlamcollege.com/adawson/Pseudocode.htm
Step 3
Development the pseudocode from your algorithm.
The following web page will help you design your algorithm and
pseudocode:
http://www.coquitlamcollege.com/adawson/Pseudocode.htm
Step 4
Using your pseudocode as a guide, implement your program in the
Python language. Use the IDLE GUI to edit and run your program:
http://www.coquitlamcollege.com/adawson/Python_Editor_IDLE.htm
Your program should start with a comment block that contains the
following information:
# File: lab8.py
#
Purpose: File handling
#
Programmer: [your name]
#
Partner: [your partner's name]
#
Course: CSCI120A
# Date: Wednesday 10th November 2004
# Test data:
Step 5
Test your program by running supplying
your own test data. You should test your program with at least 3 sets of test
data. Show your test data and results in comments at the top of your program.
Step 6
At the end of the class, save your
program file (lab8.py) and any test text files to your folder on the network
in:
CSCI120A\Week10\Lab8
Program
points will be based on the following marking scheme:
Marking
Scheme: CSCI120A - Lab 8
- File Handling
Student
name(s):
|
Category |
Points |
Description |
|
Algorithm |
15 |
An informal description of the
steps that must be taken to solve the problem. |
|
Pseudocode |
15 |
A formal description of the
steps that must be taken to solve the problem. |
|
Comments |
10 |
The program is commented appropriately. |
|
Style |
15 |
The source code should use meaningful variable
names (identifiers). |
|
Output |
15 |
Screen prompts and results should be
user-friendly. |
|
Correctness |
10 |
The program should output correct results. |
|
Completeness |
10 |
The program should be complete. |
|
Test |
10 |
Comments in the code explain how the code was
tested. |