File size: 68,407 Bytes
09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 9160cd4 09c5912 |
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OOP with C++ Exam Guide - Complete Answers</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#3b82f6',
secondary: '#1e40af',
accent: '#0ea5e9',
light: '#f0f9ff',
dark: '#0c4a6e'
}
}
}
}
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
background-attachment: fixed;
}
.unit-card {
transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}
.unit-card:hover {
transform: translateY(-5px);
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}
.choice-chip {
cursor: pointer;
transition: all 0.2s ease;
}
.choice-chip:hover {
transform: scale(1.05);
}
.question-card {
overflow: hidden;
transition: all 0.3s ease;
}
.highlighted {
background: linear-gradient(90deg, #dbeafe 0%, transparent 100%);
border-left: 4px solid #3b82f6;
}
.exam-tip {
animation: pulse 2s infinite;
}
@keyframes pulse {
0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
}
mark {
background-color: #fef3c7;
padding: 0 2px;
}
pre {
font-size: 0.9rem !important;
line-height: 1.5;
}
.answer {
border-left: 4px solid #3b82f6;
background-color: #f8fafc;
padding: 1rem;
margin-top: 1rem;
border-radius: 0 0.5rem 0.5rem 0;
}
.answer-title {
font-weight: 600;
color: #1e40af;
margin-bottom: 0.5rem;
}
</style>
</head>
<body>
<!-- Header -->
<header class="bg-secondary text-white py-8 shadow-xl">
<div class="container mx-auto px-4">
<div class="flex flex-col md:flex-row justify-between items-center gap-6">
<div>
<h1 class="text-3xl md:text-4xl font-bold flex items-center gap-3">
<i class="fas fa-laptop-code"></i>
OOP with C++ Exam Guide
</h1>
<p class="mt-2 text-blue-200">
Complete answers to all questions from the official question bank
</p>
</div>
<div class="inline-flex gap-2">
<button class="bg-accent hover:bg-blue-500 text-white px-4 py-2 rounded-full flex items-center">
<i class="fas fa-book mr-2"></i> Study Guide
</button>
<button onclick="window.print()" class="bg-primary hover:bg-blue-600 text-white px-4 py-2 rounded-full flex items-center">
<i class="fas fa-print mr-2"></i> Print
</button>
</div>
</div>
</div>
</header>
<!-- Exam Tips -->
<section class="py-6 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-blue-100">
<div class="container mx-auto px-4">
<div class="exam-tip bg-white rounded-xl p-4 shadow-md flex items-start">
<div class="bg-accent text-white rounded-full p-3 mr-4">
<i class="fas fa-lightbulb text-lg"></i>
</div>
<div>
<h3 class="font-bold text-lg text-secondary mb-1">Quick Tips for Your Exam</h3>
<ul class="list-disc pl-5 space-y-1 text-gray-700">
<li>Write neatly, <strong>underline keywords</strong>: <mark>private</mark>, <mark>friend</mark>, <mark>inline</mark>, <mark>::</mark></li>
<li><strong>Draw tables</strong> for comparisons (OOP vs POP, access specifiers)</li>
<li>Write small code snippets — even 4 lines with comments can get full marks</li>
<li>Spend ~1 minute per 2 marks — don't over-write answers</li>
<li>If you're unsure, write something — definition, syntax, or an example</li>
</ul>
</div>
</div>
</div>
</section>
<main class="container mx-auto px-4 py-8">
<!-- Unit Navigation -->
<section class="mb-12">
<h2 class="text-2xl font-bold text-center text-secondary mb-8">Exam Units</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
<div class="unit-card bg-gradient-to-br from-blue-100 to-blue-200 border border-blue-300 rounded-2xl p-6 text-center shadow-md">
<h3 class="text-xl font-bold text-secondary flex justify-center items-center">
<i class="fas fa-cube mr-2 text-accent"></i>
UNIT-1
</h3>
<p class="text-gray-700 font-medium mt-2">Principles Of OOP</p>
<div class="bg-primary/10 text-xs inline-block px-3 py-1 rounded-full mt-3 text-primary font-medium">
12 Questions
</div>
</div>
<div class="unit-card bg-gradient-to-br from-indigo-100 to-indigo-200 border border-indigo-300 rounded-2xl p-6 text-center shadow-md">
<h3 class="text-xl font-bold text-secondary flex justify-center items-center">
<i class="fas fa-cogs mr-2 text-indigo-500"></i>
UNIT-2
</h3>
<p class="text-gray-700 font-medium mt-2">Function, Class & Objects</p>
<div class="bg-indigo-500/10 text-xs inline-block px-3 py-1 rounded-full mt-3 text-indigo-700 font-medium">
9 Questions
</div>
</div>
<div class="unit-card bg-gradient-to-br from-cyan-100 to-cyan-200 border border-cyan-300 rounded-2xl p-6 text-center shadow-md">
<h3 class="text-xl font-bold text-secondary flex justify-center items-center">
<i class="fas fa-hat-wizard mr-2 text-cyan-500"></i>
UNIT-3
</h3>
<p class="text-gray-700 font-medium mt-2">Constructor & Destructor</p>
<div class="bg-cyan-500/10 text-xs inline-block px-3 py-1 rounded-full mt-3 text-cyan-700 font-medium">
6 Questions
</div>
</div>
</div>
</section>
<!-- Comparison Tables -->
<section class="mb-12">
<h2 class="text-2xl font-bold text-secondary mb-6 flex items-center gap-2">
<i class="fas fa-table text-accent"></i> Important Comparison Tables
</h2>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<!-- OOP vs POP Table -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<div class="bg-primary text-white py-3 px-4">
<h3 class="font-bold text-lg flex items-center gap-2">
<i class="fas fa-object-group"></i> OOP vs POP Comparison
</h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full">
<thead class="bg-blue-50">
<tr>
<th class="py-3 px-4 text-left">Feature</th>
<th class="py-3 px-4 text-left">OOP</th>
<th class="py-3 px-4 text-left">POP</th>
</tr>
</thead>
<tbody>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Approach</td>
<td class="py-3 px-4"><mark>Bottom-up approach</mark></td>
<td class="py-3 px-4">Top-down approach</td>
</tr>
<tr class="border-b bg-blue-50">
<td class="py-3 px-4 font-medium">Program Structure</td>
<td class="py-3 px-4"><mark>Objects and interactions</mark></td>
<td class="py-3 px-4">Functions that interact</td>
</tr>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Inheritance</td>
<td class="py-3 px-4"><mark>Supported</mark></td>
<td class="py-3 px-4">Not supported</td>
</tr>
<tr class="border-b bg-blue-50">
<td class="py-3 px-4 font-medium">Access Control</td>
<td class="py-3 px-4"><mark>Supported via access modifiers</mark></td>
<td class="py-3 px-4">Not supported</td>
</tr>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Encapsulation</td>
<td class="py-3 px-4"><mark>Used to hide data</mark></td>
<td class="py-3 px-4">No data hiding; data is globally accessible</td>
</tr>
<tr class="border-b bg-blue-50">
<td class="py-3 px-4 font-medium">Security</td>
<td class="py-3 px-4"><mark>Secure</mark></td>
<td class="py-3 px-4">Not secure</td>
</tr>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Examples</td>
<td class="py-3 px-4">C++, Java, Python</td>
<td class="py-3 px-4">C, BASIC, FORTRAN</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Access Specifiers Table -->
<div class="bg-white rounded-xl shadow-lg overflow-hidden">
<div class="bg-indigo-500 text-white py-3 px-4">
<h3 class="font-bold text-lg flex items-center gap-2">
<i class="fas fa-lock"></i> Access Specifiers Comparison
</h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full">
<thead class="bg-indigo-50">
<tr>
<th class="py-3 px-4 text-left"></th>
<th class="py-3 px-4 text-left">public</th>
<th class="py-3 px-4 text-left">private</th>
<th class="py-3 px-4 text-left">protected</th>
</tr>
</thead>
<tbody>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Access in same class</td>
<td class="py-3 px-4">✅</td>
<td class="py-3 px-4">✅</td>
<td class="py-3 px-4">✅</td>
</tr>
<tr class="border-b bg-indigo-50">
<td class="py-3 px-4 font-medium">Access in derived class</td>
<td class="py-3 px-4">✅</td>
<td class="py-3 px-4"><mark>❌</mark></td>
<td class="py-3 px-4">✅</td>
</tr>
<tr class="border-b">
<td class="py-3 px-4 font-medium">Access from objects</td>
<td class="py-3 px-4">✅</td>
<td class="py-3 px-4"><mark>❌</mark></td>
<td class="py-3 px-4"><mark>❌</mark></td>
</tr>
<tr class="border-b bg-indigo-50">
<td class="py-3 px-4 font-medium">Default specifier</td>
<td class="py-3 px-4">Classes: ❌<br>Structs: ✅</td>
<td class="py-3 px-4">Classes: ✅</td>
<td class="py-3 px-4">❌</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</section>
<!-- Unit 1 Content -->
<section id="unit-1" class="mb-12">
<div class="flex items-center gap-3 mb-6">
<div class="w-2 h-10 bg-primary rounded-lg"></div>
<h2 class="text-2xl font-bold text-secondary flex items-center gap-2">
<i class="fas fa-cube text-accent"></i> UNIT-1: Principles Of OOP
</h2>
</div>
<!-- Question 1 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q1.</span>
<span class="text-gray-800 font-medium">Define OOP.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">2 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>OOP stands for Object-Oriented Programming. It is a programming paradigm based on the concept of "objects", which are instances of classes. OOP emphasizes on objects rather than functions and makes the code flexible and modular. C++ is an object-oriented programming language that allows programmers to define their own data types and functions, called classes and objects respectively.</p>
</div>
</div>
<!-- Question 2 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q2.</span>
<span class="text-gray-800 font-medium">List applications of OOP.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">2 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>Applications of OOP include:</p>
<ul class="list-disc pl-5 mt-2">
<li>Real-Time System design</li>
<li>Hypertext and Hypermedia</li>
<li>AI Expert System</li>
<li>Office automation System</li>
<li>Neural networking and parallel programming</li>
<li>Stimulation and modeling system</li>
<li>CIM/CAD/CAM systems</li>
</ul>
</div>
</div>
<!-- Question 3 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q3.</span>
<span class="text-gray-800 font-medium">List advantages & disadvantages of OOP.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>Advantages:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Code can be reused multiple times using classes</li>
<li>Inherit classes to subclasses for data redundancy</li>
<li>Easy to maintain and modify</li>
<li>Maintains data security</li>
<li>Low-cost development</li>
</ul>
<p class="mt-3"><strong>Disadvantages:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Size is larger than other programs</li>
<li>Slower than other programs</li>
<li>Not suitable for some sorts of problems</li>
</ul>
</div>
</div>
<!-- Question 4 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q4.</span>
<span class="text-gray-800 font-medium">Differentiate OOP & POP.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>The main differences between OOP and POP are:</p>
<table class="min-w-full mt-3 border border-gray-300">
<thead class="bg-gray-100">
<tr>
<th class="py-2 px-3 border-b">Feature</th>
<th class="py-2 px-3 border-b">OOP</th>
<th class="py-2 px-3 border-b">POP</th>
</tr>
</thead>
<tbody>
<tr>
<td class="py-2 px-3 border-b">Approach</td>
<td class="py-2 px-3">Bottom-up approach</td>
<td class="py-2 px-3">Top-down approach</td>
</tr>
<tr>
<td class="py-2 px-3 border-b">Program Structure</td>
<td class="py-2 px-3">Program divided into objects and their interactions</td>
<td class="py-2 px-3">Program divided into functions that interact</td>
</tr>
<tr>
<td class="py-2 px-3 border-b">Inheritance</td>
<td class="py-2 px-3">Supported</td>
<td class="py-2 px-3">Not supported</td>
</tr>
<tr>
<td class="py-2 px-3 border-b">Access Control</td>
<td class="py-2 px-3">Supported via access modifiers</td>
<td class="py-2 px-3">Not supported</td>
</tr>
<tr>
<td class="py-2 px-3 border-b">Examples</td>
<td class="py-2 px-3">C++, Java, Python</td>
<td class="py-2 px-3">C, BASIC, FORTRAN</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Question 5 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q5.</span>
<span class="text-gray-800 font-medium">Explain the basic concepts of C++.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>The basic concepts of C++ are:</p>
<ol class="list-decimal pl-5 mt-2">
<li><strong>Object:</strong> Any entity that has state and behavior. In C++, an object is an instance of a class.</li>
<li><strong>Class:</strong> A user-defined data type that encapsulates data and functions into a single entity.</li>
<li><strong>Data Encapsulation:</strong> Binding code and data together into a single unit, providing data security.</li>
<li><strong>Data Abstraction:</strong> Hiding internal details and showing only functionality.</li>
<li><strong>Inheritance:</strong> When one object acquires all properties and behaviors of a parent object, providing code reusability.</li>
<li><strong>Polymorphism:</strong> One task performed in different ways (function overloading or operator overloading).</li>
<li><strong>Dynamic binding:</strong> Decision made at runtime regarding which code to run (late binding).</li>
<li><strong>Message passing:</strong> Objects communicate with each other by sending and receiving information through member functions.</li>
</ol>
</div>
</div>
<!-- Question 6 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q6.</span>
<span class="text-gray-800 font-medium">Explain the structure of C++ with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>The structure of a C++ program consists of the following sections:</p>
<ol class="list-decimal pl-5 mt-2">
<li><strong>Documentation Section:</strong> Contains comments about the program logic (optional).</li>
<li><strong>Link Section:</strong> Contains header files (#include) and namespaces (using namespace std;).</li>
<li><strong>Definition Section:</strong> Used to declare constants and define user-defined data types.</li>
<li><strong>Global Declaration Section:</strong> Variables and class definitions declared as global.</li>
<li><strong>Function Definition Section:</strong> Contains user-defined functions.</li>
<li><strong>Main Function:</strong> Starting point of program execution.</li>
</ol>
<p class="mt-3"><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
int main(){
cout<<"Hello World!";
return 0;
}
// Output: Hello World!</pre>
</div>
</div>
<!-- Question 7 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q7.</span>
<span class="text-gray-800 font-medium">List & explain user-defined data types & derived data types with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>User-Defined Data Types:</strong></p>
<ol class="list-decimal pl-5 mt-2">
<li><strong>Structure:</strong> Collection of logically related data items of different data types grouped together. Example: <code>struct Student { int id; char name[20]; };</code></li>
<li><strong>Class:</strong> Template that specifies fields and methods of objects. Example: <code>class Student { int id; string name; };</code></li>
<li><strong>Union:</strong> Like a structure, but elements share common memory.</li>
<li><strong>Enumeration:</strong> User-defined type with named constants. Example: <code>enum day {mon, tue, wed};</code></li>
</ol>
<p class="mt-3"><strong>Derived Data Types:</strong></p>
<ol class="list-decimal pl-5 mt-2">
<li><strong>Arrays:</strong> Fixed-size collection of elements of same type.</li>
<li><strong>Functions:</strong> Group of statements combined for a specific purpose.</li>
<li><strong>Pointers:</strong> Special variable containing address of another variable.</li>
</ol>
</div>
</div>
<!-- Question 8 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q8.</span>
<span class="text-gray-800 font-medium">Define variable.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">2 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A variable is a name of a memory location used to store data. Its value can be changed and it can be reused many times. It is a way to represent memory location through a symbol so that it can be easily identified.</p>
<p class="mt-2"><strong>Syntax:</strong> <code>datatype variable_name;</code></p>
<p><strong>Example:</strong> <code>int a;</code></p>
</div>
</div>
<!-- Question 9 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q9.</span>
<span class="text-gray-800 font-medium">What is a reference variable in C++?</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A reference variable is an alias or second name for an existing variable. It refers to the address of another variable and represents the name of another variable, location, or value. Once initialized, the variable can be referred to using either the original name or the reference name.</p>
<p class="mt-2"><strong>Syntax:</strong> <code>data_type &reference_name = existing_variable;</code></p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
int main() {
int a = 10;
int &value = a;
cout << value; // Output: 10
return 0;
}</pre>
</div>
</div>
<!-- Question 10 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q10.</span>
<span class="text-gray-800 font-medium">Describe variable declaration & dynamic initialization in C++.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>Variable Declaration:</strong> Variables must be declared before use. It specifies the data type and name of the variable.</p>
<p class="mt-2"><strong>Syntax:</strong></p>
<ul class="list-disc pl-5">
<li>Single variable: <code>type variable_name;</code></li>
<li>Multiple variables: <code>type var1, var2, var3;</code></li>
</ul>
<p><strong>Examples:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li><code>int a = 50, b = 100;</code></li>
<li><code>float f = 50.8;</code></li>
<li><code>char c = 'Z';</code></li>
</ul>
<p class="mt-3"><strong>Dynamic Initialization:</strong> Initializing a variable at runtime during its declaration.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
int main() {
int a;
cout << "Enter Value of a: ";
cin >> a;
int cube = a * a * a; // Dynamically initialized
return 0;
}</pre>
</div>
</div>
<!-- Question 11 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q11.</span>
<span class="text-gray-800 font-medium">Explain Scope Resolution.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>The scope resolution operator (::) is used to reference global variables or member functions that are out of scope. It accesses hidden variables or functions in a program.</p>
<p class="mt-2"><strong>Uses:</strong></p>
<ul class="list-disc pl-5">
<li>Access global variables when a local variable has the same name</li>
<li>Define member functions outside of a class</li>
<li>Access static variables and functions of a class</li>
<li>Override functions in inheritance</li>
</ul>
<p class="mt-3"><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
int num = 50; // Global variable
int main() {
int num = 100; // Local variable
cout << "Local variable: " << num << endl;
cout << "Global variable: " << ::num; // Using scope resolution
return 0;
}
// Output: Local variable: 100
// Global variable: 50</pre>
</div>
</div>
<!-- Question 12 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q12.</span>
<span class="text-gray-800 font-medium">Explain access specifiers (public, private, protected).</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>In C++, access specifiers determine the accessibility of class members:</p>
<ol class="list-decimal pl-5 mt-2">
<li><strong>Public:</strong> Members can be accessed from anywhere, both inside and outside the class. Used to represent the interface of the class.</li>
<li><strong>Private:</strong> Members can only be accessed from within the class. Used to represent the implementation and hide data from the outside world.</li>
<li><strong>Protected:</strong> Members can be accessed from within the class and its derived classes. Used when implementation should be accessible to derived classes.</li>
</ol>
<p class="mt-3"><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
class MyClass {
public:
int x; // Accessible anywhere
private:
int y; // Only accessible within class
protected:
int z; // Accessible in class and derived classes
};
int main() {
MyClass myObj;
myObj.x = 25; // OK
myObj.y = 50; // Error: y is private
return 0;
}</pre>
</div>
</div>
</section>
<!-- Unit 2 Content -->
<section id="unit-2" class="mb-12">
<div class="flex items-center gap-3 mb-6">
<div class="w-2 h-10 bg-indigo-500 rounded-lg"></div>
<h2 class="text-2xl font-bold text-secondary flex items-center gap-2">
<i class="fas fa-cogs text-indigo-500"></i> UNIT-2: Function, Class & Objects
</h2>
</div>
<!-- Question 13 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q13.</span>
<span class="text-gray-800 font-medium">Define function with function prototype, function declaration & function calling.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A function is a block of code that performs a specific operation. It can take input parameters and optionally return a value.</p>
<p class="mt-3"><strong>Function Prototype:</strong> Provides the compiler with a description of a function before it's defined. It includes return type, function name, and parameter types.</p>
<p><strong>Example:</strong> <code>int sum(int, int);</code></p>
<p class="mt-3"><strong>Function Declaration:</strong> Tells the compiler about a function name and how to call it. The actual body can be defined separately.</p>
<p><strong>Syntax:</strong> <code>return_type function_name(parameter list);</code></p>
<p class="mt-3"><strong>Function Calling:</strong> Invoking a function by its name with appropriate arguments. Control is passed to the function, which executes and may return a value.</p>
<p><strong>Syntax:</strong> <code>variable = function_name(arg1, arg2, ..., argn);</code></p>
<p><strong>Example:</strong> <code>result = sum(num1, num2);</code></p>
</div>
</div>
<!-- Question 14 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q14.</span>
<span class="text-gray-800 font-medium">Define an inline function & explain how to implement with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>An inline function is a function that is expanded in line when called. The entire code of the inline function is inserted at the point of the function call during compilation, which can increase efficiency for small functions.</p>
<p class="mt-3"><strong>Syntax:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
inline return-type function-name(parameters)
{
// function code
}</pre>
<p class="mt-3"><strong>Implementation:</strong></p>
<p>If a function is defined entirely within the class specification (typically in the header file), it is automatically considered inline.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
inline int cube(int s) {
return s * s * s;
}
int main() {
cout << "The cube of 2 is: " << cube(2);
return 0;
}
// Output: The cube of 2 is: 8</pre>
</div>
</div>
<!-- Question 15 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q15.</span>
<span class="text-gray-800 font-medium">Explain default and constant arguments with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>Default Arguments:</strong> Values provided in a function declaration that are automatically assigned by the compiler if the calling function doesn't provide a value for that argument. If a value is passed, the default value is overridden.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
int sum(int x, int y, int z = 0, int w = 0) {
return (x + y + z + w);
}
int main() {
cout << sum(10, 20) << endl; // Output: 30
cout << sum(10, 20, 30) << endl; // Output: 60
cout << sum(10, 20, 30, 50) << endl; // Output: 110
return 0;
}</pre>
<p class="mt-3"><strong>Constant Arguments:</strong> Arguments that cannot be modified by the function. Useful when passing by reference to prevent accidental modification.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Test {
int value;
public:
Test(int v = 0) {
value = v;
}
int get() const { // const member function
return value;
}
};
int main() {
Test t(20);
cout << t.get();
return 0;
}
// Output: 20</pre>
</div>
</div>
<!-- Question 16 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q16.</span>
<span class="text-gray-800 font-medium">Explain Function Overloading with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>Function overloading is a feature where two or more functions have the same name but different parameters (different types or number of arguments). The compiler differentiates between overloaded functions based on their parameters.</p>
<p class="mt-2"><strong>Rules:</strong></p>
<ul class="list-disc pl-5">
<li>Function name must be the same</li>
<li>Parameters must be different (type or number)</li>
<li>Return type alone cannot differentiate functions</li>
</ul>
<p class="mt-3"><strong>Advantage:</strong> Increases code readability as you can use the same name for similar operations.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Cal {
public:
int add(int a, int b) {
return a + b;
}
int add(int a, int b, int c) {
return a + b + c;
}
};
int main() {
Cal c;
cout << c.add(10, 20) << endl; // Output: 30
cout << c.add(12, 20, 23) << endl; // Output: 55
return 0;
}</pre>
</div>
</div>
<!-- Question 17 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q17.</span>
<span class="text-gray-800 font-medium">Define class & object.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">2 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>Class:</strong> A class is a user-defined data type that acts as a blueprint for creating objects. It combines data representation and methods for manipulating that data into a single package. A class specifies the form of an object and can have fields, methods, constructors, etc.</p>
<p><strong>Syntax:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
class className
{
// data members and member functions
};</pre>
<p><strong>Object:</strong> An object is a single instance of a class. When a class is defined, only the specification is created; memory is allocated when an object is created. Objects can access the data and functions defined in the class.</p>
<p><strong>Syntax:</strong> <code>className objectVariableName;</code></p>
</div>
</div>
<!-- Question 18 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q18.</span>
<span class="text-gray-800 font-medium">What is an instance of a class?</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">2 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>An instance of a class is an object created from that class at runtime using one of the available constructors. It represents a specific realization of the class with its own set of attribute values and state.</p>
<p>When you create an instance of a class, you are creating a unique object that has its own data values and can perform the actions defined by the class's methods. Each instance is independent and can have different attribute values.</p>
<p><strong>Example:</strong> If "Car" is a class with attributes like color, model, and year, then "myCar" would be an instance of the Car class with specific values for these attributes.</p>
</div>
</div>
<!-- Question 19 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q19.</span>
<span class="text-gray-800 font-medium">Define Member Function & Nesting of Member Function.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p><strong>Member Function:</strong> A member function of a class is a function that has its definition or prototype within the class definition. It operates on objects of the class and has access to all members of the class for that object. Member functions are also known as methods and encapsulate the behaviors that objects of the class can perform.</p>
<p><strong>Nesting of Member Functions:</strong> When a member function calls another member function of the same class, it is referred to as nesting of member functions. This allows for modular code organization within a class.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Average {
int a, b;
public:
void read() {
cout << "Enter a and b: ";
cin >> a >> b;
}
void print() {
cout << "Value of a: " << a << endl;
cout << "Value of b: " << b << endl;
cout << "Average is: " << avg() << endl;
}
int avg() {
return (a + b) / 2;
}
};
int main() {
Average a;
a.read();
a.print();
return 0;
}</pre>
</div>
</div>
<!-- Question 20 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q20.</span>
<span class="text-gray-800 font-medium">Define Private Member Function.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A private member function is a function declared in the private section of a class. It can only be accessed and called from within the class itself, typically through public member functions.</p>
<p>Private member functions are used for internal operations or helper functions that should not be directly accessible from outside the class. They help encapsulate implementation details, hide complexity, and ensure proper data protection.</p>
<p><strong>Characteristics:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Accessible only within the class</li>
<li>Cannot be called from outside the class or by other objects</li>
<li>Used for internal processing and helper operations</li>
<li>Contributes to data security and encapsulation</li>
</ul>
</div>
</div>
<!-- Question 21 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q21.</span>
<span class="text-gray-800 font-medium">What is a Friend Function? Explain with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A friend function in C++ is a function that is not a member of a class but has access to the class's private and protected data members. It is declared inside the class with the <code>friend</code> keyword, but defined outside the class scope.</p>
<p><strong>Properties:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Not a member function of the class</li>
<li>Can access private and protected members of the class</li>
<li>Declared with <code>friend</code> keyword inside the class</li>
<li>Defined outside the class like a normal function</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Test {
private:
int a;
public:
friend void show(Test t);
};
void show(Test t) {
cout << "Enter a: ";
cin >> t.a;
cout << "Value of a: " << t.a;
}
int main() {
Test t1;
show(t1);
return 0;
}</pre>
</div>
</div>
</section>
<!-- Unit 3 Content -->
<section id="unit-3" class="mb-12">
<div class="flex items-center gap-3 mb-6">
<div class="w-2 h-10 bg-cyan-500 rounded-lg"></div>
<h2 class="text-2xl font-bold text-secondary flex items-center gap-2">
<i class="fas fa-hat-wizard text-cyan-500"></i> UNIT-3: Constructor & Destructor
</h2>
</div>
<!-- Question 22 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q22.</span>
<span class="text-gray-800 font-medium">What is a constructor? Explain in brief with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A constructor is a special member function in C++ that is automatically invoked when an object is created. It has the same name as the class and is used to initialize the data members of the object.</p>
<p><strong>Properties:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Same name as the class</li>
<li>No return type (not even void)</li>
<li>Automatically called when object is created</li>
<li>Can be overloaded</li>
<li>Cannot be inherited</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Person {
string name;
int age;
public:
Person() { // Default constructor
name = "Unknown";
age = 0;
cout << "Default constructor called." << endl;
}
void displayInfo() {
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
}
};
int main() {
Person person1; // Constructor called automatically
person1.displayInfo();
return 0;
}</pre>
</div>
</div>
<!-- Question 23 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q23.</span>
<span class="text-gray-800 font-medium">Explain default constructor with program.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A default constructor is a constructor that has no parameters. It is invoked automatically when an object is created without any arguments. If the programmer does not define a default constructor, the compiler provides an implicit default constructor.</p>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Employee {
public:
Employee() {
cout << "Default Constructor Invoked" << endl;
}
};
int main() {
Employee e1; // Calls default constructor
Employee e2; // Calls default constructor
return 0;
}
// Output:
// Default Constructor Invoked
// Default Constructor Invoked</pre>
</div>
</div>
<!-- Question 24 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q24.</span>
<span class="text-gray-800 font-medium">How to test a copy constructor? Justify with program.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A copy constructor initializes an object using another object of the same class. It is used to:</p>
<ul class="list-disc pl-5 mt-2">
<li>Initialize one object from another of the same type</li>
<li>Copy an object to pass it as an argument to a function</li>
<li>Copy an object to return it from a function</li>
</ul>
<p>If not defined, the compiler provides a default copy constructor. However, for classes with pointer variables or dynamic memory, a user-defined copy constructor is necessary.</p>
<p><strong>Testing Copy Constructor:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class A {
public:
int x;
A(int a) { // Parameterized constructor
x = a;
}
A(A& i) { // Copy constructor
x = i.x;
}
};
int main() {
A a1(20); // Calls parameterized constructor
A a2(a1); // Calls copy constructor
cout << a2.x; // Output: 20
return 0;
}</pre>
</div>
</div>
<!-- Question 25 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q25.</span>
<span class="text-gray-800 font-medium">Explain parameterized constructor with example.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">4 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>A parameterized constructor is a constructor that accepts parameters. It is used to initialize objects with specific values provided during object creation, allowing for flexible and customized object initialization.</p>
<p><strong>Key Points:</strong></p>
<ul class="list-disc pl-5 mt-2">
<li>Has parameters in its declaration</li>
<li>Allows initialization with specific values</li>
<li>Provides flexibility in object creation</li>
<li>Can be overloaded with different parameter sets</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Employee {
public:
int id;
string name;
float salary;
Employee(int i, string n, float s) {
id = i;
name = n;
salary = s;
}
void display() {
cout << id << " " << name << " " << salary << endl;
}
};
int main() {
Employee e1(101, "Sonoo", 890000);
Employee e2(102, "Nakul", 59000);
e1.display();
e2.display();
return 0;
}
// Output:
// 101 Sonoo 890000
// 102 Nakul 59000</pre>
</div>
</div>
<!-- Question 26 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q26.</span>
<span class="text-gray-800 font-medium">Explain Characteristics of Constructor.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<p>The characteristics of constructors are:</p>
<ol class="list-decimal pl-5 mt-2">
<li>The name of the constructor is the same as its class name.</li>
<li>Constructors are mostly declared in the public section of the class (though they can be in private).</li>
<li>Constructors do not return values; hence they do not have a return type.</li>
<li>A constructor gets called automatically when we create an object of the class.</li>
<li>Constructors can be overloaded (multiple constructors with different parameters).</li>
<li>Constructor cannot be declared virtual.</li>
<li>Constructor cannot be inherited by derived classes.</li>
<li>Addresses of constructors cannot be referred (no pointer to constructor).</li>
<li>Constructors make implicit calls to new and delete operators during memory allocation.</li>
</ol>
</div>
</div>
<!-- Question 27 -->
<div class="question-card bg-white rounded-lg shadow-md p-5 mb-4">
<div class="flex flex-wrap gap-3 items-start justify-between">
<div>
<span class="font-bold text-secondary text-lg">Q27.</span>
<span class="text-gray-800 font-medium">Write a C++ program to enter student details by passing parameters to constructors.</span>
<span class="text-sm bg-blue-100 text-primary px-2 py-0.5 rounded-full">3 MARKS</span>
</div>
</div>
<div class="answer">
<div class="answer-title">Answer:</div>
<pre class="bg-gray-800 text-green-300 p-4 rounded-lg text-sm overflow-x-auto">
#include<iostream>
using namespace std;
class Student {
public:
int id;
string name;
float salary;
// Parameterized constructor
Student(int i, string n, float s) {
id = i;
name = n;
salary = s;
}
void display() {
cout << "ID: " << id << ", Name: " << name << ", Salary: " << salary << endl;
}
};
int main() {
// Creating objects with parameters passed to constructor
Student e1(101, "Sonoo", 890000);
Student e2(102, "Nakul", 59000);
e1.display();
e2.display();
return 0;
}
// Output:
// ID: 101, Name: Sonoo, Salary: 890000
// ID: 102, Name: Nakul, Salary: 59000</pre>
</div>
</div>
</section>
<!-- Key Concepts Review -->
<section class="mb-12 bg-gradient-to-br from-blue-50 to-white p-6 rounded-xl shadow-lg border border-blue-100">
<h2 class="text-2xl font-bold text-secondary mb-6">Key Concepts Cheatsheet</h2>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4">
<div class="bg-white rounded-lg p-4 border border-blue-200 shadow-sm flex flex-col items-center text-center">
<div class="bg-blue-100 p-3 rounded-full mb-3">
<i class="fas fa-box-open text-blue-600 text-xl"></i>
</div>
<h3 class="font-bold text-secondary">Encapsulation</h3>
<p class="text-sm text-gray-600 mt-1">Bundling data with methods operating on that data</p>
</div>
<div class="bg-white rounded-lg p-4 border border-indigo-200 shadow-sm flex flex-col items-center text-center">
<div class="bg-indigo-100 p-3 rounded-full mb-3">
<i class="fas fa-sitemap text-indigo-600 text-xl"></i>
</div>
<h3 class="font-bold text-secondary">Inheritance</h3>
<p class="text-sm text-gray-600 mt-1">Creating hierarchical relationships between classes</p>
</div>
<div class="bg-white rounded-lg p-4 border border-purple-200 shadow-sm flex flex-col items-center text-center">
<div class="bg-purple-100 p-3 rounded-full mb-3">
<i class="fas fa-bolt text-purple-600 text-xl"></i>
</div>
<h3 class="font-bold text-secondary">Polymorphism</h3>
<p class="text-sm text-gray-600 mt-1">Same methods performing different actions</p>
</div>
<div class="bg-white rounded-lg p-4 border border-cyan-200 shadow-sm flex flex-col items-center text-center">
<div class="bg-cyan-100 p-3 rounded-full mb-3">
<i class="fas fa-puzzle-piece text-cyan-600 text-xl"></i>
</div>
<h3 class="font-bold text-secondary">Abstraction</h3>
<p class="text-sm text-gray-600 mt-1">Hiding complex details, showing only essentials</p>
</div>
</div>
</section>
</main>
<!-- Footer -->
<footer class="bg-secondary text-blue-100 py-8">
<div class="container mx-auto px-4">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="mb-4 md:mb-0">
<h3 class="text-xl font-bold text-white">OOP with C++ Exam Guide</h3>
<p class="mt-1">Complete answers to all questions from the official question bank</p>
</div>
<div class="flex space-x-4">
<button onclick="window.print()" class="bg-blue-600 hover:bg-blue-700 text-white py-2 px-4 rounded-lg flex items-center">
<i class="fas fa-print mr-2"></i> Print Summary
</button>
<button class="bg-cyan-500 hover:bg-cyan-600 text-white py-2 px-4 rounded-lg flex items-center">
<i class="fas fa-book-open mr-2"></i> Revise Key Points
</button>
</div>
</div>
<div class="mt-8 pt-8 border-t border-blue-800 text-center text-sm text-blue-200">
<p>This comprehensive study guide covers all questions from the official C++ question bank for diploma students in computer engineering.</p>
<p class="mt-2">Important keywords to remember: <mark>private</mark>, <mark>friend</mark>, <mark>inline</mark>, <mark>::</mark>, <mark>using</mark>, <mark>namespace</mark>, <mark>class</mark>, <mark>object</mark>, <mark>constructor</mark>, <mark>destructor</mark></p>
</div>
</div>
</footer>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Add smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});
</script>
</body>
</html> |