Anne Dawson: CSCI201A_LAB4_FA04.htm   

 

Last updated: Wednesday 29th September 2004, 8:19 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.

 

 

CSCI201A

Data and Program Organization (Data Structures)

Fall 2004

Lab Assignment 4

Solving a mathematical problem using repetition and recursion

 

Step 1

 

Study the following:

 

Note: you do not type in the code of your program until Step 4.

 

For this lab you will write a function to sum the digits in an integer which is entered from the keyboard.

The function should be named sumdigits, and has one integer (or long integer) argument.

 

Example:

 

sumDigits(4296) = 4 + 2 + 9 + 6 = 21

 

Solve this problem:

 

1.   iteratively (by using a loop construct), and

2.   recursively (by using recursion instead of iteration)

 

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 C++ or Java language.

 

Your program should start with a comment block that contains the following information:

 

#  File:       lab4.cpp or lab4.java

#  Purpose:    Solving a mathematical problem using recursion

#  Programmer: [your name]   

#  Partner:    [your partner's name]

#  Course:     CSCI201A

#  Date:       Thursday 30th September 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 (lab4.cpp or lab4.java) to your folder on the network in:

 

CSCI201A\Week04\Lab04

 

 

Program points will be based on the following marking scheme:

 

Marking Scheme:

CSCI201A   -   Lab 4  -   Solving a math problem using repetition and recursion

Student name(s):

Category

Points

Description

Algorithm

15

An informal description of the steps that must be taken to solve the problem.

ref: http://www.coquitlamcollege.com/adawson/Pseudocode.htm

Pseudocode

15

A formal description of the steps that must be taken to solve the problem.

http://www.coquitlamcollege.com/adawson/Pseudocode.htm

Comments

10

The program is commented appropriately.

Style

15

The source code should be indented properly, use meaningful variable names and identifiers, use good programming practices, etc. See the book, website and lectures for examples.

Output

10

Screen prompts and results should be user-friendly.

Correctness

15

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.

 

 

Assignment Presentations :  In the next class, a random selection of lab assignment programs will be presented to the CSCI201A group.