Skip to Main Content

Introduction to Computer Science

Computer Science Department

Pseudocode – 40 course points

This assignment will introduce students to Pseudocode and conditional thinking.

General Guidelines

Please complete the following assignment in GRADESCOPE by the due date, February 7 @11pm sharp (there are NO late submissions for written Gradescope assignments).

Observe the following rules:

  1. Do not cheat
  2. Do not discuss/share answers with other students.
  3. Submit on time since there are NO late submissions for written Gradescope assignments

Problem 1: Average Speed (6 points)

Write an algorithm that calculates and displays the average speed traveled (v) by a certain object. The program reads the starting position of the object (use variable d1) in meters, then the final position (use variable d2) in meters, and the time taken to travel from start to finish (use variable t) in seconds.

Average speed is calculated by the following formula: v = (d2 – d1) / t

Pre-Condition: assume and are values greater than or equal to zero AND is greater than or equal to d1

NOTE: Do not use loops for this program.

Q1.1 Inputs, outputs, error conditions? (1.5 points)

Q1.2 Write the algorithm in Pseudocode (4.5 points)

Problem 2: Multiples (6 points)

Write an algorithm, without conditionals, that takes as inputs 2 integer numbers and displays TRUE if:

• the first number, , is a multiple of the second number,  OR
• the first number is 0 

OR
• the second number is 0

It displays FALSE otherwise

HINT: num1 is a multiple of  if num1 = num2 * , where x is any integer value

Pre-condition: Inputs are non-negative, integer numbers, and there will always be exactly two numbers.
Hint: use boolean variables instead of conditionals.

Q2.1 Inputs, outputs and error conditions (1.5 points)

Q2.2 Write the algorithm in Pseudocode (4.5 points)

Problem 3: Amusement Park (4.5 points)

Write an algorithm that reads:

  • familySize: number of family members,
  • numUnderFive: number of children under the age of 5 in the fam

Write an algorithm that reads:

  • familySize: number of family members,
  • numUnderFive: number of children under the age of 5 in the family,
  • numSeniors: number of seniors (65+) in the family, and
  • isWeekend: a boolean that is TRUE if it is the weekend or FALSE otherwise

The algorithm is expected to calculate and display the total cost for this family to visit an amusement park. Admission to the park is charged as follows:

  • Free for children 5 years old and younger
  • $20 per person for adults 65 years old and above
  • $35 per person for everyone else
  • The park offers a family discount rate of 10% on the total admission fee for any family of 5 or more members
  • On weekends there is a parking fee of $25, but parking is free on weekdays.
    • Assume the value entered for this input is either true (it’s a weekend) or false (it’s not a weekend).

Pre-Conditions: The inputs (number of family members, number of children under the 5, and number of seniors) are positive, integer numbers. The input isWeekend is a boolean.

Q3.1 Inputs, outputs and error conditions (3 points)

Q3.2 Write the algorithm in Pseudocode (8.5 points)

Q3.3 Write 3 test cases that will result in different outputs for this algorithm (1.5 points)

Problem 4: Counting Operations (5 points)

Consider the following pseudocode algorithm used by Kaira to determine whether or not she will follow a recipe to make dinner or order pizza instead.

READ timeToComplete
READ totalCost
READ difficultyLevel

IF timeToComplete > 30 minutes THEN
	DISPLAY order pizza
ELSE
	IF totalCost > 20 dollars THEN
		DISPLAY order pizza
	ELSE
		IF difficultyLevel IS hard THEN
			DISPLAY order pizza
		ELSE 
			DISPLAY make recipe
		ENDIF
	ENDIF
ENDIF

Q4.1 Minimum possible number of operations (2.5 points)

Q4.2 Maximum possible number of operations (2.5 points)

Problem 5: Evaluating and Counting Operations (10 points)

Consider the following pseudocode algorithm.

READ n
SET i TO 0

WHILE i <= n
	ADD 1 TO i
	DISPLAY i
ENDWHILE

Q5.1 Output (3 points)

What is being displayed when n has the value of 5?

Q5.2 Number of Operations (3 points)

How many operations are executed when n has the value 5?

Q5.3 Operations in terms of n (4 points)

How many operations are executed for any value of n? Write your answer in terms of n

 

Written by Apoorva Goel

Submitting Guidelines

Before submission

Collaboration policy. Read our collaboration policy here.

Getting help

If anything is unclear, don’t hesitate to drop by office hours or post a question on Piazza.

  • Find instructors office hours here
  • Find tutors office hours in Canvas -> Tutoring, RU CATS
  • Find head TAs office hours here
  • POST on Piazza in Canvas -> Piazza
  • In addition to office hours we have the CSL (Coding and Social Lounge), a community space staffed with lab assistants which are undergraduate students further along the CS major to answer questions.
  • Refer to our Programming Assignments FAQ for instructions regarding our assignments and policies.

Submitting

There will be NO late submissions accepted for this assignment!!