You are on page 1of 7

CS100 Computational Problem Solving

Dr. Maryam Mustafa


Tuesday, 21st November

Lead TA: Saad

Lab #12: Lab Guidelines


1. You are allowed to perform/submit the lab only during lab timings.
2. Copying/sharing code is strictly prohibited. Using any unfair means will lead to immediate disquali1cation.
3. Make sure you get your lab evaluated from one of the TAs during the lab timings.
4. Use of mobile phones is strictly prohibited.

Lab Grading
Below is the grading table for this lab:

Task # Points

Task 1 30

Task 2 40

Task 3 30

Task 4 Bonus 20

Total 100
Task 1: Saving El (30 marks)

Imagine waking up one day and finding yourself in Hawkins, a town full of
mysteries and weird happenings. You work at the Hawkins Lab and find out that
Eleven, a girl with special powers, is missing. The lab scientists are teaming up with
government agents to find her. Somehow, one of the scientists finds out the current
location of Eleven and her pals. Since you are good at working with arrays, he asks
you to store the current location of Eleven and her friends in an array. Then, you are
asked to show this array to one of the agents so that he can find Eleven.

Since you are friends with Mike, he tells you that Eleven's powers were used for not-
so-nice things in the lab, and he asks you to hide her location from the agents at any
cost. You feel so uneasy, and you decide to help El. So, when the scientist is gone
after making you store the location of Eleven and her friends, you try to manipulate
the array by finding the index at which Eleven's location is stored and changing her
location to somewhere else so that agents do not get to know the real location of
Eleven. Your job is to do this and then show the changed array to fool the agents and
scientists. However, you decide to populate the array using pointers, and find the
location of Eleven using pointers, else the scientist will get to know you are
deceiving them. Can you save Eleven using pointers without letting the scientists
catch on to your plan?

Hint: Make a string array of size 10, use getline() to take input for each element, and
use substr to find where El’s location is stored.

Note that you can assign any false location to Eleven.


Mike asks you to follow this sample output:
Task 2: Escaping The Upside Down (40 Marks)

One day, Lucas, your friend, rushes to your place, looking all worried. He spills the
news that Max is missing! You get panicked and decide to seek help from Eleven.
Eleven, after using her psychic abilities, discovers that Max is stuck in The Upside
Down (an alternate dimension), and she needs someone to go to Upside Down and
take her back to the real world. You decide to go there alone to find Max. However,
you are confused because you do not know how you will open the portal in the
Upside Down to come back to the real world after finding Max. Eleven, the psychic
wonder, comes up with a quirky solution: She asks you to memorize these seven
integers:

-1 0 9 2 1 7 -4

Once you enter the Upside Down, you need to keep track of the number of minutes
elapsed since you entered the Upside Down. Now when you want to open the portal
to come out of the Upside Down, you need to shift these numbers rightwards by units
equal to number of minutes elapsed. Then shout out this new sequence of numbers
and the portal will automatically open. It's like your magical Upside Down portal
code.

For example, let’s say you enter the Upside Down, and after exactly 1 minute, you
find Max and you want to open the portal to come back. Hence, you will need to shift
these numbers by 1 unit rightwards. The new sequence would become:

-4 -1 0 9 2 1 7

(Each number moved one unit towards right, and the last number came to the starting
point).

After 2 minutes of entering the upside down, the sequence would look like this:

7 -4 -1 0 9 2 1

And so on.
Since you are so good at pointers, you decide to write a piece of code that will
quickly tell you the sequence of numbers that you need to shout according to the
number of minutes elapsed. Eleven uses her psychic powers and advises you to store
these 7 integers in an array, and use modulus (%) operator for shifting (Why
modulus? Think of how you will move the number at the last index to the first
position in the array). She asks you to strictly use pointers for shifting. She also
advices you to use a single array for this shifting (You are allowed to make as many
new arrays as you like, however there is no need). Making a function for this task is
optional, however it will bag you 5 bonus points.

Note that you can hardcode the 7 numbers.

Eleven shares this sample output with you:


Task 3: The Demogorgons Count (30 Marks)

You're chilling with your buddies at Starcourt Mall when, out of the blue, the lights
flicker, and darkness engulfs everything. Turns out, there's an open portal to the
creepy Upside Down in the mall, and demogorgons start creeping out of it. Armed
with whatever you can get your hands on, you turn Starcourt into a battlefield against
these creepy creatures. You and all your friends, including El, starts killing these
demogorgons. As the dust settles, you are asked to report Jim Hoppers about how
many demogorgons you and your friends killed altogether at the mall. Swiftly, you
decide to create an integer array of size 8 (since you were 8 friends), to store the
demogorgons you and your each friend took down. Then you sum all the elements of
this array and reports this total_demogorgans_killed to Jim Hoppers.

However, there is a twist! While killing the demogorgons you forget how to use
loops, so your brilliant mind gives you an idea to make a recursive function instead
to calculate the total demogorgans killed at the Starcourt mall.

So, will you be able to get reward from Jim Hoppers by telling him the correct
number of demogorgons killed?

You write yourself this sample output:


Task 4: Scooby-Doo and the Case of the Pointer Predicament
(15 Marks) BONUS

Task Description:
Background:
In the world of Scooby-Doo and Mystery Inc., a peculiar case has emerged in
Coolsville. The gang has come across a mysterious computer program that seems to
be behaving oddly. This case involves understanding and manipulating pointers in
C++, a vital skill for any budding programmer.

The Mystery:
The gang has found a list of potential hiding spots for Scooby-Doo, who loves to
play hide and seek. However, to determine Scooby's location, they need to
understand and use pointers in C++.

Your Mission:
As honorary members of Mystery Inc., your task is to help the gang solve this
programming mystery.

Objectives:
Implement the swapSnacks Function: Scooby and Shaggy have a bunch of snacks,
but they've mixed them up! Write a function in C++ called swapSnacks that uses
pointers to swap the values of two integer variables, representing the counts of
Scooby Snacks.

You might also like