0% found this document useful (0 votes)
11 views

PF Assignment 1

The document provides instructions for Assignment #1 in Programming Fundamentals (CS 1002) at National University of Computer & Emerging Sciences. Students must submit pseudocode, flowcharts, and dry runs by hand and Scratch code files in a properly named zip file by September 20, 2023. Plagiarism will result in zero marks. The assignment includes 10 problems to write pseudocode, flowcharts, and dry runs for, with some requiring additional Scratch code. Problem 11 requires writing Scratch code to emulate basic physics in a game.

Uploaded by

Hassan Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

PF Assignment 1

The document provides instructions for Assignment #1 in Programming Fundamentals (CS 1002) at National University of Computer & Emerging Sciences. Students must submit pseudocode, flowcharts, and dry runs by hand and Scratch code files in a properly named zip file by September 20, 2023. Plagiarism will result in zero marks. The assignment includes 10 problems to write pseudocode, flowcharts, and dry runs for, with some requiring additional Scratch code. Problem 11 requires writing Scratch code to emulate basic physics in a game.

Uploaded by

Hassan Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES

ISLAMABAD
Programming Fundamentals (CS 1002)
FALL 2023 ASSIGNMENT # 1

Due Date: Wednesday, September 20, 2023 (11:59 pm)


Instructions
Submission: There are some questions in the assignment where you have to implement your
pseudocodes in scratch as well. Pseudocode, flowchart, and dry runs have to be hand-written.
Please follow the following submission instructions. Failure to submit according to the above
format would result in deduction of 10% marks. Submissions on the email will not be accepted.

• (Pseudocode, flowchart and dry runs): Submit this part to your respective instructor, if
you do not have PF class on 20th you can drop it in his/her office. Make sure that you
have clearly mentioned your Name, Registration Number and Section on the front page.
• (Scratch code): Combine all your work (solution folder) in one .zip file. Use the proper
naming convention for your submission file. Name the .zip file as SECTION_ROLL
NUM_01.zip (e.g. A_23i0412_01.zip). Your zip file should only contain .sb3 files, each file
should correspond to its question/problem number. Submit .zip file on Google Classroom
within the deadline.

Plagiarism: Plagiarism cases will be dealt with strictly. If found plagiarized, both the involved
parties will be awarded zero marks in this assignment, all of the remaining assignments, or even
an F grade in the course. Copying from the internet is the easiest way to get caught!

Deadline: The deadline to submit the assignment is 20th September 2023 at 11:59 PM. Late
submission with marks deduction will be accepted. Correct and timely submission of the
assignment is the responsibility of every student; hence no relaxation will be given to anyone.

Note: Start early so that you can finish it on time


PART I – Pseudocode, Flowcharts and Dry runs
(You have to do as many dry runs (for each problem) as are required to ensure that every path is
taken at least once)
Convention for writing pseudocode: Please use the given keywords for pseudocode questions for the
sake of consistency in all submissions
Keyword Usage
// For comments

Display Prompts e.g. Display “Hello world”

Declare Declaring variables e.g. Declare Integer variable_name

Integer To declare integers

Real To declare real numbers

Character To declare characters

String To declare strings

Input To take input from the user e.g. Input variable_name

Arithmetic operators +, -, *, /, MOD

Relational operators <, >, <=, >=, ==, !=

Set To update values of variables e.g. Set variable_name = 2

If – Else – End If Condition structure


If – Then – Else If condition Then
statement 1
statement 2
statement 3

End If

For - End For Repetition controlled repetition structure e.g.


For counterVariable = startingValue To MaximumValue
statement 1
statement 2
statement 3

End For

While – End While Condition controlled repetition structure e.g.


While condition
statement 1
statement 2
statement 3

End While
Write pseudo codes for the following problems. Each question must have five headings, INPUT (what is
supposed to be taken as input for a problem), OUTPUT (what is supposed to be the result of the
problem), PSEUDOCODE, FLOWCHART and DRY RUN(s). Create a Scratch file where mentioned.

Problem 1: Write a pseudo code that reads-in three numbers and writes them in increasing order
or decreasing order depending on user’s choice.

Problem 2: Write a pseudo code that will calculate a running sum. A user will enter a number that will
be added to the sum and when a negative number is encountered, stop adding numbers and write out
the final result.

Problem 3: Calculate your age today (depending on your date of birth)

Problem 4: Write a pseudocode that calculates the area of a triangle using formula: √(s(s-a)(s-b)(s-c)
) where a,b, and c are sides of triangle and s is sum of all sides.

Problem 5: Write a pseudo code that gives your social status depending on your age (Write in Scratch
as well). Aging criteria is:

a. If age is less than 18, display the status as a child.


b. If age is between 18 and 65, display the status as an adult.
c. If above 65, display the status as a senior citizen.

Problem 6: Write a pseudo code that gives a discount of 10% if the cost is more than 1000, 15% if the
cost is more than 2000, and 20% if cost is more than 3000. (Write in Scratch as well)

Problem 7: Write a pseudo code that calculates your eligibility to sit in exams. Attendance criteria
for exams is that if attendance is more than 80%, you are allowed to sit, else you are debarred.
Hint: take number of classes held and number of classes attended as input. (Write in Scratch as
well)

Problem 8: Write a pseudo code that prints the sequence of numbers until the user-defined number.
This sequence should be a series, the series should start with a user-defined number between 0 to 10.
These are examples of series: (1,3,5,7,9…. is a series of odd numbers), (3,6,9,…. is a series of multiples
of 3), etc.

You will need to check if the input is a prime number or not which will limit your choice of series to get
to that number. Minimize the steps it takes to reach that number.

Example: If the user-defined input is 48, check if the number is prime, and print prime numbers till 48.
If 48 is even, what would be the fastest way to reach 48 (Printing multiples of 2 can be an option, Do
Not Use this one, come up with your own). The same example goes for an odd number input.

Problem 9: Develop a program that can convert any whole number in the range of 1 to 10,000 into its
English word representation. For example, the number 123 should be converted to "one hundred
twenty three." Similarly, 1432 would be converted into "one thousand four hundred thirty-two".

Problem 10: The Tarbela Dam can hold 1550 feet of water in total. The dam's water level fluctuates
throughout the year. The water level rises by 150 feet per month from March to August. On the other
hand, the water level drops by 200 feet per month from September to February. The objective is to
calculate which month and year the dam will either reach its maximum capacity or drop to zero feet,
given that the water level in August 2022 is 1500 feet.
Input of the program:
a) Current water level in the dam.
b) Current month.
c) Current year.
d) Rate of decrease in water level from September to February.
e) Rate of increase in water level from March to August.
Output should be like:
● The dam will reach zero level in 11-2024
or
● The dam will reach its maximum capacity in 04-2025

(Scratch only)
Problem 11: You have to write a program that emulates basic physics in a game. The player is moving
at random and you have to apply canvas boundaries to the player and emulate gravity.

Assume that the game takes place in a canvas with a specified width and height, i.e. canvasWidth
and canvasHeight. The top left coordinates of the canvas represent (0, 0). The player is a square
having an xPos, yPos, width, and height. Below is a representation of this setup:

canvasWidth

gi

Hs
a
t

v
xPos
n

yPos
(xPos, yPos)
playerW
idth
Hr

Player a

lp

canvasWidth

Player
s

a
yVelocity
v

a
xVelocity
c

There are a set of booleans, upKeyPressed, leftKeyPressed and rightKeyPressed (which become true
when the respective key is pressed). You do not need to write any pseudocode to actually change their
values; assume this is already being monitored for and the booleans are always updated accordingly.
a) Write pseudocode which will move the player around on the canvas depending on the pressed
key. The player should move at the given velocity, which are different for vertical and
horizontal movement. Use the velocity values to reset the xPos and yPos positions. You
should store this velocity in some variables so that it can be modified easily.
b) The player should not be able to disappear even partially off the canvas. (top/bottom/sides) You
need to check whether or not the player is going off-bounds; if he is, make him stop moving. c)
When the player is moving horizontally, he should move at a steady (constant) rate; however, if
the player is jumping in the air (negative y-velocity), his velocity should gradually increase up to
0, and then he should begin falling downwards with constant acceleration, i.e. gravity. We want
the y velocity of the player to accelerate by 10%. We should be able to change this value easily. i)
"When the player is moving horizontally, he should move at a steady (constant) rate":
This part suggests that when the player character is moving left or right
(horizontally), their velocity should remain constant. In other words, if the player
holds down a movement key (e.g., left or right arrow key), the player character's
speed should not change. This ensures a consistent and predictable movement
experience for the player.

ii) "If the player is jumping in the air (negative y-velocity), his velocity should gradually
increase up to 0":
This part deals with vertical movement, particularly when the player character is in mid
air (jumping). When the player character jumps, their y-velocity (vertical velocity)
should start from a negative value (indicating upward movement) and gradually
increase until it reaches zero. This means that the player character should initially rise
slowly and then come to a stop at the peak of the jump.

iii) "Then he should begin falling downwards with constant acceleration, i.e. gravity":

After the player character reaches the peak of their jump (where the y-velocity
becomes zero), they should start falling downward. This falling should happen with a
constant acceleration due to gravity. In most games, this acceleration is often around
10 meters per second squared (m/s^2), which is similar to real-world gravity.

iv) "We want the y velocity of the player to accelerate by 10%. We should be able to change
this value easily":

This part specifies that the acceleration due to gravity, which affects the player
character's y-velocity while falling, should be customizable and easy to modify. The 10%
increase likely refers to the ability to adjust the acceleration value by a percentage,
making it easier for game developers to fine-tune the gameplay experience without
changing the game's code extensively.
d) What is an appropriate time to call all this code so that the emulation of physics is accurate?

You might also like