You are on page 1of 10

NATIONAL UNIVERSITY OF COMPUTER & EMERGING SCIENCES

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

Due Date: Monday, October 23, 2023 (11:59 pm)


Instructions
Submission: Please follow the following submission instructions. Failure to submit according to
the above format would result in a deduction of 10% marks. Submissions on the email will not
be accepted. 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 only .cpp 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.

Modular code: Divide your code in user defined functions where appropriate. Every unit
functionality should be implemented in a separate function. All problems solved with just the
main function will be awarded zero marks.

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


Problem 1: Let’s create your first cipher!!! Cipher is an algorithm that you can use to encrypt and decrypt
sensitive information. You have to create a cipher to store sensitive information in an information
system. This number is stored in a 64-bit unsigned number (it can be long long int as its size is at least 8
bits).
In this system, the 64 bits are organized as follows:
• The first 4 bits represent the Transaction Type. (shown as Tr)
• The next 28 bits represent the Transaction ID (shown as T)
• The final 32 bits represent the Customer ID (shown as C)
63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48

Tr Tr Tr Tr T T T T T T T T T T T T
47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32

T T T T T T T T T T T T T T T T

31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16

C C C C C C C C C C C C C C C C

15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

C C C C C C C C C C C C C C C C

a) Develop a function to extract the customer ID from the 64-bit number using bitwise operations.
b) Another function to extract transaction ID.
c) Function to extract transaction type.
d) For enhanced security, your task is to invent a unique encryption method. Write a function to
encrypt the 64-bit number (X) using a custom encryption algorithm that you design. The
decryption function should be created as well, to recover the original 16-bit value.

The details and mechanics of your custom encryption algorithm are entirely up to your ingenuity. You
should aim to make it both robust and challenging to decipher.

Problem 2: FAST-NU’s 74th convocation is on 21st October 2023. You are required to create a Booking
System for the graduating students and their guests. A student is allowed to bring in no more than 4
guests out of which two will be adults and two can be children between ages 10 to 17. For each guest
the cost of one ticket is Rs. 1500/-, and parking per hour is Rs. 100/-.

Age restriction and discounts


• 10-17 (age) 25 %
*Children under 10 are not allowed

Sample output: 1
Please enter your name: Muhammad Ali
How many guests will accompany you? 4
Are there any children among them, remember children under the age of 10 are not allowed?
Yes How many children between 10 to 17 will accompany you? 2

Total cost is: Rs. 5250/-

Sample output: 2
Please enter your name: Muhammad Ali
How many guests will accompany you? 5

Registration failed!!!

For any input which is not allowed display the message “Registration failed”.

Problem 3 – Expected Monitory Value (EMV): EMV is one of the techniques used for quantitative risk
analysis. It is used to calculate cost of each decision alternatives available in the project to choose the
cost effective and best decision, using Decision Tree analysis. It helps project managers in decision
making during a project.

A project manager is required to also have exotic plants in a botanic garden that he is setting up. Now he
is in a dilemma of whether to buy them or grow them. Decision tree (above) shows the cost of growing
exotic plants ($60K) vs buying them from a vendor ($40K). This makes it an easy decision to just look at
the dollar value and since he/she will end up spending $20K more when growing them. The better
decision is to buy them from a vendor.

Sadly, these analyses are not that straightforward and involve various other external factors. In this
scenario, depending on the weather conditions the potential dollar value that will be added to the
botanical garden will vary. If the weather is favorable the person ends up making $80K when he chooses
to grow these exotic plants versus $60K when he chose to buy them from a vendor. This makes this
problem confusing, as only taking this factor into consideration now growing these plants seems
favorable.

Looking at individual paths will not help the PM in coming to a decision. He/she has to calculate EMV of
both decisions. Here is how EMV for both decisions can be calculated:

EMV of the decision (grow plants) = ($80K-$60K) * 0.7 + ($50K-$60K) * 0.3 = $11K
EMV of the decision (buy from vendor) = ($60K-$40K) * 0.7 + ($40K-$40K) * 0.3 = $14K Since

the EMV of decision (buy from vendor) is better than the other. It is a less risky decision.

You have to implement this decision tree in C++ so that the PM can use it for risk analysis. You cannot use
the probabilities written in the decision tree. You must run this tree 20 times for every decision (grow or
buy), and in each run randomly select between favorable weather or harsh weather. Use these numbers
to replace the probabilities in the tree.

Problem 4 – Cricket Fortune Teller: In this problem, you are required to build a system that will predict
the winner of the current world cup. There are 10 teams in the tournament and every team will play
against the other. The top four teams will qualify for the semifinals, where the firstsemifinal will be
played against the 1st and 4th team and the second semifinal will be played against 2nd and 3rd team.
Final will be played against the winners of these semifinals.

You can use a random number to simulate the toss. For every match, you can generate a random number
to declare the winner of the match. While deciding the winner also take into consideration win-loss ratio
of the two teams competing which will be taken as an input from the user.

You are required to use if-else (if-else-if) structure to run the tournament and generate one complete
winning scenario randomly. The names of the teams are as below:
1. Afghanistan
2. Australia
3. Bangladesh
4. England
5. India
6. Netherlands
7. New Zealand
8. Pakistan
9. South Africa
10. Sri Lanka

Problem 5: Compose a C++ program that takes the order from the user and calculates the bill
accordingly. System should also add some discount on the respective bill that exceeds the limit of the
payment. The discount should be added according to the following table:
Order amount Dine in Delivery Takeawa
y

Within 1000 2.5% 5% 7.5%


1000 - 1500 5% 10% 12.5%

1500 - 2000 7.5% 15% 20%

2000 - 2500 10% 20% 25%

2500 - 3000 15% 30% 35%

Above 3000 25% 50% 60%

You are required to display the Menu of the restaurant as follows.


***********welcome to our menu***************

Press 0 to select TAKEAWAY


press 1 to select DINE IN
press 2 to select DELIVERY

which category you want to choose: 0

***********welcome to takeaway menu***************

_____PRESS 0 FOR BURGERS_____


_____PRESS 1 FOR PARATHAS_____
_____PRESS 2 FOR DESI _____

which category you want to choose: 0


Select burger type:
1) Mack___________699
2) Zinger___________599
3) Hot___________449
4) Patty Burger___________699

which category you want to choose: 1


Select paratha roll type:
1) platter___________299
2) cheese___________349
3) crispy___________399
4) double trouble___________699

which category you want to choose: 2


Select Pakistani food type:
1) Haleem___________199
2) Nihaari___________199
3) Daal___________149
4) Ghosht___________249
Note: The menu is same for Dine in and delivery.

Display the total bill and adjust the discounted value.

Problem 6: Write a C++ program that implements the following loan approval. Your program should lead
a person through the steps to help a customer. Given below is the flow chart.

Here is an example of the program’s output (following one of the flows):

Sample output 1:
Enter salary of the customer: Rs. 200,000/-
Loan amount requested: Rs. 1,000,000/-
Loan amount > 50% of Salary: Yes

***Loan Rejected***

Sample output 2:
Enter salary of the customer: Rs. 200,000/-
Loan amount requested: Rs. 1,00,000/-
Loan amount > 50% of Salary: No

***Submit loan application, with 2 references and 3 salary slips***

Reviewer - Documents submitted are correct: Yes


***confirming application***

Approver – Application meets all requirements: Yes


***Loan approved***

Problem 7: You are given a 9*9 grid as shown in the figure below. You can determine the color of each
square from the grid. The number of each square is also shown below. Write a C++ program for this
below given grid. The user is given two options to select from.
1 2 3 … … 7 8 9

10 11 12 … … 18

… 34 35 36 …

64 65 66 …

… 79 80 81

NOTE: You cannot use arrays to store the matrix information.

a) When the user selects 1st option, the user will enter number of square in this grid (any number
from 1-81). Your program will determine the color of the square.
b) When the user enters 2nd option, the user will enter two numbers from this grid. Your program
will determine if the two squares entered in this 9*9 grid have same color or not.

Problem 8: FAST-NUCES has expanded its operations to a great extent and it needs an automated
helpline system for its One Stop Student Center. In order to develop the system, FAST-NUCES has hired
the best programmers from its Islamabad campus. You are required to develop the following scenario
for the helpline system using switch-case construct in C++.
FAST-NUCES has five campuses at Islamabad, Lahore, Karachi, Peshawar, and Faisalabad in Pakistan.
Your system shall cater for all the campuses and provide the following scenario:

Welcome to FAST-NUCES! Press 1 for Islamabad campus. Press 2 for Lahore campus. Press 3 for Karachi
campus. Press 4 for Peshawar campus. Press 5 for Faisalabad campus. Press 0 to talk to an operator. 1)
Welcome to Islamabad campus.
Press 1 for admission related queries.
Press 1 for admission in school of computing
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for admission in school of electrical engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 for admission in school of management sciences
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for academics related queries.
Press 1 to apply for a degree/transcript generation
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 to freeze your semester
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 to add/drop courses
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 for accounts and fees related queries.
Press 1 for queries related to fee challan generation
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 to apply for financial aid
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 apply for a scholarship
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 4 for information technology related queries.
Press 1 to apply for an email id generation
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 0 to talk to an IT expert
Please wait.
Press 5 for sports related queries.
Press 1 to get a sports venue booked
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 0 to talk to a representative
Please wait
If you know your desired extension, please dial it directly.

2) Welcome to Lahore campus.


Press 1 for admission related queries.
Press 1 for admission in school of computing
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for admission in school of electrical engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 for admission in school of management sciences Please
enter your query: (user shall enter a text message here) Your
query is registered. We will get back to you soon.
Press 4 for admission in school of civil engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 5 for admission in school of science and humanities Please
enter your query: (user shall enter a text message here) Your
query is registered. We will get back to you soon.
(Use the same menu as Islamabad campus for the rest of the services)
3) Welcome to Karachi campus.
Press 1 for admission related queries.
Press 1 for admission in school of computing
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for admission in school of electrical engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 for admission in school of management sciences
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
(Use the same menu as Islamabad campus for the rest of the services)

4) Welcome to Peshawar campus.


Press 1 for admission related queries.
Press 1 for admission in school of computing
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for admission in school of electrical engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
(Use the same menu as Islamabad campus for the rest of the services, except for the sports services)

5) Welcome to Faisalabad campus.


Press 1 for admission related queries.
Press 1 for admission in school of computing
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 2 for admission in school of electrical engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 3 for admission in school of management sciences
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 4 for admission in school of civil engineering
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
Press 5 for admission in school of science and humanities
Please enter your query: (user shall enter a text message here)
Your query is registered. We will get back to you soon.
(Use the same menu as Islamabad campus for the rest of the services)
0) Please wait to talk to the operator.

You might also like