-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
1865 lines (1468 loc) · 96.8 KB
/
main.cpp
File metadata and controls
1865 lines (1468 loc) · 96.8 KB
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include<iostream>
#include<string>
#include <cctype>
using namespace std;
int userScore[10];
void cBasic() {
string cBasicQuestions[10][1] = {
{"What is the correct way to declare a variable in C?"},
{"Which of the following is not a data type in C?"},
{"What is the output of the following code: printf(\"%d\", 10 + 20);?"},
{"How do you create a comment in C?"},
{"Which function is used to read input from the user in C?"},
{"What does the `return` statement do in a function?"},
{"What is the correct syntax for an if statement in C?"},
{"What symbol is used to denote a string in C?"},
{"Which of the following is a valid identifier in C?"},
{"What is the purpose of the `#include` directive?"}
};
string cBasicOptions[10][1] = {
{"a) int number;\nb) number int;\nc) var number;\nd) integer number;"},
{"a) int\nb) float\nc) character\nd) string"},
{"a) 30\nb) 10\nc) 20\nd) Compilation error"},
{"a) // This is a comment\nb) -- This is a comment\nc) /* This is a comment */\nd) # This is a comment"},
{"a) input()\nb) scanf()\nc) read()\nd) get()"},
{"a) It exits the program\nb) It returns a value to the caller\nc) It terminates the loop\nd) None of the above"},
{"a) if x = 10\nb) if (x == 10)\nc) if x == 10\nd) if (x = 10)"},
{"a) 'string'\nb) \"string\"\nc) (string)\nd) `string`"},
{"a) 1valid\nb) valid_1\nc) valid#1\nd) 1valid!"},
{"a) To include standard libraries\nb) To define macros\nc) To declare variables\nd) None of the above"}
};
char cBasicAnswers[10] = {'a', 'c', 'a', 'a', 'b', 'b', 'b', 'b', 'b', 'a'};
string cBasicExplanations[10][1] = {
{"In C, a variable is declared by specifying its data type followed by the variable name, like `int number;`. This indicates that `number` can hold integer values."},
{"`character` is not a data type in C. The primary data types in C are `int`, `float`, and `double`, among others."},
{"The output of `printf(\"%d\", 10 + 20);` is `30`, as it sums the two integers."},
{"Comments in C can be created using `//` for single-line comments or `/* ... */` for multi-line comments."},
{"The `scanf()` function is used to take input from the user, allowing dynamic data entry."},
{"The `return` statement exits a function and can return a value to the function's caller, enabling feedback from functions."},
{"The correct syntax for an if statement in C is `if (condition)`. This checks the condition and executes the block of code if true."},
{"Strings in C are denoted using double quotes, e.g., \"string\". Single quotes are used for single characters."},
{"`valid_1` is a valid identifier. Identifiers must start with a letter or underscore and cannot contain special characters."},
{"The `#include` directive is used to include standard libraries or headers, enabling access to pre-defined functions."}
};
char userAnswers[10];
int userScore[10] = {0};
for(int i = 0; i < 10; i++) {
cout << i + 1 << ". " << cBasicQuestions[i][0] << endl;
cout << cBasicOptions[i][0] << endl;
cout << "Answer: ";
cin >> userAnswers[i];
userAnswers[i] = tolower(userAnswers[i]);
cout << endl;
if (userAnswers[i] == cBasicAnswers[i]) {
userScore[i] = 4;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == 'p'){
userScore[i] = 0 ;
cout << "The correct answer is " << cBasicAnswers[i] << "." << endl;
cout << endl;
cout << "Explanation: " << cBasicExplanations[i][0] << endl;
}
else {
userScore[i] = -1;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cBasicAnswers[i] << "." << endl;
cout << endl;
cout << "Explanation: " << cBasicExplanations[i][0] << endl;
}
cout << endl;
}
}
void cIntermediateQuiz() {
string cIntermediateQuestions[10][1] = {
{"What is a pointer in C?"},
{"How do you allocate memory dynamically in C?"},
{"What is the output of the following code: printf(\"%d\", sizeof(int));?"},
{"What is the purpose of the `void` keyword in a function signature?"},
{"How do you define a macro in C?"},
{"What is a segmentation fault?"},
{"What is the difference between `==` and `=` in C?"},
{"How do you declare a structure in C?"},
{"What is the purpose of the `break` statement?"},
{"What is a function pointer?"}
};
string cIntermediateOptions[10][1] = {
{"a) A variable that stores a memory address\nb) A special data type\nc) Both a and b\nd) None of the above"},
{"a) malloc()\nb) calloc()\nc) realloc()\nd) All of the above"},
{"a) 2\nb) 4\nc) 8\nd) Compiler error"},
{"a) It indicates a function does not return a value\nb) It is used for pointers\nc) Both a and b\nd) None of the above"},
{"a) #define MACRO_NAME\nb) define MACRO_NAME\nc) macro MACRO_NAME\nd) #define(MACRO_NAME)"},
{"a) An error caused by accessing invalid memory\nb) A warning during compilation\nc) Both a and b\nd) None of the above"},
{"a) `==` is used for assignment, `=` is used for comparison\nb) `==` is used for comparison, `=` is used for assignment\nc) Both a and b\nd) None of the above"},
{"a) struct myStruct {}\nb) struct myStruct = {}\nc) struct myStruct[]\nd) struct = myStruct"},
{"a) To exit loops\nb) To stop program execution\nc) Both a and b\nd) None of the above"},
{"a) A pointer that points to a function\nb) A function that returns a pointer\nc) Both a and b\nd) None of the above"}
};
char cIntermediateAnswers[10] = {'c', 'd', 'b', 'a', 'a', 'a', 'b', 'a', 'a', 'a'};
string cIntermediateExplanations[10][1] = {
{"A pointer in C is a variable that stores the memory address of another variable, allowing for dynamic memory management."},
{"Memory in C can be allocated dynamically using `malloc()`, `calloc()`, or `realloc()` functions."},
{"The output of `printf(\"%d\", sizeof(int));` is typically `4`, as most systems use 4 bytes for an integer."},
{"The `void` keyword in a function signature indicates that the function does not return a value."},
{"A macro can be defined in C using `#define MACRO_NAME`, allowing for code substitution during preprocessing."},
{"A segmentation fault is an error that occurs when a program attempts to access an invalid memory location."},
{"`==` is used for comparison (equality), while `=` is used for assignment (setting values)."},
{"A structure in C is declared using `struct myStruct { ... };`, which groups related variables."},
{"The `break` statement is used to exit loops or switch cases prematurely."},
{"A function pointer is a pointer that points to a function, allowing dynamic function calls."}
};
char userAnswers[10];
int userScore[10] = {0};
for (int i = 0; i < 10; i++) {
cout << i + 1 << ". " << cIntermediateQuestions[i][0] << endl;
cout << cIntermediateOptions[i][0] << endl;
cout << "Answer: ";
cin >> userAnswers[i];
userAnswers[i] = tolower(userAnswers[i]);
if (userAnswers[i] == cIntermediateAnswers[i]) {
userScore[i] = 4;
cout << "Correct answer..." << endl;
} else if (userAnswers[i] == 'p') {
userScore[i] = 0;
cout << "The correct answer is " << cIntermediateAnswers[i] << "." << endl;
cout << endl;
cout << "Explanation: " << cIntermediateExplanations[i][0] << endl;
} else {
userScore[i] = -1;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cIntermediateAnswers[i] << "." << endl;
cout << endl;
cout << "Explanation: " << cIntermediateExplanations[i][0] << endl;
}
cout << endl;
}
}
void cAdvancedQuiz() {
string cAdvancedQuestions[10][1] = {
{"What is the difference between `malloc()` and `calloc()`?"},
{"What is a union in C?"},
{"What is the output of the following code: printf(\"%d\", sizeof(*p)); where int *p;?"},
{"What is the purpose of the `const` keyword in C?"},
{"What is a linked list?"},
{"How do you handle errors in C?"},
{"What is the significance of `static` storage class in C?"},
{"What are function prototypes in C?"},
{"What is the difference between `strncpy()` and `strcpy()`?"},
{"What is the purpose of the `volatile` keyword in C?"}
};
string cAdvancedOptions[10][1] = {
{"a) `malloc()` initializes memory to zero\nb) `calloc()` initializes memory to zero\nc) Both do the same thing\nd) None of the above"},
{"a) A data type that can hold multiple values\nb) A special type of array\nc) A structure that can hold different data types\nd) None of the above"},
{"a) Size of the pointer\nb) Size of the data type\nc) Size of the variable\nd) Compiler error"},
{"a) To make a variable read-only\nb) To indicate a constant pointer\nc) Both a and b\nd) None of the above"},
{"a) A data structure that stores elements sequentially\nb) A data structure that stores elements non-sequentially\nc) A linear data structure\nd) None of the above"},
{"a) Using return codes\nb) Using assertions\nc) Both a and b\nd) None of the above"},
{"a) It retains its value between function calls\nb) It initializes variables to zero\nc) It makes a variable accessible globally\nd) None of the above"},
{"a) They declare the function's name and parameters\nb) They define the function's behavior\nc) Both a and b\nd) None of the above"},
{"a) `strncpy()` is safer than `strcpy()`\nb) `strncpy()` does not null-terminate the string if the length exceeds\nc) Both a and b\nd) None of the above"},
{"a) It tells the compiler to optimize the variable\nb) It prevents the compiler from caching the variable\nc) Both a and b\nd) None of the above"}
};
char cAdvancedAnswers[10] = {'b', 'c', 'b', 'a', 'c', 'c', 'a', 'a', 'c', 'b'};
string cAdvancedExplanations[10][1] = {
{"`malloc()` allocates uninitialized memory, while `calloc()` allocates memory and initializes it to zero. This can affect program behavior if uninitialized values are used."},
{"A union in C is a special data type that allows storing different data types in the same memory location. Only one member can contain a value at any given time."},
{"The output of `printf(\"%d\", sizeof(*p));` would be the size of the integer type (typically 4 bytes on many systems), as `p` is a pointer to an integer."},
{"The `const` keyword in C is used to define variables whose value cannot be modified after initialization, enhancing code safety and clarity."},
{"A linked list is a data structure consisting of nodes, where each node contains data and a pointer to the next node, allowing dynamic memory allocation."},
{"Errors in C can be handled using return codes or specific functions like `perror()` to print error messages related to system calls."},
{"The `static` storage class means the variable retains its value between function calls and is limited to the scope in which it is defined."},
{"Function prototypes declare the function's name, return type, and parameters, enabling type checking before the actual function definition."},
{"`strncpy()` copies a specified number of characters from one string to another and does not null-terminate if the length exceeds, making it safer than `strcpy()`."},
{"The `volatile` keyword informs the compiler that the variable may change at any time, preventing optimization that might assume the value doesn't change."}
};
char userAnswers[10];
int userScore[10] = {0};
for (int i = 0; i < 10; i++) {
cout << i + 1 << ". " << cAdvancedQuestions[i][0] << endl;
cout << cAdvancedOptions[i][0] << endl;
cout << "Answer: ";
cin >> userAnswers[i];
userAnswers[i] = tolower(userAnswers[i]);
if (userAnswers[i] == cAdvancedAnswers[i]) {
userScore[i] = 4;
cout << "Correct answer..." << endl;
} else if (userAnswers[i] == 'p') {
userScore[i] = 0;
cout << "The correct answer is " << cAdvancedAnswers[i] << "." << endl;
cout << "Explanation: " << cAdvancedExplanations[i][0] << endl;
} else {
userScore[i] = -1;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cAdvancedAnswers[i] << "." << endl;
cout << "Explanation: " << cAdvancedExplanations[i][0] << endl;
}
cout << endl;
}
}
void cppBasic(){
string cppBasicQuestions[10][1]={
{"What is the correct way to declare a variable in C++?",},
{"What does the std namespace stand for?"},
{"Which symbol is used to end a statement in C++?"},
{"Which of the following is not a keyword in C++?"},
{"How do you create a single-line comment in C++?"},
{"Which function is used to print output to the console in C++?"},
{"What will the following code output: cout << \"Hello World\" ;?"},
{"Which operator is used for assignment in C++?"},
{"How do you start a for loop in C++?"},
{"What is the correct way to include a header file in C++?"}
};
string cppBasicOptions[10][1]={
{"a) int number;\nb) number int;\nc) var number;\nd)integer number;"},
{"a) Standard\nb) Study\nc) Standalone\nd) Static"},
{"a) .\nb) ;\nc) ,\nd) :"},
{"a) int\nb) float\nc) number\nd) double"},
{"a) # This is a comment\nb) -- This is a comment\nc) // This is a comment\nd) /* This is a comment */"},
{"a) print()\nb) cout\nc) echo\nd) output()"},
{"a) Hello\nb) World\nc) Hello World\nd) cout << \"Hello World\";"},
{"a) =\nb) ==\nc) !=\nd) ++"},
{"a) for(int i = 0; i < 10; i++)\nb) for i = 1 to 1\nc) foreach(int i in 10)\nd) loop from i = 1 to 10"},
{"a) #include <iostream>\nb) include iostream\nc) #include \"iostream\"\nd) #import <iostream>"}
};
char cppBasicAnswers[10] = {'a', 'a', 'b', 'c', 'c', 'b', 'c', 'a', 'a', 'a'};
string cppBasicExplanations[10][1] = {
{"In C++, a variable is declared by specifying its data type followed by the variable name, like `int number;`. Here, `int` defines the type of data that the variable will store, which in this case is an integer. Proper declaration is crucial because it reserves memory space and allows the compiler to manage the data type correctly."},
{"`std` stands for 'Standard' and is a namespace in C++. A namespace is used to organize code and prevent name conflicts. The `std` namespace contains the standard library's functionality, such as input and output functions like `cout` (for displaying output) and `cin` (for receiving input). Using `std` helps avoid conflicts with user-defined names."},
{"A semicolon (`;`) is used to terminate statements in C++. It marks the end of a logical instruction. Missing semicolons lead to compilation errors because the compiler expects each command to be concluded with this symbol."},
{"`number` is not a keyword in C++. Keywords like `int`, `float`, and `double` are reserved words that have specific meanings in C++ and cannot be used as variable names. Choosing non-keyword names for variables avoids conflicts and allows the code to function correctly."},
{"In C++, `//` is used to create a single-line comment, making the compiler ignore the remainder of the line. Comments are crucial for code readability, helping developers understand the purpose of specific code blocks without affecting execution."},
{"`cout` is a standard output stream in C++, used to print data to the console. It's part of the `iostream` library, which requires `#include <iostream>`. `cout` works with the insertion operator (`<<`) to display strings or variables."},
{"The statement `cout << \"Hello World\";` outputs the text 'Hello World' to the console. Without `endl` or `\\n`, it doesn't move to a new line after printing. Proper output formatting enhances user interaction."},
{"The `=` operator in C++ assigns a value from the right-hand side to a variable on the left-hand side. This basic operator is fundamental for setting and updating variable values in programs."},
{"In C++, a typical for loop starts with `for(int i = 0; i < 10; i++)`. It includes initialization (`int i = 0`), a condition (`i < 10`), and an increment (`i++`). This loop is essential for iterating a set number of times."},
{"To include standard libraries in C++, use the `#include <iostream>` directive. This allows access to functions like `cout` and `cin` by linking the necessary libraries during compilation. Proper inclusion of headers is vital for utilizing C++ functionalities."}
};
char userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << cppBasicQuestions[i][0] << endl;
cout << cppBasicOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
userAnswers[i] = tolower(userAnswers[i]);
if(userAnswers[i] == cppBasicAnswers[i]){
userScore[i] = 4;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == 'p'){
userScore[i] = 0;
cout << "The correct answer is " << cppBasicAnswers[i] << "." << endl;
cout << "Explaination : " << cppBasicExplanations[i][0] << endl;
}
else{
userScore[i] = -1 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cppBasicAnswers[i] << "." << endl;
cout << "Explaination : " << cppBasicExplanations[i][0] << endl;
}
cout << endl;
}
}
void cppIntermediate(){
string cppIntermediateQuestions[10][1] = {
{"What does the following code snippet output?\nint a = 5, b = 10;\ncout << a + b << endl;"},
{"Which keyword is used to define a constant variable in C++?"},
{"How do you access the third element in an array named `numbers` in C++?"},
{"What is the output of the following code?\nint x = 3;\nx *= 2;\ncout << x;"},
{"Which of the following is used to create an object in C++?"},
{"What is the scope resolution operator in C++?"},
{"Which of the following is a valid C++ string declaration?"},
{"What does the following code do?\nint *ptr = new int;"},
{"What is the result of `5 % 2` in C++?"},
{"How do you define a destructor in a C++ class?"}
};
string cppIntermediateOptions[10][1] = {
{"a) 5\nb) 10\nc) 15\nd) 50"},
{"a) constant\nb) final\nc) const\nd) let"},
{"a) numbers[3]\nb) numbers(3)\nc) numbers[2]\nd) numbers(2)"},
{"a) 3\nb) 6\nc) 9\nd) 12"},
{"a) class\nb) struct\nc) object\nd) new"},
{"a) ::\nb) ..\nc) =>\nd) **"},
{"a) string s = \"Hello\";\nb) char s[6] = \"Hello\";\nc) str s = 'Hello';\nd) String s = Hello;"},
{"a) Allocates memory for an integer pointer\nb) Allocates memory for an integer\nc) Creates a null pointer\nd) Deallocates memory"},
{"a) 2.5\nb) 1\nc) 0\nd) 2"},
{"a) ~ClassName()\nb) destructor ClassName()\nc) delete ClassName()\nd) ~ClassName[]"}
};
char cppIntermediateAnswers[10] = {'c', 'c', 'c', 'b', 'd', 'a', 'a', 'b', 'b', 'a'};
string cppIntermediateExplanations[10][1] = {
{"The code snippet `int a = 5, b = 10; cout << a + b << endl;` outputs `15`. This is because the addition operation `a + b` results in `5 + 10`, which equals 15. The `endl` moves the cursor to the next line."},
{"The keyword `const` is used to define a constant variable in C++. It prevents the variable's value from being modified after its initial assignment. This is helpful in maintaining consistency, especially when values should remain unchanged."},
{"To access the third element in an array `numbers` in C++, you use `numbers[2]`. In C++, array indexing starts from 0, so `numbers[2]` gives you the third element."},
{"The code `int x = 3; x *= 2; cout << x;` will output `6`. The `x *= 2` statement is equivalent to `x = x * 2`, multiplying the original value of `x` by 2."},
{"To create an object in C++, you use the `new` operator, which allocates memory dynamically. This is essential for creating instances of classes and handling memory management manually when necessary."},
{"The scope resolution operator `::` in C++ is used to specify the context for identifiers. It allows access to global variables or specific class members, especially when there are naming conflicts."},
{"In C++, `string s = \"Hello\";` is the correct way to declare a string variable using the `std::string` class. This is part of the standard library for handling sequences of characters."},
{"The code `int *ptr = new int;` dynamically allocates memory for an integer. The `new` operator returns a pointer to the allocated memory. It's crucial to manage memory properly to avoid leaks."},
{"The expression `5 % 2` returns `1`. The `%` operator is the modulo operator, which provides the remainder of the division. In this case, `5 divided by 2` leaves a remainder of 1."},
{"To define a destructor in C++, you use `~ClassName()`. A destructor is a special member function that is automatically called when an object goes out of scope, cleaning up resources."}
};
char userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << cppIntermediateQuestions[i][0] << endl;
cout << cppIntermediateOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
userAnswers[i = tolower(userAnswers[i])];
if(userAnswers[i] == cppIntermediateAnswers[i]){
userScore[i] = 4;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == 'p'){
userScore[i] = 0;
cout << "The correct answer is " << cppIntermediateAnswers[i] << "." << endl;
cout << "Explaination : " << cppIntermediateExplanations[i][0] << endl;
}
else{
userScore[i] = -1 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cppIntermediateAnswers[i] << "." << endl;
cout << "Explaination : " << cppIntermediateExplanations[i][0] << endl;
}
cout << endl;
}
}
void cppAdvanced(){
string cppAdvancedQuestions[10][1] = {
{"What is a virtual function in C++?"},
{"Which of the following is used for dynamic method resolution in C++?"},
{"What is the main purpose of the `friend` keyword in C++?"},
{"What does RAII stand for in C++ programming?"},
{"Which of the following types cannot be thrown as an exception in C++?"},
{"What will the following code output if a segmentation fault does not occur?\nint* ptr = nullptr;\ncout << *ptr;"},
{"What is the use of the `mutable` keyword in C++?"},
{"Which of the following concepts is achieved by using templates in C++?"},
{"Which C++ feature helps in preventing memory leaks when using dynamic memory allocation?"},
{"What is the difference between `delete` and `delete[]` in C++?"}
};
string cppAdvancedOptions[10][1] = {
{"a) A function that can be overridden in a derived class\nb) A function that cannot be overridden\nc) A function that must return an integer\nd) A function with no parameters"},
{"a) Pointers\nb) Virtual functions\nc) Static variables\nd) Templates"},
{"a) To create global variables\nb) To allow access to private members of a class\nc) To define constants\nd) To create pointers"},
{"a) Resource Allocation Is Initialization\nb) Resource Allocation Is Invalid\nc) Random Access Initialization Interface\nd) Run-time Allocation and Initialization"},
{"a) Classes\nb) Integers\nc) Objects\nd) Functions"},
{"a) 0\nb) An error\nc) Undefined behavior\nd) The value stored in memory at the address 0"},
{"a) To make a variable modifiable even if it's part of a const object\nb) To create mutable objects\nc) To allocate memory dynamically\nd) To define constant expressions"},
{"a) Overloading\nb) Data abstraction\nc) Inheritance\nd) Code reusability"},
{"a) Virtual functions\nb) Smart pointers\nc) Global variables\nd) Static memory allocation"},
{"a) `delete` is used for pointers, `delete[]` is for arrays\nb) `delete[]` is used for classes, `delete` is for integers\nc) Both are identical\nd) `delete` is faster than `delete[]`"}
};
char cppAdvancedAnswers[10] = {'a', 'b', 'b', 'a', 'b', 'c', 'a', 'd', 'b', 'a'};
string cppAdvancedExplanations[10][1] = {
{"A virtual function in C++ is a member function that can be overridden in derived classes. It's defined with the `virtual` keyword in the base class. This enables dynamic binding, allowing the correct function to be called based on the object type during runtime."},
{"Dynamic method resolution in C++ is achieved using virtual functions. They allow derived classes to override base class functions, ensuring that the appropriate function is called based on the actual object type at runtime."},
{"The `friend` keyword in C++ grants a non-member function or another class access to the private and protected members of the class. This is useful when external functions need access to a class's internal details without violating encapsulation principles."},
{"RAII stands for 'Resource Acquisition Is Initialization'. It's a programming concept in C++ that ties resource management to object lifetime. When an object is created, resources are acquired, and they are released when the object is destroyed, helping prevent resource leaks."},
{"In C++, types that cannot be thrown as exceptions include primitive data types like `int`, `float`, and `double`. Instead, exceptions should be objects of classes that can convey detailed error information."},
{"If `int* ptr = nullptr; cout << *ptr;` is executed without a segmentation fault, it results in undefined behavior. Attempting to dereference a `nullptr` is unsafe, and it typically causes a runtime error or a crash."},
{"The `mutable` keyword in C++ allows a member variable of a `const` object to be modified. This is helpful when you need to change some internal state without affecting the object's external interface."},
{"Templates in C++ provide code reusability and type safety by allowing functions and classes to operate with generic types. They enable compile-time polymorphism, facilitating operations with various data types without rewriting code."},
{"Smart pointers in C++ manage dynamic memory to prevent memory leaks. They automatically deallocate memory when it's no longer needed, reducing the risk of resource leaks and improving memory management."},
{"The difference between `delete` and `delete[]` in C++ is that `delete` is used to free memory allocated for a single object, while `delete[]` is for memory allocated for an array of objects, ensuring proper deallocation."}
};
char userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << cppAdvancedQuestions[i][0] << endl;
cout << cppAdvancedOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
userAnswers[i] = tolower(userAnswers[i]);
if(userAnswers[i] == cppAdvancedAnswers[i]){
userScore[i] = 4;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == 'p'){
userScore[i] = 0;
cout << "The correct answer is " << cppAdvancedAnswers[i] << "." << endl;
cout << "Explaination : " << cppAdvancedExplanations[i][0] << endl;
}
else{
userScore[i] = -1 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << cppAdvancedAnswers[i] << "." << endl;
cout << "Explaination : " << cppAdvancedExplanations[i][0] << endl;
}
}
}
void pythonBasic(){
string pythonBasicQuestions[10][1]={
{"What is the correct syntax to output the text 'Hello, World!' in Python?"},
{"How do you create a variable with the numeric value 5 in Python?"},
{"Which operator is used to multiply numbers in Python?"},
{"What data type is the result of this expression: 5 / 2?"},
{"Which function is used to get the length of a list in Python?"},
{"How do you insert a comment in a Python code?"},
{"Which method is used to convert a string to lowercase in Python?"},
{"How do you create a list in Python?"},
{"What keyword is used to define a function in Python?"},
{"How do you add a single line comment in Python?"}
};
string pythonBasicOptions[10][1] = {
{"a) echo 'Hello, World!'\nb) print('Hello, World!')\nc) p('Hello, World!')\nd) echo.print('Hello, World!')"},
{"a) x = 5\nb) int x = 5\nc) num = int(5)\nd) var x = 5"},
{"a) +\nb) -\nc) *\nd) /"},
{"a) int\nb) float\nc) str\nd) bool"},
{"a) size()\nb) count()\nc) length()\nd) len()"},
{"a) # This is a comment\nb) // This is a comment\nc) <!-- This is a comment -->\nd) /* This is a comment */"},
{"a) lower()\nb) downcase()\nc) lowercase()\nd) convert()"},
{"a) myList = (1, 2, 3)\nb) myList = {1, 2, 3}\nc) myList = [1, 2, 3]\nd) myList = <1, 2, 3>"},
{"a) func\nb) define\nc) def\nd) function"},
{"a) //\nb) /*\nc) #\nd) <!--"}
};
string pythonBasicAnswers[10] = {"b", "a", "c", "b", "d", "a", "a", "c", "c", "c"};
string pythonBasicExplanations[10][1] = {
{"In Python, the correct syntax to output text is using the print() function, as in print('Hello, World!'). This function sends the specified text to the console, allowing for easy debugging and interaction."},
{"To create a variable with a numeric value in Python, you simply write x = 5. Unlike some languages, Python does not require explicit data type declarations, making it straightforward to define variables."},
{"The multiplication operator in Python is the asterisk (*). It's used to multiply two numbers, just as in mathematics, and is a fundamental operator in arithmetic operations."},
{"The expression 5 / 2 evaluates to a float data type in Python (2.5), because Python automatically converts the result to a floating-point number when dividing integers."},
{"To get the length of a list in Python, the len() function is used. This built-in function returns the number of elements in a list, making it essential for list manipulations."},
{"In Python, comments are inserted using the '#' symbol. Anything following this symbol on the same line is ignored by the interpreter, making it easier for developers to annotate code."},
{"The method lower() is used to convert a string to lowercase in Python. This is useful for case-insensitive comparisons or data normalization."},
{"To create a list in Python, you can use square brackets, as in myList = [1, 2, 3]. This syntax is straightforward and flexible for storing multiple items."},
{"The keyword def is used to define a function in Python. It precedes the function name and allows the programmer to encapsulate code for reuse."},
{"In Python, a single line comment can be added with the '#' symbol. This practice is important for code clarity, helping others (and yourself) understand the logic later."}
};
string userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << pythonBasicQuestions[i][0] << endl;
cout << pythonBasicOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
for (char &c : userAnswers[i] ){
c = tolower(c);
}
if(userAnswers[i] == pythonBasicAnswers[i]){
userScore[i] = 1;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == "pass"){
userScore[i] = 0;
continue;
}
else{
userScore[i] = 0 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << pythonBasicAnswers[i] << "." << endl;
cout << "Explaination : " << pythonBasicExplanations[i][0] << endl;
}
}
}
void pythonIntermediate(){
string pythonIntermediateQuestions[10][1] = {
{"Which of the following data types is not mutable in Python?"},
{"What is the output of the following code? print('Hello' + 'World')"},
{"Which keyword is used for error handling in Python?"},
{"What does the following code output? print(type(10))"},
{"How do you access the last element of a list named myList?"},
{"What is the correct way to open a file in read mode in Python?"},
{"Which of the following is used to define a block of code in Python?"},
{"What is the output of the following code: print(2 ** 3)?"},
{"Which built-in function can be used to sort a list in ascending order?"},
{"Which of the following statements creates a dictionary?"}
};
string pythonIntermediateOptions[10][1] = {
{"a) list\nb) tuple\nc) dictionary\nd) set"},
{"a) HelloWorld\nb) Hello World\nc) Hello+World\nd) Error"},
{"a) catch\nb) try\nc) except\nd) error"},
{"a) float\nb) int\nc) str\nd) list"},
{"a) myList[-1]\nb) myList[1]\nc) myList[0]\nd) myList[myList.length]"},
{"a) open('file.txt', 'r')\nb) open('file.txt', 'read')\nc) open('file.txt')\nd) open.read('file.txt')"},
{"a) {}\nb) []\nc) ()\nd) Indentation"},
{"a) 6\nb) 8\nc) 9\nd) None of the above"},
{"a) order()\nb) sorted()\nc) sortList()\nd) arrange()"},
{"a) myDict = {}\nb) myDict = {1, 2, 3}\nc) myDict = {'name': 'John', 'age': 25}\nd) myDict = [1, 2, 3]"}
};
string pythonIntermediateAnswers[10] = {"b", "a", "b", "b", "a", "a", "d", "b", "b", "c"};
#include <string>
string pythonIntermediateExplanations[10][1] = {
{"A tuple in Python is an immutable sequence type, defined by placing values inside parentheses (e.g., my_tuple = (1, 2, 3)). Once created, its elements cannot be changed, making it useful for fixed collections of items."},
{"The output of the code print('Hello' + 'World') will be HelloWorld. The plus operator concatenates the two strings, joining them without spaces."},
{"The keyword used for exception handling in Python is try, followed by an except clause to catch exceptions. This structure allows for error management and graceful handling of unexpected events."},
{"The output of type(10) is <class 'int'>, indicating that the value is of integer type. Python dynamically determines the type based on the assigned value."},
{"To access the last item of a list, you can use negative indexing, such as myList[-1]. This feature allows for easy retrieval of elements from the end of a list."},
{"To open a file in Python, the open() function is used. This function can read or write files, and it's crucial for file operations in Python."},
{"Indentation in Python is significant as it defines the blocks of code. Unlike other languages that use braces, Python uses spaces or tabs to group statements, affecting the program's structure."},
{"The expression 2 ** 3 evaluates to 8. The double asterisk operator is used for exponentiation in Python, raising the left operand to the power of the right operand."},
{"To sort a list in Python, the sort() method is called on the list. This method rearranges the elements in ascending order by default."},
{"A dictionary in Python is defined using curly braces with key-value pairs, such as myDict = {'key': 'value'}. This data structure allows for efficient data retrieval based on unique keys."}
};
string userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << pythonIntermediateQuestions[i][0] << endl;
cout << pythonIntermediateOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
for (char &c : userAnswers[i] ){
c = tolower(c);
}
if(userAnswers[i] == pythonIntermediateAnswers[i]){
userScore[i] = 1;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == "pass"){
userScore[i] = 0;
continue;
}
else{
userScore[i] = 0 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << pythonIntermediateAnswers[i] << "." << endl;
cout << "Explaination : " << pythonIntermediateExplanations[i][0] << endl;
}
}
}
void pythonAdvanced(){
string pythonAdvancedQuestions[10][1] = {
{"What is a decorator in Python?"},
{"Which of the following is not a valid way to create a set in Python?"},
{"What is the purpose of the `self` keyword in Python?"},
{"What will be the output of this code: print([x for x in range(5) if x % 2 == 0])?"},
{"Which of the following statements about Python is true?"},
{"What does the `with` statement do in Python?"},
{"What is the difference between `__str__` and `__repr__`?"},
{"How can you remove duplicates from a list in Python?"},
{"What is the main advantage of using `asyncio` in Python?"},
{"Which method is used to combine two lists in Python?"}
};
string pythonAdvancedOptions[10][1] = {
{"a) A function that modifies another function\nb) A type of class\nc) A built-in function\nd) A module"},
{"a) set()\nb) {} \nc) []\nd) set([1, 2, 3])"},
{"a) It refers to the class itself\nb) It refers to the current instance of the class\nc) It is optional\nd) None of the above"},
{"a) [0, 2, 4]\nb) [1, 3]\nc) [0, 1, 2, 3, 4]\nd) None of the above"},
{"a) Python is statically typed\nb) Python supports multiple inheritance\nc) Python uses braces to define blocks\nd) None of the above"},
{"a) It creates a context for resource management\nb) It defines a new function\nc) It handles exceptions\nd) It is used for importing modules"},
{"a) They serve the same purpose\nb) `__str__` is for user-friendly output, `__repr__` is for unambiguous output\nc) `__str__` is called by `print`, `__repr__` is not\nd) Both are the same"},
{"a) Use a set\nb) Use a loop\nc) Use the list method\n d) All of the above"},
{"a) It allows asynchronous programming\nb) It is faster than threading\nc) It simplifies code\n d) None of the above"},
{"a) concat()\nb) combine()\nc) append()\nd) extend()"}
};
string pythonAdvancedAnswers[10] = {"a", "c", "b", "a", "b", "a", "b", "d", "a", "d"};
#include <string>
string pythonAdvancedExplanations[10][1] = {
{"In Python, a decorator is a function that modifies another function or method, allowing you to wrap additional behavior around the original function, enhancing its capabilities."},
{"A list in Python is correctly created using square brackets. For example, myList = [1, 2, 3] initializes a list containing three elements."},
{"In a class, 'self' refers to the instance of the class itself. It allows access to the attributes and methods associated with that instance, making it fundamental in object-oriented programming."},
{"The output of the list comprehension [x for x in range(5) if x % 2 == 0] will be [0, 2, 4]. This creates a new list containing only the even numbers from the specified range."},
{"Multiple inheritance in Python allows a class to inherit attributes and methods from more than one parent class. This feature provides greater flexibility but can lead to complexity in method resolution."},
{"The 'with' statement in Python simplifies exception handling by wrapping the execution of a block of code within methods defined by a context manager, ensuring proper resource management."},
{"The __str__ and __repr__ methods in Python serve different purposes; __str__ is meant to provide a readable string representation for end-users, while __repr__ aims to provide an unambiguous representation for developers."},
{"To remove duplicates from a list, you can convert it to a set and back to a list, e.g., list(set(myList)). This method leverages the set's unique properties."},
{"Asyncio in Python allows for asynchronous programming, enabling concurrent execution of tasks without blocking, which is essential for I/O-bound applications."},
{"The extend() method in a list appends elements from an iterable to the end of the list, effectively merging lists, unlike append(), which adds a single element."}
};
string userAnswers[10];
for(int i=0; i<10; i++){
cout << i + 1 << ". " << pythonAdvancedQuestions[i][0] << endl;
cout << pythonAdvancedOptions[i][0] << endl;
cout << "Answer : "; cin >> userAnswers[i];
for (char &c : userAnswers[i] ){
c = tolower(c);
}
if(userAnswers[i] == pythonAdvancedAnswers[i]){
userScore[i] = 1;
cout << "Correct answer..." << endl;
}
else if (userAnswers[i] == "pass"){
userScore[i] = 0;
continue;
}
else{
userScore[i] = 0 ;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << pythonAdvancedAnswers[i] << "." << endl;
}
}
}
void sqlBasicQuiz() {
string sqlBasicQuestions[10][1] = {
{"What does SQL stand for?"},
{"Which of the following is a valid SQL statement?"},
{"What is the purpose of the `SELECT` statement?"},
{"Which SQL clause is used to filter records?"},
{"What is the default sorting order of the `ORDER BY` clause?"},
{"What is the purpose of the `WHERE` clause?"},
{"Which SQL statement is used to update data in a table?"},
{"What is a primary key?"},
{"Which SQL function is used to count the number of rows?"},
{"What is the purpose of the `JOIN` clause?"}
};
string sqlBasicOptions[10][1] = {
{"a) Structured Query Language\nb) Sequential Query Language\nc) Simple Query Language\nd) None of the above"},
{"a) SELECT * FROM table;\nb) SELECT table *;\nc) TABLE SELECT *;\nd) None of the above"},
{"a) To insert data into a table\nb) To retrieve data from a database\nc) To update data in a table\nd) To delete data from a table"},
{"a) WHERE\nb) FILTER\nc) SELECT\nd) SORT"},
{"a) Ascending\nb) Descending\nc) Random\nd) None of the above"},
{"a) To delete records\nb) To update records\nc) To filter records based on a condition\nd) To select records"},
{"a) UPDATE statement\nb) CHANGE statement\nc) MODIFY statement\nd) None of the above"},
{"a) A unique identifier for each record in a table\nb) A field that can hold null values\nc) A foreign key reference\nd) None of the above"},
{"a) COUNT()\nb) SUM()\nc) AVERAGE()\nd) TOTAL()"},
{"a) To combine rows from two or more tables\nb) To delete data from multiple tables\nc) To update data in a table\nd) To select records"}
};
string sqlBasicAnswers[10] = {"a", "a", "b", "a", "a", "c", "a", "a", "a", "a"};
string sqlBasicExplanations[10][1] = {
{"SQL stands for Structured Query Language, which is used for managing and manipulating databases."},
{"`SELECT * FROM table;` is a valid SQL statement that retrieves all records from the specified table."},
{"The purpose of the `SELECT` statement is to retrieve data from a database."},
{"The `WHERE` clause is used to filter records based on specified conditions."},
{"The default sorting order of the `ORDER BY` clause is ascending."},
{"The `WHERE` clause filters records based on a specified condition, allowing more control over the results."},
{"The `UPDATE` statement is used to modify existing records in a table."},
{"A primary key is a unique identifier for each record in a table, ensuring that no two records have the same value."},
{"The `COUNT()` function counts the number of rows in a result set."},
{"The `JOIN` clause combines rows from two or more tables based on a related column."}
};
string userAnswers[10];
int userScore[10] = {0};
for(int i = 0; i < 10; i++) {
cout << i + 1 << ". " << sqlBasicQuestions[i][0] << endl;
cout << sqlBasicOptions[i][0] << endl;
cout << "Answer: ";
cin >> userAnswers[i];
// Convert user answer to lowercase
for (char &c : userAnswers[i]) {
c = tolower(c);
}
// Check the answer and provide feedback
if (userAnswers[i] == sqlBasicAnswers[i]) {
userScore[i] = 1;
cout << "Correct answer..." << endl;
} else {
userScore[i] = 0;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << sqlBasicAnswers[i] << "." << endl;
cout << "Explanation: " << sqlBasicExplanations[i][0] << endl;
}
cout << endl; // Print a newline for better readability
}
// Optionally, print the total score
int totalScore = 0;
for (int score : userScore) {
totalScore += score;
}
cout << "Your total score is: " << totalScore << " out of 10." << endl;
}
void sqlIntermediateQuiz() {
string sqlIntermediateQuestions[10][1] = {
{"What is a foreign key?"},
{"What is the purpose of the `GROUP BY` clause?"},
{"How do you remove duplicate records in SQL?"},
{"What is the output of the following SQL query: SELECT COUNT(*) FROM users;?"},
{"What is an aggregate function?"},
{"What does `HAVING` do in SQL?"},
{"What is the difference between `INNER JOIN` and `OUTER JOIN`?"},
{"What SQL statement is used to create a new table?"},
{"How do you change a column's data type in SQL?"},
{"What is normalization in databases?"}
};
string sqlIntermediateOptions[10][1] = {
{"a) A key that refers to another table's primary key\nb) A unique identifier\nc) A key that can have null values\nd) None of the above"},
{"a) To sort records\nb) To group records with similar values\nc) To filter records\nd) To join tables"},
{"a) Using the DISTINCT keyword\nb) Using the UNIQUE keyword\nc) Using the GROUP BY clause\nd) None of the above"},
{"a) Returns the total number of users\nb) Returns the first user\nc) Returns an error\nd) Returns all user records"},
{"a) A function that operates on multiple rows\nb) A function that returns a single value\nc) Both a and b\nd) None of the above"},
{"a) To filter groups based on a condition\nb) To sort records\nc) To join tables\nd) None of the above"},
{"a) `INNER JOIN` returns only matching rows, `OUTER JOIN` returns all rows\nb) `INNER JOIN` returns all rows, `OUTER JOIN` returns only matching rows\nc) Both are the same\nd) None of the above"},
{"a) CREATE TABLE statement\nb) ALTER TABLE statement\nc) DROP TABLE statement\nd) INSERT INTO statement"},
{"a) Using ALTER TABLE command\nb) Using UPDATE command\nc) Using CREATE TABLE command\nd) None of the above"},
{"a) The process of organizing data to reduce redundancy\nb) The process of duplicating data\nc) The process of removing data\nd) None of the above"}
};
string sqlIntermediateAnswers[10] = {"a", "b", "a", "a", "c", "a", "a", "a", "a", "a"};
string sqlIntermediateExplanations[10][1] = {
{"A foreign key is a field in a table that uniquely identifies a row of another table, establishing a relationship between the two."},
{"The `GROUP BY` clause groups rows that have the same values in specified columns, allowing aggregate functions to be applied to each group."},
{"To remove duplicate records in SQL, the `DISTINCT` keyword is used in the `SELECT` statement."},
{"The output of `SELECT COUNT(*) FROM users;` returns the total number of records in the `users` table."},
{"An aggregate function performs a calculation on a set of values and returns a single value, such as `SUM()`, `AVG()`, or `COUNT()`."},
{"The `HAVING` clause filters records after aggregation, allowing conditions to be applied to groups."},
{"`INNER JOIN` returns only rows that have matching values in both tables, while `OUTER JOIN` returns all rows from one table and matched rows from the other."},
{"The SQL statement used to create a new table is `CREATE TABLE`."},
{"To change a column's data type, you can use the `ALTER TABLE` command with `ALTER COLUMN`."},
{"Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity."}
};
string userAnswers[10];
int userScore[10] = {0};
for(int i = 0; i < 10; i++) {
cout << i + 1 << ". " << sqlIntermediateQuestions[i][0] << endl;
cout << sqlIntermediateOptions[i][0] << endl;
cout << "Answer: ";
cin >> userAnswers[i];
// Convert user answer to lowercase
for (char &c : userAnswers[i]) {
c = tolower(c);
}
// Check the answer and provide feedback
if (userAnswers[i] == sqlIntermediateAnswers[i]) {
userScore[i] = 1;
cout << "Correct answer..." << endl;
} else {
userScore[i] = 0;
cout << "Wrong answer..." << endl;
cout << "The correct answer is " << sqlIntermediateAnswers[i] << "." << endl;
cout << "Explanation: " << sqlIntermediateExplanations[i][0] << endl;
}
cout << endl; // Print a newline for better readability
}
// Optionally, print the total score
int totalScore = 0;
for (int score : userScore) {
totalScore += score;
}
cout << "Your total score is: " << totalScore << " out of 10." << endl;
}
void sqlAdvancedQuiz() {
string sqlAdvancedQuestions[10][1] = {
{"What is a subquery?"},
{"What is the purpose of indexes in SQL?"},
{"What is a stored procedure?"},
{"What is a trigger?"},