Practice Questions C++

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

1. Write a C++ program to find the sum of individual digits of a positive integer.

2. Write a C++ program to generate the first ‘n’ terms of the sequence. A Fibonacci sequence is
defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent terms are
formed by adding the preceding two terms in the sequence.

3. Write a C++ program to generate all the prime numbers between 1 and n. Where ‘n’ is a value
supplied by the user.

4. Write a C++ programs that use both recursive and non-recursive functions a) To find the factorial
of a given integer. b) To find the GCD of two given integers. c) To find the nth Fibonacci number.

5. Write a C++ program to perform addition, suCSraction and multiplication operations on two
complex numbers using classes and objects.

6. Write a C++ program to find out the total and average marks of 10 students using Classes and
objects?

7. Write a C++ program to implement static data members and static member functions

8. Write a C++ program to implement the matrix ADT using a class. The operations Supported by this
ADT are: a) Reading a matrix. c) Addition of matrices. b) Displaying a matrix d) Multiplication of
matrices.

9. Write a C++ program to illustrate the usage of following: Default Constructor, Parameterized
Constructor, Copy Constructor and Destructor

10. Write a C++ program that illustrates the following: a) Friend Function b) inline function

11. Write C++ programs that illustrates the usage of following forms of inheritance. (Exercise the
access specifier protected also) a) Single Inheritance b) Multiple Inheritance c) Multi level
Inheritance d) Hierarchical Inheritance

12. Write a C++ program to call base class constructors in the following forms of inheritance. a)
Single Inheritance b) Multiple Inheritance c) Multi level Inheritance d) Hierarchical Inheritance.

13. Write a C++ program that illustrates the concept of Function over loading?

14. C++ Program to convert a decimal number into binary with friend function

15. Write a C++ Program to display the reverse of a number using the Friend function.
16. Write a program to print the names of students by creating a Student class. If no name is passed while
creating an object of the Student class, then the name should be "Unknown", otherwise the name should be
equal to the String value passed while creating the object of the Student class.

17.

/***********************for MST-2 Preparation ********************************/

14. Write a C++ program that overloads the binary + operator to concatenate two strings and to add
two complex numbers.

15. Write a C++ program that overloads the unary ++ operator to increment each element of the
given one dimensional array by ‘1’?
16. Write a C++ program that illustrates run time polymorphism by using virtual functions.

17. Write a template based C++ program to check whether the given item is existed in the array or
not.

18. Write an example C++ program to illustrate the procedure of exceptions handling.

19. Write a C++ program to display the contents of a text file.

20. Write a C++ program which copies the contents of one file to another.

21.Describe virtual destructors. Why can’t we have virtual constructor ?

22. ) Explain early binding & late binding in detail.

23. Write a C++ program to overload unary increment and decrement operator.
24. Write a short note on
i) Polymorphism.
ii) Abstract Classes
25. Whether Inheritance uses the concept of reusability if yes how? Also explain the
need of virtual Function.
26. Write a C++ program by using pure virtual function to convert grams to kilograms
& liters into milliliters.

27. Make a class named Fruit with a data member to calculate the number of fruits in a
basket. Create two other class named Apples and Mangoes to calculate the number of apples
and mangoes in the basket. Print the number of fruits of each type and the total number of
fruits in the basket.

28. What is template class? Write a template class to find sum of elements of an array.
29. Explain the role of seekg(), seekp(), tellg(), tellp(),function in the process of random
access in a binary file.

30. When do we make a virtual function pure? What are the implications of making a
function a pure virtual function? Explain.

31. What is operator overloading? What are the methods of overloading the operators in C+
+? Explain.

32. What is significance of virtual destructor? Explain with suitable example.


33. What is exception handling? Write a c++ program that illustrates exception handling with
help of : try, throw and catch.

34. How can you create and access in file in C++? Explain with a program.

You might also like