Page 21 - Data Structures Interactive Book
P. 21
1.6 Exercise
Essay Questions
1. Write a program that declares variables of different data types and prints their values.
2. Create a class Book with attributes title and author, and a method to display them.
3. Write a program that uses a loop to print numbers from 1 to 10.
4. Implement a program that writes student data into a file and then reads it back.
5. Demonstrate the use of pointers by printing the value of a variable using its address.
6. Write a program that dynamically allocates memory for an array of integers, stores values,
and then releases the memory.
Multiple Choice Questions (MCQ)
Q1. Which of the following is NOT a primitive data type in C++?
a) int b) float c) string d) char
Q2. What is the main difference between an Abstract Data Type (ADT) and a Data Structure?
a) ADT is a mathematical model, Data Structure is its implementation
b) ADT is faster than Data Structure
c) ADT uses more memory than Data Structure
d) ADT is only used in databases
Q3. Which of the following correctly declares a pointer to an integer in C++?
a) int p; b) int *p; c) int &p; d) pointer int p;
Q4. Which operator is used in C++ to dynamically allocate memory?
a) malloc b) new c) alloc d) create
Q5. In Object-Oriented Programming, which concept allows a class to inherit attributes and
methods from another class?
a) Encapsulation b) Polymorphism c) Inheritance d) Abstraction
Q6. Which of the following statements about file handling in C++ is TRUE?
a) Files can only be opened in read mode.
b) Files must always be opened using fstream.
c) Files can be opened in read, write, or append modes.
d) Files cannot store structured data.
21

