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

PF_Assignment_1-1

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

PF_Assignment_1-1

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

FAST NUCES Programming Olympics

PROGRAMMING FUNDAMENTAL CS1002 - Fall 2024


Release Date: 02 September 2024 Due Date: 16th September 2024
Total Marks 130
Welcome athletes. You have qualified for the Programming Olympics of Fall 2024 by enrolling in CS1002.
There is only one game in the Programming Olympics, that is, problem solving. This is the first round and
here are the rules.
1. Your goal is to reach the finish line, problem 10.
2. To reach problem 10 you are to solve the series of problems below. Each question is of equal marks.
3. Design IPO Charts, Flowchart diagrams and pseudocodes for all 10 questions.
4. Speed is not the aim in this game. You need to reach the finish line with grace, beauty and hardwork.
5. The real challenge is to avoid hurdles like ChatGPT, Gemini, looking at other athletes' work etc.
Failing to do so will result in immediate disqualification.

How to submit
There are a total 10 questions in the assignment and each question carries equal marks i.e 10.You must
submit the hard copy of your own handwritten assignment in my office within the due date. Solve each
problem on a separate sheet of paper with neat and legible handwriting and diagrams using dark pencil or
pen.
On your marks…
Problem 1: Miles per hour to kilometers per seconds
This year olympics were held in Europe causing all sorts of problems for the Americans as they don’t use
the standard measures like meters and kilometers, grams and kilograms. For racing events the speeds are
measured in kilometers per seconds. Can you design a solution to convert kilometers per seconds to miles
per hour for US viewers of the Paris Olympics?

Problem 2: Even or Odd


Mr. Bhola does not know what an even or odd number is. He is least bothered to learn the difference either.
It all comes down to your programming skills to design a program that will ask for a positive number
greater than 0 and prints whether the number is even or odd. Be careful, Mr. Bhola can even enter 0 or
negative numbers so your solution must give an error saying invalid input in that case.

Problem 3: Legal age of marriage in Pakistan


Child marriages are a major problem in Pakistan. To avoid responsibility the Federal Government delegated
the task of Child Marriage Laws to provinces. Only Punjab and Sindh have updated the laws while in Punjab
the law is going under another amendment this year. To make things simple in Sindh, No child, girl or boy,
below the age of 18 can marry. Whereas in Punjab (until the new bill is passed) and other provinces ACT of
1929 is followed which prohibits girls below the age of 16 to marry whereas for boys the age is 18.
You are required to design a solution for both provinces to make this decision easy by asking relevant
information from the user and giving output whether it is legal to marry to or not.

Problem 4: Grocery Assistance/ Calculator


Imagine Mr. Bhoola is going to the market to buy some yummy fruits and vegetables. He's a little bit
forgetful, so he doesn't always have a list or a fixed amount of money to spend. We're going to help Mr.
Bhoola figure out how much he needs to pay and how much change he gets back.
Here's what we need to know:
● How much money Mr. Bhoola has today to buy fruits and vegetables.
● The prices of the onions, apricots, grapes, and tomatoes at the market.
● What vegetables Mr. Bhoola buys and how many of each.

Here is an example of some random day in life of Mr. Bhoola


1. What fruits and vegetables does Mr. Bhoola buy today?
(For example, 2kg onions, 1 kg of grapes, and 3kg tomatoes)
2. What are the prices of each vegetable today?
(For example, onions cost $1 per kg, grapes cost $2 per kg, and tomatoes cost $0.50 per kg)
3. How much money does Mr. Bhoola have with him ?
(For example, $10)
Design a solution to help Mr. Bhoola every time he goes shopping!
Problem 5 : Crop Management.
A smart agricultural drone monitors a large farm to manage irrigation efficiently. The drone first checks the
type of crop being monitored whether it's wheat, corn, or rice. For wheat, if the soil moisture is below 30%,
and if it has not rained in the last 24 hours, the system will initiate irrigation. For corn, if the soil moisture is
below 40% , the system will irrigate regardless of recent rainfall. For rice, if the soil moisture is below 25% ,
the system will irrigate unless it has rained in the last 24 hours. If the soil moisture is above these
thresholds, no irrigation is applied. Design a solution to determine if irrigation should be initiated based on
the crop type, soil moisture level, and rainfall status.

Problem 6: Amusement Park Ride eligibility


Safari park is a famous amusement park situated in Karachi that has specific height and age requirements
for its rides. For The Dragon Roller Coaster, visitors must be at least 48 inches tall and 10 years old. The Sky
Swing requires visitors to be at least 54 inches tall, with no age restriction. The Carousel has no height
requirement but visitors must be at least 5 years old. A visitor is wearing a band so he may take as many
rides as he wants until he is tired. Design a solution that determines if a visitor meets the criteria to go on a
chosen ride based on their height, age, and selected ride.
Examples:

Input: Input:
● Height: 55 inches ● Height: 48 inches
● Age: 10 years ● Age: 9 years
● Ride: "The Carousel" ● Ride: "The Dragon Roller Coaster"
Expected Output: Expected Output:
"You meet the criteria for The Carousel." "Sorry, you do not meet the criteria for The Dragon
Roller Coaster."

Problem 7: Which floor…


There are 10 floors in a building 0 to 9. The building lift/elevator has a 1 digit, 7
segment LCD Panel display to tell which floor the lift is on, as shown. The input into
the LCD Panel is a 7-digit long number with only 1s and 0s. Each digit of the 7-digit
long number tells which panel to light or not to light from A to G respectively, where
1 means to light the panel and 0 means to keep it off.

E.g., 0110000 means only panel ‘B’ and ‘C’ are lit thus telling that this is the first
floor. Similarly, the number 1111110 tells that all panels are lit except panel ‘G’
displaying the number 0.

You need to design a program for a computer surveillance system to tell which floor the lift is on. The input
for the program is the 7-digit number comprising only 1s and 0s. The output should be a single digit number
0 to 9 telling which floor the lift is on.
Hint: You can get the last digit by using %10 and the remaining digits by using number division /10. Also,
you only need branching to do it.
Get set ...
Problem 8: Digit Sum
You are required to design a solution that takes as input a single number and prints out the sum of its
digits. Check the examples below for clarity.
Examples:
sumDigit(345) = 12 sumDigit(1) = 1 sumDigit(1600) = 7
sumDigit(55) = 10 sumDigit(400000000) = 4 sumDigit(0) = 0

Problem 9 : Exact Age in days, months, and years from DOB


NOTE: For this problem you may ignore the leap years when calculating age but not when validating date of
birth or current date.
Mr. Bhoola is trying to figure out how old someone is, but he keeps getting confused! He needs your help.
Your job is to create a solution that makes calculating ages super easy.
Here's what you need to do:

GET THE DATES:


First, you need to ask Mr. Bhoola for two dates: The person's Birthday: This is the date they were born. And
Today's Date: You'll need to know what day it is right now.

CHECK FOR MISTAKES: (THE VALIDATION STEP)


Before you can calculate the age, you need to make sure the dates Mr. Bhoola gives you are correct. Think
about these things: Are there too many days in the month? For example, April only has 30 days, so you can't
have a date like April 31st. Is it a leap year? February has 29 days on a leap year, and 28 days otherwise!
Now, you can calculate the exact age. Bonus for also including leap year in the calculation.

Go Go Go !!!
Problem 10: Poor Mr. Bhoola bought a faulty keyboard
Imagine Mr. Bhoola's keyboard is a bit mischievous! Every time he types the number "9," the keyboard adds
an extra zero. So, if he types "9," it shows up as "90".
Your Mission:
Mr. Bhoola wrote down some numbers using his silly keyboard. But we know they're wrong because of the
extra zeroes. Your job is to fix them by taking away the extra zeroes whenever you see a "90" in the number.
Here are some examples:
100900: The keyboard typed "90" where there should be "9". So, it's really 10090.
1540090: The keyboard added an extra zero again. It's really 154009.
1290905: This one is tricky! There's a "90" where there should be a "9". It's really 12995.

Design a solution to fix the other numbers Mr. Bhoola wrote down!
Problem 11: No not optimus prime its Coprime..
Mr. Bhoola just found out about coprime numbers. Now he is obsessed with them and keeps checking two
numbers whether they are coprime or not. You are to design a solution to this problem and help Mr. Bhoola
with checking whether any two whole numbers greater than 0 are coprime or not.
A simplified definition of Coprime numbers is that their GCD is 1. You are encouraged to check wiki or other
resources for more information.
Examples:
8 and 9 are coprimes despite the fact that they are not prime numbers.
14 and 33 are coprimes.

Problem 12: Die Hard 3: Defuse the bomb… Quick!


You've got to defuse a bomb by placing exactly 4 liters of water on a sensor. And you have to be quick! The
problem is, you only have a 5L jug and a 3L jug on hand!
See the video clip here: https://youtu.be/BVtQNK_ZUJg
You have an unlimited water source, and if needed you can also empty the water in the jugs to get rid of it.
How could 4 liters be measured?

Problem 13: The general N-M size die hard jug problem
Design a solution to solve the general form M-NL jugs of the above problem.
So instead of having just 3-5L jugs you can be given 3-9L jugs or 7-9L jugs. Can you extract any number of
liters of water less than the larger jug or only some quantities. Is there a formula for this? What amounts of
water can be extracted from M-NL jugs?

GOOD LUCK 🙂

You might also like