PF FINAL PAPER___

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

National University of Computer & Emerging Sciences, Karachi

Spring-2020 Computer Science Department


Final Exam

Course Code: CS118 Course Name: Programming Fundamentals


Instructor Name: Ms. Tania Iram /Ms. Farah Sadia/Ms. Atiya Jokhio

Instructions:

READ carefully the following instructions before attempting the paper.

● The Final Exam consists of eight questions. Be sure that you have all of these and that they are all legible.
● Read all questions and their instructions thoroughly before you begin. It is always worth your time to plan
ahead!
● Write your roll number, section accompanied by your signature on each page.
● The Final Exam is worth 50 weightage.
● Points will be awarded based on your explicit answers. Partial credit will be given where possible, so show
all of your work.
● Read the question properly, you can’t find it on google so “don’t waste your time”. It’s easy.
● You are supposed to make a program according to the question.
● Don’t share your work, if your submission is matched to any member of your class, both will be marked 0
straight without asking who shared or who magically copied.
● You have to “ATTEMPT ON Paper”.
● In case of non availability of internet due to load shedding etc, mobile data should be good enough to
download and upload files. You do not need the internet during 3 hour offline exams. So better, fully charge
your mobile battery and ready to upload data using mobile in case of emergency.
● 180 minutes is for an exam to attempt, 30 minutes for pdf formation and submission on LMS (Slate/
Google Classroom). If you find some problem with LMS, don’t waste your time and email your theory
teacher with the subject: FINAL_DS_SectionName. Also submit the same later to LMS as well.
● Email Addresses are: farah.sadia@nu.edu.pk || tania.iram@nu.edu.pk || atiya.jokhio@nu.edu.pk
● Submissions after 12:30 pm are considered late. There is a penalty for late submission i.e deduction of 5
points for 10 minutes late submission.

Time: 180 minutes (to attempt) + 30 minutes (to submit) Max weightage: 50

Question # 01: [Points: 04], Time: 15 minutes


Welcome to the “Pie in the Sky” bakers. The customer wants to buy some combination of bakery items
like any single item, or two items for example; cake and biscuits. Write a program that displays the
following menu for the bakery items available to take order from the customer using IF and Switch case
statements.

C = Cake (Rs. 500)

B= Biscuits (Rs. 200)

The program first asks to enter the no of categories of bakery items i.e. 1 or 2, then it asks to enter the
choice i.e. ‘C’ for Cake, ‘B’ for Biscuits and then for quantity. If the customer asks for other than menu
items, it shows a message of the unavailability of items on bakers. The program should finally display the
total charges for the order. Example input/output data is given:

Question # 02: [Points: 04], Time: 20 minutes


Print your nic number string on the screen diagonally using nested loops by following the algorithm.
Program should separate and add the individual digits of middle part of your NIC number ex. NIC number
Input= “42213-1509923-0”. The program will input the whole NIC string 42213-1509923-0 and the middle
number 1509923 and after separating the digits of the middle numbers add the digits to get the sum
:1+5+0+9+9+2+3=29. Divide the sum by three using integer division which gives e.g. 29/3 =9. Now print
your whole nic strings individual characters diagonally upto the final result i.e. 9 lines. Give the dry run of
the whole algorithm:

Question # 03: [Points 06 = 3+3], Time: 20 minutes

A SuperMarket wants to maintain the record of customer visits, items available and quantity of items.
Suppose you are a software designer of that software house and you are assigned to do this task using
structure and filing. Following are the requirements of the supermarket’s owner :

a) The worker has to maintain the record of ‘n’ customers in (customer_details.txt) file.
b) Customer details include: a customer ID (type int), a customer Name (type string), Customer
address (consisting of street address, city, state). Hint: Structure nesting is required in address
field. [ The user has to input all the data].
c) The worker has to maintain the ID of Product, Name of Product, Quantity of Product in
(Product_details.txt) file. He should take the input from the user until the user enters ‘EOF’.

Further, the worker should have menu to select any option out of the given three below:
i) list out all the maintained items.
ii) list only those items whose quantity is zero.
iii) list only those items whose quantity is greater than fifty.

Question # 04: [Points 10 = 2+2+2+2+2], Time: 30 minutes

During Covid-19 spread, civil hospital has to manage budget for its 6 departments. Its account manager
has to track expense report : department-wise and month-wise from January to May in the following
format:

Expense report
===================================================================================

January February March April May Total


======= ======== ======== ======= ======= ======

Department
----------------

Surgery 27000.50 34000.50 45000.50 50000.50 50000.00 240002

Emergency 29000.50 27000.55 36000.00 36000.50 37000.50 201002.6

Skin 27000.50 36000.00 27000.00 36000.50 22000.50 170002

Covid-19 36000.50 36000.50 39000.50 27000.00 22000.00 182002

Dentistry 27000.50 36000.55 36000.00 22000.00 27000.00 170001.1

Total 146002.5 169002.1 183001 171001.5 158001

Write a program using 2-dimensional arrays to hold the expense month-wise and department-wise.

a. Department and Months names should be stored and displayed using array of string pointers.
b. Modular programming should be used i.e. input-data(parameters list..),output data(parameters
list…), department-wise-total(parameters list…),month-wise-total(parameters list…) should be
used to generate report.
c. 2D array holding expenses should be passed from main to all functions by reference.
d. Calculate and display based on data, which department will need federal support i.e. expenses
higher than 50,000.
e. Display which month was stable in terms of expenses i.e having the lowest monthly expense

Question # 05: [Points: 04], Time: 20 minutes

Consider: Two trains are on the same track and they are coming toward each other. The speed of the
first train is 50 km/h and the speed of the second train is 70 km/h. A honeybee starts flying between the
trains when the distance between two trains is 100 km. The honeybee first flies from first train to
second train. Once it reaches the second train, it immediately flies back to the first train … and so on
until trains collide. Calculate the total distance travelled by the honeybee. Speed of a honeybee is 80
km/h. Distance formula is given below.
Total distance travelled by honeybee:
(honeybee speed * distance)/(train_1 speed + train_2 speed)

Your task is to solve the problem recursively (direct or indirect).

Question # 06: [Points 08: 1.5+1.5+1+2+1+1], Time: 20 minutes


Consider a two player game, Player A and Player B. Both the players get the turn one by one and choose
a box randomly. There should be an even number of boxes so that both players can have an equal
number of turns. Every box has some label in terms of 1,2,3...6 and inside of every box has some cash.

Game Rules:
If player A chooses box "1" and opens it then, Player B can not have the opportunity to open box "1".
Once the box is opened that is no longer available to open again.
For each box make sure to allocate the memory dynamically in the main() and initialize cash of each box
randomly by using rand(), pass to the user defined function "Jeet_ki_bazi()" play the complete game
turn by turn in this function and calculate sum of each player's cash . Return the both player cash values
to the main function without using any array or static variable. Use the two individual variables for total
cash of each player. After returning to main() use the ternary operator to make a decision which player
won the game and display the player name with "Congratulations on your well-deserved success".
For example the number of boxes are 6 and are placed in front of you on a table. At the end sum the all
cash of each player. The player that collects maximum cash with more value wins the game.

Initial row: 28 22 10 33 19 40

Round # Process

Round 1: Player A picks box 1: which has 28 rupees, now remaining boxes of cash is
After first pick: 22 10 33 19 40
Player B picks box 4: which has 33 rupees, now remaining boxes of cash is

Round 2: After second pick: 22 10 19 40


Player A picks box 6: which has 40 rupees, now remaining boxes of cash is
After third pick: 22 10 19
Player B picks box 2: which has 22 rupees, now remaining boxes of cash is

Round 3: After 4th pick: 10 19


Player A picks box 3: which has 10 rupees, now remaining boxes of cash is
Last pick: 19
Player B picks box 5: which has 19 rupees, game over.

Total: The total value collected by Player B is more (33 + 22 + 19) compared to the first player (22 + 40 + 10).
So the second picker, Player B wins. Congratulations on your well-deserved success.

Question # 07: [Points: 04], Time: 20 minutes


Write an ethical paragraph corrector program which accepts two to three lines of text as input. After
tokenizing the text, the program checks for a list of unethical words and replaces them with some
ethical words. For this purpose the program tokenize, compares words and modifies the input string into
output string by replacing the words: stupid, ugly, pathetic, Alas etc. An example is shown to
demonstrate:

Hint: you may use string.h functions for string comparing and tokenizing

Question # 08: [Points 10: 3+2+3+2], Time: 25 minutes


Sara and Humna are best friends. Sara lives in joint family system and Humna lives in nuclear family
System. Humna said to Sara,"She loves the joint family system". Sara has a small house and her father
is daily wage labour. Sara lives with 1 younger sister, 2 elder brothers, father, mother , grand father
and mother, paternal uncle and aunty.
Sara has 10 family members overcrowded in the 2 room house with 4 people having corona. Now our
task is to separate corona patients from non-corona patients so that the ones having corona can be
shifted to another room and doctors can then deal with these patients accordingly.
Your task is to design a two array of size 10 for all family members, one for name and one for COVID-19
status in terms of positive and negative in main() and initialize the details of each family member. Use
the bubble sort algorithm for sorting. Sort the record according to the COVID status. You should design
the three functions one for display records, one for swapping and one for bubble sort
passes/epochs/iteration. All three function names are DISPLAY(), SWAP() and BUBBLE_SORT(). Pass the
two arrays to the BUBBLE_SORT(). Don't call any function directly from anywhere. You must use function
pointer technique for all three functions calling.
Unsorted: Name:{”Hina”,”Sara”,“Ali”,”Zain”,”Bakhtawar”,”Hashim”,”Zeeshan”,”Jameela”,”Asfa”,”Zahid”}
Covid:{“P”,”N”,”P”,”P”,”N”,”P”,”,”N”,”N”,”N”,”N”}

Sorted: Name:{”Hina”,“Ali”,”Zain”,”Hashim”,”Sara”,”Bakhtawar”,”Zeeshan”,”Jameela”,”Asfa”,”Zahid”}
Covid:{“P”,”P”,”P”,”P”,”N”,”N”,”,”N”,”N”,”N”,”N”}

You might also like