Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

C++ quiz exam prep+ MCQs+ practice paper exam

Beoordeling
-
Verkocht
-
Pagina's
6
Geüpload op
29-06-2025
Geschreven in
2024/2025

This document contains a collection of easy-to-understand C++ programs, designed especially for beginners, college students, and BSCS first-year learners. Each program is written with clear syntax, step-by-step logic, and proper output display to help you build a strong foundation in C++.

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

Document 10: C++ Mid-Term Practice Paper.
This will be a full-length practice paper designed to help students prepare for a C++ mid-term
exam, covering a range of topics from basic syntax to OOP concepts. It will include questions
and their corresponding answers. I'll generate both DOCX and PDF versions, with an
anonymous author.

C++ Mid-Term Practice Paper
Instructions:
● Answer all questions.
● Show your work for programming questions where applicable.
● Time: Approximately 90 minutes (adjust as needed)
● Total Marks: 50

Section A: Conceptual Questions (20 Marks)
1. Fill in the Blanks (5 Marks)
a) A ________ is a block of code that performs a specific task and promotes code reusability. b)
In C++, default arguments must be placed from ________ to ________ in the function's
parameter list. c) Function ________ allows multiple functions to have the same name but
different parameter lists. d) An ________ is an instance of a class. e) A ________ is a special
member function automatically called when an object is destroyed.
2. True/False (5 Marks)
a) A function's return type is part of its signature for overloading. (True/False) b) If you define a
parameterized constructor, the compiler will still provide an implicit default constructor.
(True/False) c) private members of a class are accessible from derived classes. (True/False) d)
The dot operator (.) is used to access members of an object. (True/False) e) A destructor can
take arguments. (True/False)
3. Short Answer Questions (10 Marks)
a) Briefly explain the concept of encapsulation in Object-Oriented Programming (OOP). (2
Marks) b) What is the main difference between a function declaration and a function
definition? (2 Marks) c) When would you prefer to use protected access modifier over private?
(2 Marks) d) Explain why a constructor does not have a return type. (2 Marks) e) Describe one
scenario where default arguments would be a better choice than function overloading. (2
Marks)

Section B: Programming Questions (30 Marks)
4. C++ Functions (8 Marks)
Write a C++ program that defines a function isEven(int number) which takes an integer as input
and returns true if the number is even, and false otherwise. In main(), use this function to check
if numbers entered by the user are even or odd until the user enters 0.
5. Classes and Objects (10 Marks)
Design a C++ class named Circle with the following:
● A private data member radius (of type double).
● A public parameterized constructor that initializes the radius.
● A public member function calculateArea() that returns the area of the circle (\\pi \*
radius^2). (Use \\pi = 3.14159)
● A public member function displayRadius() that prints the current radius.
In your main() function: a) Create an object of Circle with a radius of 7.5. b) Call displayRadius()

, for this object. c) Call calculateArea() and print the calculated area.
6. Constructor & Destructor (12 Marks)
Create a C++ class named DynamicArray that dynamically allocates an integer array.
● It should have a private data member int* arr and int size.
● Implement a parameterized constructor that takes an integer s (for size), allocates
memory for s integers, and initializes them to their index value (i.e., arr[i] = i).
● Implement a destructor that properly deallocates the memory pointed to by arr. Print a
message inside the constructor and destructor indicating their execution (e.g.,
"Constructor: Array of size X created." and "Destructor: Array deallocated.").
● Add a public member function displayArray() to print the contents of the array.
In your main() function: a) Create a DynamicArray object arr1 of size 5. b) Call displayArray() for
arr1. c) Create another DynamicArray object arr2 of size 3 within a nested scope (e.g., inside
curly braces {}). d) Observe the order of constructor and destructor calls for arr1 and arr2.

Answer Key

Section A: Conceptual Questions (20 Marks)
1. Fill in the Blanks (5 Marks)
a) A function is a block of code that performs a specific task and promotes code reusability. b)
In C++, default arguments must be placed from right to left in the function's parameter list. c)
Function overloading allows multiple functions to have the same name but different parameter
lists. d) An object is an instance of a class. e) A destructor is a special member function
automatically called when an object is destroyed.
2. True/False (5 Marks)
a) A function's return type is part of its signature for overloading. (False) b) If you define a
parameterized constructor, the compiler will still provide an implicit default constructor. (False)
c) private members of a class are accessible from derived classes. (False) d) The dot operator
(.) is used to access members of an object. (True) e) A destructor can take arguments. (False)
3. Short Answer Questions (10 Marks)
a) Encapsulation in OOP is the bundling of data (attributes) and the methods (functions) that
operate on that data into a single unit, which is typically a class. It also involves restricting direct
access to some of an object's components, meaning that internal representation of an object is
hidden from the outside world. This promotes data hiding and protects data integrity.
b) A function declaration (prototype) tells the compiler about the function's name, return type,
and parameters. It announces that a function with a certain signature exists, allowing the
compiler to check for correct usage. A function definition contains the actual code (body) of the
function that performs the task.
c) You would prefer to use protected over private when you want a class's members to be
accessible to its derived (child) classes while still keeping them inaccessible to the outside
world. private members are completely hidden from derived classes, whereas protected
members allow a controlled form of inheritance for internal implementation details.
d) A constructor does not have a return type (not even void) because its primary job is to
initialize the object itself, not to compute and return a value. The object's creation and
initialization are the "return value" implicitly. The compiler knows what a constructor does and
expects no explicit return.
e) Default arguments would be a better choice than function overloading when you have a
function that performs essentially the same operation but some parameters have common,
frequently used values. Instead of writing multiple overloaded functions for each combination,
you can provide default values for those optional parameters in a single function definition,

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
29 juni 2025
Aantal pagina's
6
Geschreven in
2024/2025
Type
College aantekeningen
Docent(en)
Fawad gillani
Bevat
Alle colleges

Onderwerpen

$10.99
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
fatimamaqbool77

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
fatimamaqbool77 ncba&e
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
11 maanden
Aantal volgers
0
Documenten
14
Laatst verkocht
-
study by fatima

Welcome to my store! I upload original, easy-to-understand notes designed for school and university students. My content covers a range of subjects including English Grammar, Functional English, Logic and Critical Thinking, Computer Science, and General Studies. All documents are written in simple language, with examples, definitions, and formatting that help you study faster and perform better in exams. Whether you’re preparing for tests or just want clear notes to understand your subject, you’ll find something helpful here.

Lees meer Lees minder
0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen