Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
12 views4 pages

CS 160: Algorithm Design Guide

Uploaded by

knguyen2300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

CS 160: Algorithm Design Guide

Uploaded by

knguyen2300
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

CS 160: Exploring Computer Science

Algorithm Design Document


Make a copy before you begin (File -> Make a copy). Add the Assignment # above and complete the
sections below BEFORE you begin to code. The sections will expand as you type. When you are
finished, download this document as a PDF (File -> Download -> PDF) and submit it to D2L.

This document contains an interactive checklist. To mark an item as complete, click on the box.

Planning your program before you start coding is part of the development process. In this
document, you will:

● Step 1: Write a detailed description of your program, at least two complete sentences
● Step 2: If applicable, design a sample run with test input and output
● Step 3: Algorithm design
● Identify the program inputs and their data types
● Identify the program outputs and their data types
● Identify any calculations or formulas needed
● Write the algorithmic steps as pseudocode or a flowchart. Look at the
Pseudocode syntax at the bottom of this document. Tools for flowchart - Draw.io
- Diagrams.net

1. Program Description
In the box below, describe the purpose of the program. You must include a detailed description
with at least two complete sentences.

Program Description:

For this Assignment, I will create a program that will convert meters to feet and inches. In this
program, users will enter any amount in meters. The program will then respond by converting
and printing out the number of feet in integers along with the remaining inches.

2. Sample Run
If you are designing your own program, you will start with a sample run. Imagine a user is
running your program - what will they see? What inputs do you expect, and what will be the
outputs from the given inputs? Choose test data you will use to test your program. Calculate
and show the expected outputs. Use the sample run to test your program.

Sample run:

Welcome to my Meters to Feet and Inches Tool!

Use this tool to convert Meters to Feet and Inches

Enter the number of meters here: 50 meters

50.0 meters equals 164 feet and 0.5 inches

Thanks so much for using my converter! Goodbye!


3. Algorithmic Design
Before you begin coding, you must first plan out the logic and think about what data you will
use to test your program for correctness. All programmers plan before coding - this saves a lot
of time and frustration! Use the steps below to identify the inputs and outputs, calculations, and
steps needed to solve the problem.

Use the pseudocode syntax shown in the document, supplemented with English phrases if
necessary. Do not include any implementation details (e.g. source code file names, or
language syntax). Do not include any Python-specific syntax or data types.

Algorithmic design:

a. Identify and list all of the user input and their data types. Include a variable name, data
type, and description. Simple data types include string, integer, floating point, (single)
character, and boolean. Complex Data structures like lists should be referenced by name,
e.g. “array of integer” or “array of string”.

The input will be that the user enters the number of meter, which will be represented as an int.

b. Identify and list all of the user output and their data types. Include a variable name, data
type, and description. Data types include string, integer, floating point, (single) character,
and boolean. Complex Data structures like lists should be referenced by name, e.g.
“array of integer” or “array of string”.

The output will be the number of feet as well as inches. Feet will be an int but inches will be a
float.

c. What calculations do you need to do to transform inputs into outputs? List all formulas
needed, if applicable. If there are no calculations needed, state there are no calculations
for this algorithm. If there are no calculations needed, state there are no calculations for
this algorithm. Formulae should reference the variable names from Step A and Step B as
applicable.

● I will assign the feet variable to the value of the inches integer divided by 12
● Feet = inches // 12
● I will assign the variable totalFeet to the value, which is the expression of the meter
multiplying by the feet plus the float 3.28084, both embedded inside the parenthesis
● totalFeet = meter * (feet + 3.28084)
● I will assign the leftoverInches to the value of the inches moduling by 12
● leftoverInches = inches % 12

d. Design the logic of your program using pseudocode or flowcharts. Here is where you
would use conditionals, loops, or functions (if applicable) and list the steps in transforming
inputs into outputs. Walk through your logic steps with the test data from the assignment
document or the sample run above. Use the syntax shown at the bottom of this
document and plain English phrases. Do not include any implementation details
(e.g. file names) or Python or any language-specific syntax.

1. DISPLAY Welcome message


2. DISPLAY Program description
3. DECLARE meter as int
4. DECLARE feet as int
5. DECLARE inches as int
6. DECLARE totalFeet as int
7. INOUT meter to a float type inputting a string that says to Enter the number of meters
here
8. SET feet to inches // 12
9. SET totalFeet to meter * (feet + 3.28084)
10. SET leftoverInches to inches % 12
11. DISPLAY a message saying that the number of meters is equal to the corresponding
number of feet and remaining inches.
12. DISPLAY a thank you and a goodbye message

Pseudocode Syntax
Think about each step in your algorithm as an action and use the verbs below:

To do this: Use this verb: Example:

Create a variable DECLARE DECLARE integer num_dogs

Print to the console DISPLAY DISPLAY “Hello!”


window

Read input from the user INPUT INPUT num_dogs


into a variable

Update the contents of a SET SET num_dogs = num_dogs + 1


variable

Conditionals

Use a single alternative IF condition THEN IF num_dogs > 10 THEN


conditional statement DISPLAY “That is a lot of
statement dogs!”
END IF END IF

Use a dual alternative IF condition THEN IF num_dogs > 10 THEN


conditional statement DISPLAY “You have more than
statement 10 dogs!”
ELSE ELSE
statement DISPLAY “You have ten or
statement fewer dogs!”
END IF END IF

Use a switch/case SELECT variable or SELECT num_dogs


statement expression CASE 0: DISPLAY “No dogs!”
CASE value_1: CASE 1: DISPLAY “One dog..”
statement CASE 2: DISPLAY “Two dogs..”
statement CASE 3: DISPLAY “Three dogs..”
CASE value_2: DEFAULT: DISPLAY “Lots of
statement dogs!”
statement END SELECT
CASE value_2:
statement
statement
DEFAULT:
statement
statement
END SELECT
Loops

Loop while a condition is WHILE condition SET num_dogs = 1


true - the loop body will statement WHILE num_dogs < 10
execute 0 or more times. statement DISPLAY num_dogs, “ dogs!”
END WHILE SET num_dogs = num_dogs + 1
END WHILE

Loop while a condition is DO SET num_dogs = 1


true - the loop body will statement DO
execute 1 or more times. statement DISPLAY num_dogs, “ dogs!”
WHILE condition SET num_dogs = num_dogs + 1
WHILE num_dogs < 10

Loop a specific number FOR counter = start TO FOR count = 1 TO 10


of times. end DISPLAY num_dogs, “ dogs!”
statement END FOR
statement
END FOR

Functions

Create a function FUNCTION return_type FUNCTION Integer add(Integer


name (parameters) num1, Integer num2)
statement DECLARE Integer sum
statement SET sum = num1 + num2
END FUNCTION
RETURN sum
END FUNCTION

Call a function CALL function_name CALL add(2, 3)

Return data from a RETURN value RETURN 2 + 3


function

You might also like