-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuizApp_Maheer.dart
298 lines (284 loc) · 8.65 KB
/
QuizApp_Maheer.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
import 'dart:io';
import 'dart:math';
class Quiz {
final List<Map<String, dynamic>> questions;
int score = 0;
int totalQuestions = 0;
Quiz(this.questions);
void askQuestion(int index, Map<String, dynamic> question) {
totalQuestions++;
print('Question ${index + 1}: ${question['question']}');
for (var i = 0; i < question['options'].length; i++) {
print('${i + 1}. ${question['options'][i]}');
}
stdout.write('Your answer (enter the option number): ');
var userAnswer = stdin.readLineSync();
if (userAnswer != null &&
userAnswer.isNotEmpty &&
RegExp('^[1-${question['options'].length}]').hasMatch(userAnswer)) {
var userChoice = int.parse(userAnswer);
if (userChoice == question['correctOption']) {
//print('Correct!\n');
score++;
} // else {
// print(
// 'Wrong! The correct answer is ${question['correctOption']}: ${question['options'][question['correctOption'] - 1]}\n');
// }
} else {
print('Invalid input. Please enter a valid option number.\n');
}
}
void runQuiz() {
var randList =
List.generate(10, (index) => Random().nextInt(questions.length));
print(randList);
for (var index = 0; index < randList.length; index++) {
askQuestion(index, questions[randList[index]]);
}
showResult();
}
void showResult() {
var percentageCorrect = (score / totalQuestions) * 100;
print('Total Correct Answers: $score');
print(
'Percentage of Correct Answers: ${percentageCorrect.toStringAsFixed(2)}%');
if (percentageCorrect > 50) {
print('Congratulations! You passed the quiz!');
} else {
print('Better luck next time!');
}
}
}
void main() {
var questions = [
{
'question': 'Who is the founder of Pakistan?',
'options': ['Allama Iqbal', 'Muhammad Ali Jinnah', 'Liaquat Ali Khan'],
'correctOption': 2,
},
{
'question': 'Which is the longest and biggest river of Pakistan?',
'options': ['Chenab River', 'Swat River', 'Sindh River'],
'correctOption': 3,
},
{
'question': 'What is the national language of Pakistan?',
'options': ['Urdu', 'Sindhi', 'Punjabi'],
'correctOption': 1,
},
{
'question': 'When did Pakistan got independence?',
'options': ['1945', '1947', '1950'],
'correctOption': 2,
},
{
'question': 'Which is the national bird of Pakistan?',
'options': ['Owl', 'Eagle', 'Chakor'],
'correctOption': 3,
},
{
'question': 'Which is the capital of Pakistan?',
'options': ['Karachi', 'Islamabad', 'Lahore'],
'correctOption': 2,
},
{
'question': 'Which is the largest city in Pakistan?',
'options': ['Multan', 'Islamabad', 'Karachi'],
'correctOption': 3,
},
{
'question': 'What is the meaning of Pakistan?',
'options': ['Green Land', 'Holy Land', 'Clean Land'],
'correctOption': 2,
},
{
'question': 'Where is Ayub Stadium in Pakistan?',
'options': ['Quetta', 'Multan', 'Islamabad'],
'correctOption': 1,
},
{
'question': 'Where is the tomb of Quaid e Azam?',
'options': ['Quetta', 'Lahore', 'Karachi'],
'correctOption': 3,
},
{
'question': 'In which city of Pakistan The Faisal Mosque is located?',
'options': ['Islamabad', 'Sukkur', 'Rawalpinidi'],
'correctOption': 1,
},
{
'question': 'Which is the national flower of Pakistan?',
'options': ['Rose', 'Tulip', 'Jasmine'],
'correctOption': 3,
},
{
'question': 'What is the name of the highest peak of Pakistan?',
'options': ['Nanga Parbat', 'K2', 'Tirich Mir'],
'correctOption': 2,
},
{
'question':
'Which desert is located in the southeastern part of Pakistan?',
'options': ['Thar', 'Cholistan', 'Katpana'],
'correctOption': 1,
},
{
'question': 'Which is the national animal of Pakistan?',
'options': ['Monkey', 'Cow', 'Markhor'],
'correctOption': 3,
},
{
'question': 'How many provinces are there in Pakistan?',
'options': ['Six', 'Five', 'Four'],
'correctOption': 2,
},
{
'question': 'What is the currency of Pakistan?',
'options': ['PKR', 'TAKA', 'RIYAL'],
'correctOption': 1,
},
{
'question': 'Who is known as the Father of Pakistans Nuclear program?',
'options': ['Salim Mehmud', 'Dr. Abdul Salam', 'Dr. Abdul Qadeer Khan'],
'correctOption': 3,
},
{
'question': 'Which Pakistani cricketer holds multiple batting records?',
'options': ['Babar Azam', 'Javed Miandad', 'Imran Khan'],
'correctOption': 2,
},
{
'question': 'In which city Minar e Pakistan is located?',
'options': ['Lahore', 'Multan', 'Hyderabad'],
'correctOption': 1,
},
{
'question': 'Which is the largest dam in Pakistan?',
'options': ['Mangla Dam', 'Kala Bagh Dam', 'Tarbela Dam'],
'correctOption': 3,
},
{
'question': 'What is the name of Pakistan Intelligence Agency?',
'options': ['FBI', 'RAW', 'ISI'],
'correctOption': 3,
},
{
'question': 'Who is the captain of Pakistan cricket team?',
'options': ['Babar Azam', 'Shaheen Afridi', 'Sarfaraz Ahmad'],
'correctOption': 1,
},
{
'question': 'In Islam, “Gateway to knowledge” is the title of?',
'options': ['Abu Bakr R.A', 'Ali R.A', ' Umar R.A'],
'correctOption': 2,
},
{
'question': 'When was first constitution of Pakistan was promulgated?',
'options': ['1956', '1973', '1960'],
'correctOption': 1,
},
{
'question': 'Which mountain range in located in Murree?',
'options': ['Kohsar', 'Potwar', 'Pir Panjal Range'],
'correctOption': 3,
},
{
'question':
'Which of the following operating system is based on open-source software?',
'options': ['Linux', ' Windows 2000', 'Windows NT'],
'correctOption': 1,
},
{
'question': 'RAM stands for?',
'options': [
'Random Access Memory',
'Read All Memory',
'Read Access Memory'
],
'correctOption': 1,
},
{
'question':
'Currently, which programming language is being mostly used in Data Science?',
'options': ['C#', 'JAVA', 'PYTHON'],
'correctOption': 3,
},
{
'question':
'The OSI model partitions the flow of data in a communication system into',
'options': ['5 layers', '7 layers', '3 layers'],
'correctOption': 2,
},
{
'question': 'How many Surahs (or chapters) are there in the Holy Quran?',
'options': ['105', '114', '120'],
'correctOption': 2,
},
{
'question': 'A formula in MS Excel =sum(D1:D10) will',
'options': [
'add first 10 rows of column 4',
'add first 10 columns',
'None of these'
],
'correctOption': 1,
},
{
'question':
'Which MS Office program is suitable to deliver presentation?',
'options': ['MS Excel', 'MS PowerPoint', 'MS Word'],
'correctOption': 2,
},
{
'question':
'Indus Waters Treaty between India and Pakistan was signed on?',
'options': ['1973', '1960', '1945'],
'correctOption': 2,
},
{
'question': 'Who was the first governor general of Pakistan?',
'options': ['Allama Iqbal', 'Muhammad Ali Jinnah', 'Liaquat Ali Khan'],
'correctOption': 2,
},
{
'question': 'Who was the first Prime Minister of Pakistan?',
'options': [
'Liaqat Ali Khan',
'General Ayub Khan',
'General Iskandar Mirza'
],
'correctOption': 1,
},
{
'question':
'Pakistan highest mountain K2 is situated in which mountain range?',
'options': ['Himalaya', 'Hindu Kush', 'Karakoram'],
'correctOption': 3,
},
{
'question': 'Which is the second highest mountain in Pakistan?',
'options': ['Nanga Parbat', 'Broad Peak', 'Rakaposhi'],
'correctOption': 1,
},
{
'question':
'Pakistans second highest mountain Nanga Parbat is situated in which mountain range?',
'options': ['Himalaya', 'Hindu Kush', 'Karakoram'],
'correctOption': 1,
},
{
'question': 'The worlds first nuclear power plant was built by',
'options': ['Russia', 'United States', 'Germany'],
'correctOption': 1,
}
];
var quiz = Quiz(questions);
while (true) {
quiz.runQuiz();
stdout.write('Do you want to restart the quiz? (yes/no): ');
var restart = stdin.readLineSync()?.toLowerCase();
if (restart != 'yes') {
break;
}
}
}