You are on page 1of 6

National University of Computer and Emerging Sciences

FAST School of Computing Spring 2020 Islamabad Campus

CS-118: Programming Remote Final Retake Exam


Attempt Time: 3 Hours
Fundamentals Submission (on Google
Classroom and through email)
Time: 15 minutes

Friday, 24th July, 2020


Total Marks: 90
Course Instructor(s)
Dr. Faisal Cheema, Dr. Subhan Ullah,
Mr. Jawad Hassan.

Instructions:
1. The retake-final exam will be attempted offline in the student's own handwriting (in readable way).
2. The students will use A4 size blank white sheets to attempt the exam (portrait format unless a diagram or
table requires landscape). Each sheet of the A4 size paper MUST have the Roll Number, Name, the course
code, name of the course, Sheet Number and Signature of the student at the top of EACH sheet.
3. Students will use cam-scanner, MS lens, or an equivalent application to scan and convert their hand-written
answer sheets into a SINGLE pdf file (keeping the correct order of pages and question numbers), which they
will submit on Google Classroom and MUST also email to the email address (of the concerned course/lab
instructor) which will be provided. They will be given 15 minutes (after the 3 hours attempt time) for this
purpose. All students must use the standard file name format (Full course code - Roll number e.g. CS-118-
19i-0123). Submissions after 30 minutes may not be accepted. Try to submit soon after 3 hours of attempt
time and do not wait for 15 minutes to be elapsed.
4. For proven cheating/ plagiarism, student will get an F grade even if the student had opted for S/U grade,
and the case will be referred to DDC (Department’s Disciplinary Committee). Instructors will conduct vivas
of randomly selected students or in case of doubt (significantly different attempt as compared to past
performance in the course or matching attempt with other students). Plagiarism includes sharing an attempt
to other students (copy providing). Students who are not able to satisfactorily answer instructor’s questions
(based on the exam as well as slightly lateral but related concepts) during viva will also be considered as
plagiarism cases.
5. Students should carry a clean scanning that is free from any marks/stains etc.

Q-1 Q-2 Q-3 Q-4 Q-5 Q-6 Q-7 Q-8 Q-9 Q-10 Total

Marks 5 5 5 15 10 10 10 10 10 10 90
National University of Computer and Emerging Sciences
FAST School of Computing Spring 2020 Islamabad Campus
Important Note: For all coding parts a proper error checking, correct formatting, and
comments/explanation of code are required and these carry marks in each question. Please
look into the section of marks distribution for each coding problem.
Question 1 [5 Marks]: Write a program that take input of ten integers from a user and
then computes the sum and average of those integers. Your program will use simple I/O
statements and operators (without loops, arrays, or advanced structures of C++) with no
more than two variables.
Marks distribution for question 1:
1) Using only two variables without advanced structures = 1 marks
2) Correct data types = 1 marks
3) Correct syntax = 1 marks
4) Logic = 1 marks
5) Comments or explanation of code= 1 marks

Question 2 [5 Marks]: Write a program with a function countZeroes(n) which takes as


input a pointer to a positive int n and outputs the number of zeroes in n. For example:
countZeroes(10) is 1, countZeroes(50803) is 2, and countZeroes(547) is 0.

Marks distribution for question 2:


1) Appropriate data type and format = 1 marks
2) Correct syntax = 1 marks
3) Logic = 2 marks
4) Comments or explanation of code= 1 marks

Question 3 [5 Marks]: Write a program to input the price of a book and its sale tax in
percent (Hints: use decimal units). Then the program will calculate the total price with
and without the tax for any number of books. Also, compute the amount of the total tax.
Example output:

a) Enter the price of a book: 100


b) Enter the sale tax in a percent: 0.25
c) How many books do you want to buy? 5
d) The total price without tax is: 500
e) The total price with tax is: 625
f) The total tax is: 125

Marks distribution for question 3:


1) Appropriate data type and format = 1 marks
2) Correct syntax = 1 marks
3) Logic = 2 marks
4) Comments or explanation of code= 1 marks

Page 2 of 6
National University of Computer and Emerging Sciences
FAST School of Computing Spring 2020 Islamabad Campus
Question 4 [15 Marks]: Alice and Bob want to share a 4-digit pin-code with each other on
a public internet channel, but they are worried about its confidentiality (unauthorized
access). That’s, why they want some encryption mechanism to securely share the pin-
code with each other. Please write a C++ program to encrypt the pin-code on the Alice
side and decrypt it back to its original (pin-code) on the Bob side. The encryption and
decryption on Alice and Bob side will work as follows:

1. Replace each digit by (the sum of that digit plus 5 modulus 7). For example, for a
pin-code 3254, the first digit is 3 so you will replace it by “(3+5) % 7” e.g., by 1.
Repeat this process for all digits.
2. In the resulted 4-digits, swap the first digit with the third and the second digit
with the fourth, and print the encrypted pin-code.
3. On the Bob side: Enter the encrypted pin-code and decrypt it by such a way that
the encrypted pin-code converts back to its original pin-code.

Hints: Please use the following representation of 4-digit number e.g., 3254 =
3*1000+2*100+5*10+4.

Marks distribution for question 4:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 4 marks
3) Logic = 6 marks
4) Comments or explanation of code= 3 marks

Question 5 [10 Marks]: Write a C++ program by using a “while loop” to calculate the sum
of all “even numbers” and “odd numbers” respectively within two given boundaries
(e.g., between 20 and 100). Then the program will calculate the difference between their
computed sums. You should have proper checking for correct entries of the boundaries
(e.g., for upper bound and lower bound).

Marks distribution for question 5:


1) Appropriate data type and format = 1 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Proper check for boundaries = 1
5) Comments or explanation of code= 2 marks

Page 3 of 6
National University of Computer and Emerging Sciences
FAST School of Computing Spring 2020 Islamabad Campus
Question 6 [10 Marks]: Write a “void function” called rotateR which takes three integers
and rotates them in a clockwise direction. That is, the third integer is moved to the first
place, the second to the third place, and the first to the second place. For example, if
integer variables number1, number2, and number3 have values 10, 20, and 30,
respectively, then their values will become 30, 10, and 20, respectively, after executing
the function call rotateR (number1, number2, number3).

Marks distribution for question 6:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Comments or explanation of code= 2 marks

Question 7 [10 Marks]: Mean of matrix is the average of all the elements present in a
matrix. Consider a modified mean as floor of mean row-wise minimum and column-
wise maximum. The row-wise minimum is the sum of minimum element from each row
of a given matrix and column-wise maximum is the sum of maximum element from
each column. Given a matrix of order n *m, write a C++ program to find the number of
elements greater than new mean obtained.
mean = floor((sum(row-wise Min) + sum(col-wise Max)) / (row_no. + col_no.)

Input:
int arr[3][3] = {{1,5,6},{2,3,0},{5,2,8}}

Expected Output:
Number of Elements: 4

Marks distribution for question 7:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Comments or explanation of code= 2 marks

Page 4 of 6
National University of Computer and Emerging Sciences
FAST School of Computing Spring 2020 Islamabad Campus
Question 8 [10 Marks]:
Pig-Latin is a constructed language game where words in English are altered according
to a simple set of rules.
a) If the word begins with a consonant, Pig-Latin takes the first alphabet, moves it to
the end of the word and adds an “ay” at the end.
b) If a word begins with a vowel it just adds “way” to the end.
For example: "banana" becomes "ananabay", "trash" becomes "ashtray", "eat" becomes
"eatway", "omelet" becomes "omeletway”.
Write a C++ a program that reads a sentence as input and converts each word to “Pig-
Latin.”
Example output:
Input in English: One language is never enough
Output in Pig-Latin: Oneway anguagelay isway evernay enoughway

Marks distribution for question 8:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Comments or explanation of code= 2 marks

Question 9 [10 Marks]: Write a C++ program using pointers to compute the maximum and
minimum values of an array having a size of 10. The requirements are using two
functions of min and max and iterate the elements using pointers variable (and not
indexing of the array) to find the maximum and minimum values of the elements in the
array.
Example:
The array is: {11,30,107,17,92}
The maximum value in the array is: 107
The minimum value in the array is: 11

Marks distribution for question 9:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Comments or explanation of code= 2 marks

Page 5 of 6
National University of Computer and Emerging Sciences
FAST School of Computing Spring 2020 Islamabad Campus
Question 10 [10 Marks]:

Happy Numbers: A number is called a happy number, if you start with the given number
and arrive at 1 by repeating the following process (as illustrated in the below example):
(a) compute the sum of the squares of given number digits (b) if the resultant value is 1,
then the number is a happy number, else execute point (a) for the newly produced number.

Note that if a number is not a happy number, there will be an endless loop to this
execution.
Goal: In this question, you are required to write C++ code that checks whether the number
entered by the user is a happy number or not for 10 cycles/iteration only.

Marks distribution for question 10:


1) Appropriate data type and format = 2 marks
2) Correct syntax = 2 marks
3) Logic = 4 marks
4) Comments or explanation of code= 2 marks

Page 6 of 6

You might also like