PF Lab Final Fall'23
PF Lab Final Fall'23
Serial No:
CS-1002: Programming Final Exam
Fundamentals Lab Total Time: 3 Hours
Total Marks: 100
Instructions:
1. Attempt the questions on the provided system. Attempt all of them. Read the question
carefully, understand the question, and then attempt it. Write two lines of PF Lab feedback
on page 2 to get a bonus of two marks. Write clean code, correct indentation & make use of
good programming practices. “THINK MORE CODE LESS”
2. After being asked to commence the exam, please verify that you have nine (9) different
printed pages including this title page. There are a total of 4 questions.
3. Please make sure to submit a zipped folder(.zip) named yourRollNumber (23xxxx).
Please note that there is NO dash(-) and alphabet(i) in the folder name. The folder
should contain only .cpp files. The questions must be named as q1.cpp, q2.cpp…
4. Submission will only be accepted on Google Classroom. Failure to submit according to
submission guidelines will result in deduction of 20% marks in your section Tab.
5. Late submission will not be accepted.
6. Please note that you have to write the submission time at GCR on the front page of the
question paper.
Question: Write a C++ function to draw the following pattern using loop(s). YOU MUST FOLLOW
THE FOLLOWING STEPS
1. Make a function named “pattern” that takes two integer arguments i.e waveLength &
waveHeight. The function will print the pattern.
int main(){
for (int i = 3, j= 3; i<=8; i++,j+=2){
cout<< "length="<< i << " & height=" << j << endl;
pattern(i,j);
cout<<endl;
}
}
3. The output should look like this, if it’s 100% correct mark yourself 25/25 otherwise
0/25. Even an error of a single character will be considered incorrect. If you mark
yourself fairly you will get 1.5 marks.
Page 2 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
Page 3 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
An 3x3 normal magic square is an arrangement of the numbers 1, 2, 3, ... n2 in a square array, with
the property that the sum of every row and column, as well as both diagonals, is the same number.
An example of a 3x3 normal magic square is
618
753
294
You can verify that each of the three rows, the three columns, and the two diagonals add to 15.
Algorithm: To build a magic square we will be using Loubere's algorithm which is as follows:
Page 4 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
Page 5 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
dimension = 3 dimension = 5
816 17 24 1 8 15
23 5 7 14 16
357 4 6 13 20 22
492 10 12 19 21 3
11 18 25 2 9
dimension = 7 dimension = 9
30 39 48 1 10 19 28 47 58 69 80 1 12 23 34 45
38 47 7 9 18 27 29 57 68 79 9 11 22 33 44 46
46 6 8 17 26 35 37 67 78 8 10 21 32 43 54 56
5 14 16 25 34 36 45 77 7 18 20 31 42 53 55 66
13 15 24 33 42 44 4 6 17 19 30 41 52 63 65 76
21 23 32 41 43 3 12 16 27 29 40 51 62 64 75 5
22 31 40 49 2 11 20 26 28 39 50 61 72 74 4 15
36 38 49 60 71 73 3 14 25
37 48 59 70 81 2 13 24 35
The output should look like this, if it’s 100% correct mark yourself 25/25 otherwise 0/25. Even an
error of a single digit will be considered incorrect. If you mark yourself fairly you will get a 1.5
marks bonus.
Page 6 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
Question 3 [25 Marks]
Question: You are tasked with developing a simple user registration and login system in C++.
● Implement a displayMenu() function that has the following menu options. This
displayMenu() will be called repeat in the main function until the user exits the
program.
● Implement a registerUser() function that will ask the user to enter his name, email,
username, password, and age. After taking an input, call the isPasswordStrong(string)
to validate if the password is strong or not. If the password is strong, the registration
details should be stored in a text file with the given format. For example if I enter my
name then “ammar.txt” file will be created with all the entered information. Similarly, if
I register another user a new file for example “ahmed.txt” will be created containing
user info according to the following format.
ammar.txt
name:ammar
age:24
email:[email protected]
username:ammar_user
password:12am34
Implementation (1+3+3+3) 10
Page 7 of 8
National University of Computer and Emerging Sciences
FAST School of Computing Fall-2023 Islamabad Campus
Question 4 [25 Marks]
Implementation 8
Page 8 of 8