0% found this document useful (0 votes)
489 views52 pages

C++ Questions

The document discusses different types of loops in C++ including for loops, nested for loops, while loops, and do-while loops. It provides examples of problems that can be solved using each type of loop. For loops repeat a block of code until a condition is false, and have initialization, condition, and increment/decrement parts. Nested for loops contain one or more for loops within another for loop. While and do-while loops also repeat code until a condition is false, with the difference that do-while loops always execute the code block at least once.

Uploaded by

sadiomane8706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
489 views52 pages

C++ Questions

The document discusses different types of loops in C++ including for loops, nested for loops, while loops, and do-while loops. It provides examples of problems that can be solved using each type of loop. For loops repeat a block of code until a condition is false, and have initialization, condition, and increment/decrement parts. Nested for loops contain one or more for loops within another for loop. While and do-while loops also repeat code until a condition is false, with the difference that do-while loops always execute the code block at least once.

Uploaded by

sadiomane8706
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

For loop

For loop is a methodology to use a piece of code again and again until the given condition
remains true. Loop will terminate when the given condition will false.

For loop have three parts. Loop initialization, Condition, and increment or decrement of a loop.

1. Program to find the length of a number in C++ (CPP). Solution


2. Program to find the square root of a number in C++. Solution
3. Factorial Program in C, C++ (C Plus Plus, CPP) with flow chart. Solution
4. Fibonacci Series Program in C++ and C with flowchart. Solution
5. Palindrome Program in C, C++, C Plus Plus (CPP) with flow chart. Solution
6. Program to the Print sum of the number of Series in C Plus Plus (CPP, C++) and C with
Flowchart. Solution
7. C++ and C Program to Find the Number of Vowels, Digits, Consonants and White
Spaces in a String with flowchart. Solution
8. Program in C++, C to display the reverse of a number with a flowchart. Solution
9. Write a program that lets the user enter the total rainfall for each of 12 months
10. Write a C++ program to print a triangle of prime numbers up to given number of lines of
the triangle
11. Write a C++ program to print all numbers between a and b (a and b inclusive) using for
loops
12.

Nested for loop


Nested for loop means one or many for loops inside some another for loop.

1. Nested For Loop including 3 loops in C++ (C Plus Plus). Solution


2. 3 Level Nested for loop in C++ (C Plus Plus). Solution
3. Compound Assignment Operators in C++. Solution
4. C++ program to show the sum of main diagonal elements by using nested for loop.
Solution
5. Write nested loops to print a rectangle. sample output for given program: * * * * * *.
6. Write a C++ program to print the lower and upper triangles of a square matrix
7. Write a C++ program for trapezoidal rule

while loop
The while loop is a methodology to use a piece of code again and again until the given condition
remains true. Loop will terminate when the given condition will false.

Just lie for loop, the while loop has three parts. 1. Loop initialization, 2. Condition, and 3.
increment or decrement of a loop.
1. Program of the sum of all digits of a number in C, C Plus Plus (CPP, C++) with flow
chart. the solution
2. converts a number into binary in C++and C with a flowchart. Solution
3. Program in C Plus Plus and C with an explanation to find the Greatest Common Division
(GCD). Solution with flowchart. Solution
4. C++ Program to convert Octal to decimal number using while loop. Solution
5. Write a program using integers usernum and x as input, and output usernum divided by x
four times.
6. Write a C++ program to add two numbers without using the addition operator
7. Write a C++ program that simulates the rolling of two dice

Do while loop
In Do, while loop, first one time we execute the do part of the loop, and then we check the
condition. It means that if the condition is false then still do part execute one time.

1. C++ Program to Display English Alphabets from A-Z. Solution


2. Write a program in C++ to display the multiplication table vertically from 1 to n.
Solution
3. C++ Program to Find the Sum of Digits of a Number – C++ Program. Solution
4. Program in C++ to display the n terms of even natural number and their sum. Solution
5. C++ program to find the sum of all integer between 100 and 200 which are divisible by 9.
Solution
6. Write a program in C++ to print Floyd’s Triangle. Solution
7. C++ program to print pyramid pattern of numbers. Solution
8. C++ Program to display the n terms of odd natural number and their sum. Solution
9. Convert a binary number to octal in C++. Solution
10. c++ program to check whether a given number is a perfect number or not. Solution
11. C++ program to find HCF (Highest Common Factor) of two numbers. Solution
12. Program in C++ to convert a decimal number into binary without using an array. Solution
13. Program C++ to convert an octal number into binary. Solution
14. Write a c program to find out the sum of an A.P. series. Solution
15. Program in C++, C to display the reverse of a number with flowchart. Solution
16. Write the Octal to Decimal number program in C++. Solution
17. C++ Program right angle triangle with a number that will repeat a number in a row.
Solution
18. C++ program to print rhombus or parallelogram star pattern. Solution
19. Program in C++ to make such a pattern like a pyramid with a number that will repeat the
number in the same row. Solution
20. Write a program in C++ to Check Whether a Number can be Express as a Sum of Two
Prime Numbers. Solution
21. C++ program to print mirrored right triangle star pattern. Solution
22. Decimal to octal number conversion program in C++. Solution
23. C++ program to print a hollow square or rectangle star pattern. Solution
24. C++ Program Sum of odd Natural Number. Solution
25. The sum of the first 10 natural numbers program in C++. Solution
[Set – 2]

1. Write a program to print number from 1 to 10. solution

2. Write a program to calculate the sum of first 10 natural number. solution

3. Write a program to find the factorial value of any number entered through the keyboard.
solution

4. Two numbers are entered through the keyboard. Write a program to find the value of one
number raised to the power of another. solution

5. Write a program to reveres any given integer number. solution

6. Write a program to sum of digits of given integer number. solution

7. Write a program to check given number is prime or not. solution

8. Write a program to calculate HCF of Two given number. solution

9. Write a program to enter the numbers till the user wants and at the end it should display the
count of positive, negative and zeros entered. solution

10. Write a program to enter the numbers till the user wants and at the end it should display the
maximum and minimum number entered. solution

11. Write a program to print out all Armstrong numbers between 1 and 500. If sum of cubes of
each digit of the number is equal to the number itself, then the number is called an Armstrong
number.
For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 ) solution

12. Write a program to print Fibonacci series of n terms where n is input by user : 0 1 1 2 3 5 8
13 24 ..... solution

13. Write a program to calculate the sum of following series where n is input by user.
1 + 1/2 + 1/3 + 1/4 + 1/5 +…………1/n solution

14. Compute the natural logarithm of 2, by adding up to n terms in the series


1 - 1/2 + 1/3 - 1/4 + 1/5 -... 1/n
where n is a positive integer and input by user. solution

The C++ programs covered in this section include:


1. Find if a number is positive or negative
2. Even or Odd Number
3. Prime or Composite Number
4. Print prime numbers between 1 to 20
5. Reverse a number
6. Find if a character is an alphabet or not
7. Swap two numbers
8. Swap without third variable
9. Character is vowel or not
10. Calculate grade of student
11. Leap year program
12. Palindrome number
13. Armstrong number
14. Add digits of number
15. Count +ve, -ve & zero
16. Find larger of two numbers
17. Largest among three numbers
18. Find HCF and LCM

1. Write a C++ program to find the largest element of a given array of integers. Go to the editor
Click me to see the sample solution

2. Write a C++ program to find the largest three elements in an array. Go to the editor
Click me to see the sample solution

3. Write a C++ program to find second largest element in a given array of integers. Go to the
editor
Click me to see the sample solution

4. Write a C++ program to find k largest elements in a given array of integers. Go to the editor
Click me to see the sample solution

5. Write a C++ program to find the second smallest elements in a given array of integers. Go to
the editor
Click me to see the sample solution

6. Write a C++ program to find all elements in array of integers which have at-least two greater
elements. Go to the editor
Click me to see the sample solution
7. Write a C++ program to find the most occurring element in an array of integers. Go to the
editor
Click me to see the sample solution

8. Write a C++ program to find the next greater element of every element of a given array of
integers. Ignore those elements which have no greater element. Go to the editor
Click me to see the sample solution

9. Write a C++ program to sort a given unsorted array of integers, in wave form. Go to the editor
Note: An array is in wave form when array[0] >= array[1] <= array[2] >= array[3] <= array[4]
>= . . . .
Click me to see the sample solution

10. Write a C++ program to find the smallest element missing in a sorted array. Go to the editor
Click me to see the sample solution

11. Write a C++ program to update every array element by multiplication of next and previous
values of a given array of integers. Go to the editor
Click me to see the sample solution

12. Write a C++ program to rearrange the elements of a given array of integers in zig-zag fashion
way. Go to the editor
Note: The format zig-zag array in form a < b > c < d > e < f.
Click me to see the sample solution

13. Write a C++ program to separate even and odd numbers of an array of integers. Put all even
numbers first, and then odd numbers. Go to the editor
Click me to see the sample solution

14. Write a C++ program to separate 0s and 1s from a given array of values 0 and 1. Go to the
editor
Click me to see the sample solution

15. Write a C++ program to rearrange a given sorted array of positive integers . Go to the editor
Note: In final array, first element should be maximum value, second minimum value, third
second maximum value , fourth second minimum value, fifth third maximum and so on.
Click me to see the sample solution

16. Write a C++ program to sort a given array of 0s, 1s and 2s. In the final array put all 0s first,
then all 1s and all 2s in last. Go to the editor
Click me to see the sample solution

17. Write a C++ program to sort (in descending order) an array of distinct elements according to
absolute difference of array elements and with a given value. Go to the editor
Click me to see the sample solution
18. Write a C++ program to move all negative elements of an array of integers to the end of the
array without changing the order of positive element and negative element. Go to the editor
Click me to see the sample solution

19. Write a C++ program to find a number which occurs odd number of times of a given array of
positive integers. In the said array all numbers occur even number of times. Go to the editor
Click me to see the sample solution

20. Write a C++ program to count the number of occurrences of given number in a sorted array
of integers. Go to the editor
Click me to see the sample solution

21. Write a C++ program to find the two repeating elements in a given array of integers. Go to
the editor
Click me to see the sample solution

22. Write a C++ program to find the missing element from two given arrays of integers except
one element. Go to the editor
Click me to see the sample solution

23. Write a C++ program to find the element that appears once in an array of integers and every
other element appears twice. Go to the editor
Click me to see the sample solution

24. Write a C++ program to find the first repeating element in an array of integers. Go to the
editor
Click me to see the sample solution

25. Write a C++ program to find and print all common elements in three sorted arrays of
integers. Go to the editor
Click me to see the sample solution

26. Write a C++ program to find and print all unique elements of a given array of integers. Go to
the editor
Click me to see the sample solution

27. Write a C++ program to find the number of pairs of integers in a given array of integers
whose sum is equal to a specified number. Go to the editor
Click me to see the sample solution

28. Write a C++ program to arrange the numbers of a given array in a way that the sum of some
numbers equal the largest number in the array. Go to the editor
Click me to see the sample solution

29. Write a C++ program to find the second lowest and highest numbers in a given array
 C++ Program to Remove Characters in String Except Alphabets

 C++ Program to find Maximum or Largest number in array

 C++ Program to enter 5 numbers & display first and last only

 C++ Program To reverse an array elements entered by user

 C++ Program to Sort an Array Elements in Ascending Order

 C++ Program to Sort an Array Elements in Descending Order

 C++ Program for Addition of two matrix

 C++ Program to Find Duplicate Elements in Array

 C++ Program to Find Sum of Elements of an Array

 C++ Program to Reverse elements of an Array

 C++ Program to Find Even & Odd Elements in Array

 C++ Program to Delete element from Array

 C++ program to Insert element at specific position in array

 C++ Program to Pass Array in Function

 C++ Program for Three Dimensional (3D) Array

 C++ Program for Two Dimensional Array

 C++ Program to Delete Element from Array

 C++ Program to Find Smallest Element in Array

 C++ Program to Find Largest Element in Array

 C++Program for One Dimensional (1-D) Array

 C++ Program to Calculate Average of elements in an Arrays

1.
Write a program to print the address of a variable whose value is input from user.

2.
Write a program to print the address of the pointer to a variable whose value is input from user.

3.
Write a program to print the value of the address of the pointer to a variable whose value is input
from user.

4.
Write a program to print a number which is entered from keyboard using pointer.

5.
Write a function which will take pointer and display the number on screen. Take number from
user and print it on screen using that function.

6.
Write a program to find out the greatest and the smallest among three numbers using pointers.
7.
Write a program to add two numbers using pointer

 About
 Courses
 Discussion
 Practice
 Blog
 PRO
 Salaries

 Sign Up
 Login

Practice questions on Function


 Level 1
 Level 2

Level 1
1.
Write a program to print the sum of two numbers entered by user by defining your own function.

2.
Define a function that returns the product of two numbers entered by user.

3.
Write a program to print the circumference and area of a circle of radius entered by user by
defining your own function.

4.
Define two functions to print the maximum and the minimum number respectively among three
numbers entered by user.

5.
Define a program to find out whether a given number is even or odd.

6.
A person is elligible to vote if his/her age is greater than or equal to 18. Define a function to find
out if he/she is elligible to vote.

7.
Define a function to find out if number is prime or not.

8.
Write a program which will ask the user to enter his/her marks (out of 100). Define a function
that will display grades according to the marks entered as below:
Marks Grade
91-100 AA
81-90 AB
71-80 BB
61-70 BC
51-60 CD
41-50 DD
<=40 Fail

9.
Write a program to print the factorial of a number by defining a function named 'Factorial'.
Factorial of any number n is represented by n! and is equal to 1*2*3*....*(n-1)*n. E.g.-
4! = 1*2*3*4 = 24
3! = 3*2*1 = 6
2! = 2*1 = 2
Also,
1! = 1
0! = 0

Write a program to find the factorial of a given number by using a function in C++ programming
language.

Write a Program to print the Fibonacci sequence of a number using functions in C++ programming
language.

Write a program using the C++ programming language to print all the prime numbers between two
given numbers by creating a function.
1. Write a program using function which accept two integers as an argument and return its sum.
Call this function from main( ) and print the results in main( ). solution

2. Write a function to calculate the factorial value of any integer as an argument. Call this
function from main( ) and print the results in main( ). solution

3. Write a function that receives two numbers as an argument and display all prime numbers
between these two numbers. Call this function from main( ). solution

4. Raising a number to a power p is the same as multiplying n by itself p times. Write a function
called power that takes two arguments, a double value for n and an int value for p, and return the
result as double value. Use default argument of 2 for p, so that if this argument is omitted the
number will be squared. Write the main function that gets value from the user to test power
function. solution

 C++ Program for Linear search using recursion


 C++ Program to Find Factorial of Number Using Recursion
 C++ program to Find Sum of Natural Numbers using Recursion
 C++ program to Check Number can Express as Sum of Prime Numbers
 C++ Program to Check Prime Number
 C++ Program to Display Prime Numbers Between Two Intervals
 C++ Program to Find GCD Using Recursion
 C++ Program to Find Power Using Recursion
 C++ program to Reverse String Using Recursion
 C++ Program to Convert Binary Number to Octal
 C++Program to Convert Octal to Binary
 C++ Program to Convert Octal Number to Decimal
 C++ Program to Convert Decimal Number to Octal
 C++ Program to Convert Binary Number to Decimal
 C++ Program to convert decimal number to binary
 C++ Program for Fibonacci Series Using Recursion
 C++ program to swap values using pass by reference
 C++ Program to print series using function: x + x^3/3! + x^5/5! +…….+ x^n/n!
 C++ Program for Addition,subtraction and multiplication using function
 C++ Program to find cube of number using function
 C++ program to find greatest between two numbers using inline function
 C++ program to find factorial by defining functions outside the class
 C++ program to find greatest b/w 3 nos. by defining the functions inside class
 C++ program to swap two characters and integers by call by value
 C++ program to find reverse of number by defining functions outside class
 C++ program to swap 2 characaters and integers by call by address
 C++ program to find sum and product of 5 numbers using inline function
 C++ program to add two time by Call by reference
 C++ program to add two time by Call by address
 C++ program to find how many times function called by objects
 C++ program to find square of float and integer using inline function
 C++ program to add two complex number passing objects as arguments
 C++ program to find factorial of number using functions
 C++ program to check number is palindrome or not using Function
 C++ Program to Swap two numbers using call by value
 C++ Program to Swap two numbers by call by address
 C++ Program to Swap two numbers by call by reference
 . Write a program using function which accept two integers as an argument and return its
sum. Call this function from main( ) and print the results in main( ). solution
 2. Write a function to calculate the factorial value of any integer as an argument. Call this
function from main( ) and print the results in main( ). solution
 3. Write a function that receives two numbers as an argument and display all prime
numbers between these two numbers. Call this function from main( ). solution
 4. Raising a number to a power p is the same as multiplying n by itself p times. Write a
function called power that takes two arguments, a double value for n and an int value for
p, and return the result as double value. Use default argument of 2 for p, so that if this
argument is omitted the number will be squared. Write the main function that gets value
from the user to test power function. solution
 5. Write a function called zero_small() that has two integer arguments being passed by
reference and sets the smaller of the two numbers to 0. Write the main program to access
the function. solution

List of most popular & searched C++ programs


1. C++ Program to print right angled (Right oriented) pyramid of numbers.
In this program, we are going to learn how to print numbered pyramids of numbers (which is
right angled and right oriented)? This post contains solved program with output and
explanation.
2. C++ Program to print right angled pyramid of numbers.
In this program, we are going to learn how to print numbered pyramids of numbers? This post
contains solved program with output and explanation.
3. C++ program to keep calculate the sum of the digits of a number until the number is a single
digit.
In this program, we are going to implement logic to find sum of digits until the number is a single
digits in C++ programming language.
4. How to skip some of the array elements in C++?
Learn: How to skip some of the array elements using C++ program? Here, using an example - we
going to understand the concept of skipping some of the elements in C++.

Advertisement
5. Example of declaring and printing different constants in C++.
Declaring and printing different constant in C++: Here, we will learn to declare and print the
value of different type of constants using C++ program.
6. C++ program to demonstrate example of delay() function.
dos.h delay() function in C++: Here, we will learn about the delay() function of dos.h header file
in C++ through a simple example/program.
7. C++ program to print your name randomly on the screen with colored text.
Print your name on output screen randomly with colored text and background color using C++
program: Here you will learn some of the in-built functions that are using to print randomly,
colored, print text of specified position etc.
8. C++ program to print the maximum possible time using six of nine given single digits.
The Objective is to form the maximum possible time (in HH:MM:SS and 12 hour format) using
any six of nine given single digits (not necessarily distinct).
9. Find last index of a character in a string using C++ program.
In this post, we are going to learn: how we can get the last index of a character in a string using
C/C++ program using simple method?

Advertisement

10. C++ program to get week day from given date.


Learn: How to get weekday from a given date in C++ program? Here I am writing a C++ code by
using you can able to access the weekday of given date.
11. Set date and time in Linux Operating System using C++ program.
Learn: How to define/set date and time in Linux Operating System using C++ program? Here we
are using system() function to set date time.
12. Reading date and time from Linux operating system using C++ program.
Learn: How to get current date and time from Linux Operating System using C++ program? This
program will read date, time from Operating system and print on the standard output device.
13. C++ program to get previous date of given date.
Given a date in DD, MM and YYYY format, you have to find the previous date.
14. C++ program to find total number of days in given month of year.
C++ program to find/print total number of days in a month, in this program, we will input
month, year and program will print total number of days in that month, year.
15. C++ program to set network settings for IPv6 Network in Linux Devices.
Learn: How to set network settings for IPv6 based Network in Linux Devices? Here, we will learn
to set IP address, prefix and Gateway for IPv6 based Network.

Advertisement

16. C++ program to pad octets of IP Address with Zeros.


Learn: How to pad IP Address octets with Zeros? In this C++ program, we will learn to pad each
octet of an IP Address.
17. C++ program to set MAC address in Linux Devices.
Learn: How to set MAC address (physical address) in Linux devices using C++ program, this
program is compiled and executed in G++ compiler.
18. C++ program to get MAC address of Linux based network device.
Learn: How to get/display MAC address of a Linux based network devices using C++ program?
This program is compiled and executed in G++ compiler.
19. C++ program to set IP address, subnet mask, network gateway in Linux System.
Learn: How to set network settings like IP Address, Subnet Mask, Network Gateway using C++
program in Linux System using G++ Compiler?
20. C++ program to check given string is numeric or not.
Learn: How to check given string is numeric or not? In this C++ program, we are going to learn
how to check whether a given a string is numeric or not?
21. C++ program to check given date is in valid format or not.
In this C++ program, we will read date and check whether it is in correct format or not?

Advertisement
22. C++ program to add seconds to the time.
Learn: How to add seconds in given time and print the time in HH:MM:SS format using C++
program, here we will add seconds in time (with using all conditions like time truncating etc).
23. C++ program to find Fibonacci number using different methods.
Learn: What to find fibonacci number using different methods, here you will find multiple
methods to find the fibonacci number using C++ programs.
24. C++ program to find the next greatest number from the same set of digits.
Learn: How to find next greatest number from the same set of digits using a C++ program?
25. C++ program to convert number to word (up to four digits only).
Write a C++ program that will read an integer number (up to four digits) and convert it into
words.
26. C++ program to check whether a string2 can be formed from string1.
This C++ program reads two Strings (String1 and String2) and checks whether String2 can be
formed from String1, by printing ‘Yes’ otherwise ‘No’.
27. C++ program to print a spiral matrix.
Printing a spiral matrix up to given number using C++ program: A spiral matrix is a matrix consist
of natural numbers up to n^2.
28. C++ program to find the frequency of a character in a string using Count Array.
This C++ program will read a string and count frequency of a character using count array.
29. C++ program to find factorial of large numbers using array.
Learn: How to find factorial of large numbers in C++ using array, this program will explain finding
the factorial of large number.
30. C++ program to generate random alphabets and store them into a character array.
In this program first we take two character arrays, one to store all the alphabets and other to
print random characters into it. To keep it simple we have taken the length as 20.

Advertisement
31. C++ program to print pattern of stars till N number of rows.
This C++ program will read total number of rows from the user and print the star pattern till N
rows.
32. C++ Program to print a chessboard pattern.
This C++ program will print a chessboard like pattern using loops.
33. C++ Program to print a Pascal Triangle upto N depth.
This C++ program will read the depth and print the Pascal Trainable up to input depth.
34. C++ program to reverse a number.
This program will read and integer number and print its reverse number in C++.
35. C++ program to sort an array in Descending Order.
This program will read an integer array (one dimensional array) and sort its elements in
descending order.
36. C++ program to sort an array in Ascending Order.
This program will read an integer array (one dimensional array) and sort its elements in
ascending order.
37. C++ program to convert lowercase character to uppercase and vice versa .
This program will read a character and converts lowercase to uppercase and uppercase to
lowercase character.
38. C++ program to check leap year.
This program will read a year from the user and check whether it is Leap year or not.
39. C++ Program to check if a number is even using Recursion.
This program will read a number and check whether it is EVEN or ODD using recursion in C++.
40. C++ Program to find odd or even number without using modulus operator.
This program will read an integer number and check whether it is EVEN or ODD without using
Modulus (%) Operator.
41. C++ program to check EVEN or ODD.
This program will read an integer number and check whether it is EVEN or ODD using three
different methods.
42. C++ program to add two times.
This program will read two times and calculate their addition (total times in hours, minutes and
seconds).
43. C++ program to display prime numbers.
This program will read maximum range of the numbers (N) and print all prime numbers between
2 to N.
44. C++ program to check prime number.
This program will read an integer number and check whether it is Prime or Not using User
Defined Function.

Advertisement

45. C++ program to find factorial of a number.


This program will read an integer number and find its factorial using loop and user defined
function.
46. C++ program to display name and age.
This program will read name and age of the person and display them on separate lines.
47. C++ program to read a string.
This program will read a string using cin and cin.getline().
48. C++ program to add two integer numbers using class.
This program will read two integer numbers from the user and calculate their addition/sum
using class.
49. C++ program to add two integer numbers using pointers.
This program will read two integer numbers from the user and calculate their addition/sum
using pointer.
50. C++ program to add two integer numbers using function.
This program will read two integer numbers from the user and calculate their addition/sum
using user defined function.
51. C++ program to add two integer numbers.

Figure 1
Figure 2

Lab ACN : C++ Programming


Exercises
---------------------------------------------------------------------------------------------
----------------------
Exercise 1
Write a temperature conversion program that gives the user the option of
converting a value of
temperature to Celsius and Fahrenheit scales of temperature.
Output:
Exercise 2 (Automatic Teller Machine)
Write a program that takes balance of a user’s account as input. It should
then ask the user how
much amount he wants to withdraw from his account. The program should
take this amount as
input and deduct from the balance. Similarly it should ask the user how
much amount he wants
to deposit in his account. It should take this amount as input and add to the
balance. The
program shall display the new balance after amount has been withdrawn
and deposited.
Output:
Welcome!
Enter your balance: 1234
-------------------------------------------------------
Select an option:
1. Withdraw Amount
2. Deposit Amount
3. Exit
-------------------------------------------------------
How much amount you want to withdraw from your account?
Amount: 1233
Your new balance is: 101
How much amount you want to deposit in your account?
Amount: 100
Your new balance is: 101
Thank you for using the system!
Press 1 to convert Fahrenheit to Celsius
Press 2 to convert Celsius to Fahrenheit
Enter temperature in Fahrenheit: 70
In Celsius that’s: 21.111111
Figure 1
Note: Your program should have a check on balance and amount being
withdrawn. Amounts
greater than balance cannot be withdrawn i.e. balance cannot be negative.
Exercise 3
Write a program which takes two numbers as input from user and
determines which is the larger
of the two numbers. The Program should also tell which of the entered
numbers is even or odd.
Output
Exercise 4
You need to design a calculator that performs four basic arithmetic
operations. You will write a
program that takes two numbers as input from the user. It then displays a
list of arithmetic
operations. The user selects one operation and the program displays the
result of the
corresponding operation. The program should also display which of the two
input numbers is
greater and which is smaller. Use do-while loop. Interaction with the
program might look like the
following:
Exercise 5
Write a program that takes marks of 10 students as input. It calculates the
class average and
displays it on the screen. Interaction with the program might look like this.
Use while loop.
Welcome
Enter number 1: 4
Enter number 2: 7
number 2 is greater than number 1
number 1 is EVEN.
number 2 is ODD.
Please enter two numbers
24
8
Please make a selection:
1) Addition
2) Subtraction
3) Multiplication
4) Division
1
Addition:32
24 is greater.
Welcome
Enter marks: 10
Enter marks: 20
Enter marks: 22.5
Enter marks: 70
Enter marks: 54.75
Enter marks: 87.5
Enter marks: 90.5
Enter marks: 43
Enter marks: 24
Enter marks: 45
Class Average is: 46.725
Figure 2
Exercise 6
Write a program that repeatedly asks the user to enter two money amounts
expressed in
pounds. The program should then add the two amounts and display the
answer in pounds. The
program should then convert the amount in Rupees. (Set conversion rate:
1£=120.33 rupees).
Display the answer in Rupees. Use a do-while loop that asks the user
whether the program
should be terminated.
Exercise 7
An aircraft system is designed which checks speeds and monitors various
functions of the
aircraft during the flight. Warnings and errors are generated if any fault
develops during the
flight. The system is coded in a manner that if 100 is entered as input it
indi- cates “normal
speed range”, if 101 is entered it gives “over-speed warning” indicating that
aircraft is over-
speeding. If 88 is entered, it indicates “Low Oil Pressure” and if 187 is
entered it indicates
“Engine Failure”. Use switch statement to implement this logic.
Exercise 8
Write a program that calculates and prints the sum of the even integers
from 2 to
user_defined_limit and product of odd integers from 1 to
user_defined_limit. Use a do-while
loop that asks the user whether the program should be terminated or not.
Also maintain a count
as to how many times the user ran the do-while loop.
Exercise 9 (for loop)
Write the following program and execute it. What output does the program
display? Expand the
shorthand form of expression sum += i-- to show what it actually
represents. State the total
number of iterations made by the “for loop”?
Welcome!
Enter first amount: £5.10
Enter second amount: £3.2
Total amount: £8.30
Amount in rupees: Rs.998.739/-
Do you wish to continue (y or Y/n or N)?
Thank you for using the system!
Exercise 10
The factorial of an integer n, written n!, is simply the product of all the
integers from 1 to n. For
example 5! = 1*2*3*4*5 = 120. Write a program to calculate the factorial of
integers from 1 to n
where n is taken from the user. Your output should look like the sample
output given below. Use
setw() operator to format your output. What is the maximum value of
factorial that you can
calculate for int data type? Is there any difference between the maximum
value of factorial for
unsigned and signed int?
Exercise 11
Write a program which asks the user whether he wants to draw a pattern
as shown in the
screenshot below. If user enters “Y” or “y” the program should draw the
pattern. If “Q” or “q” is
opted the program should quit. However, if any other alphanumeric input is
given to program
the program shall display that the particular input is not recognized. Use
nested for loops in your
program. Interaction with the program might look like this:
.
Exercise 12
A calculator for a supercomputer is to be designed using C language. While
the engineers were
working on the project they found that the calculator was not giving correct
answers for very
large calculations. For example, if 150000000 is to be multiplied by 10; the
calculator gave
faulty result. The bug was detected to be the limited range of integers. Use
type casting to
design a calculator that performs arithmetic operations of large inputs. (e.g;
150000000 *10)
Take input from the user in integer data type.
Exercise 13
Write a program which takes PIN number of the user as input and then
verifies his pin. If pin
is verified the program shall display “pin verified” and “Welcome”; otherwise
the program
shall give user another chance. After 4 wrong attempts, the program shall
display “Limit
expired” and then exit. Use for loops to implement the logic.
Note: 5 random PIN numbers can be assumed and fed into the program
with which input pin
is matched.
Exercise 14
The function definition of starline() function is given to you below. Write a C
program that uses
the following function to generate the output given below.
.
Exercise 15
Write a program which takes two integers from the user using scanf().
Implement a function
void swapInts(int, int) that interchanges the two int values passed to it by
main() function.
Display the interchanged numbers inside the function using printf(). Also
display the values
of the two integers in main() function. What do you observe from the
output?
What happens to the output if you change the function prototype as follows:
void swapInts(int &, int &);
Exercise 16
Write a program that takes a set of test scores of a student. It then uses
two functions calcula-
teSum() and calculateAverage() to calculate the sum and average of the
data set.
Your program must use the following functions:
1. A value-returning function, calculateSum(), to determine the sum of the
test scores. Use
a loop to read and sum the test scores. The function does not output the
sum of the test
scores. This task must be done in the main function.
2. A void function, calculateAverage(), to determine the average of the test
scores. The
func- tion does not output the average test score. This task must be done in
the main
function. Hint: Use pass by reference for average variable.
Exercise 17
If P is the population of the first day of the year, B is the birth rate and D is
the death rate, the
estimated population at the end of the year is given by formula:
Pn + ( B * Pn ) / 100 – ( D * Pn ) / 100
The population growth rate is given by the formula:
B-D
Write a program that prompts the user to enter the starting population, birth
and death rates and
n, the number of years. The program should then calculate and print the
estimated population
after n years. Your program must contain the following functions:
GrowthRate: This function takes as its parameters the birth and death rates
and returns the
population growth rate.
Estimated Population: This function takes as its parameters the current
population, population
growth rate and n, the number of years. It returns the estimated population
after n years. Your
program should not accept negative birth rate, negative death rate or
population less than 2.
• Exercise 18
Write a function that displays a message indicating the number of times it
gets called: For
instance “The function has been called three times”. Write a program that
calls this function
10 times from main(). You will need to use a global variable to store the
count. A global
variable is declared outside the main() function.
Note: All variables declared inside a function are local variables. Their
value is lost once
the function ends.
Exercise 19 (Converting a Number from Decimal to Binary)
This exercise designs a program that uses recursion to convert a non-
negative integer in de-
cimal format to equivalent binary number. Let x be an integer. We call the
remainder of x after
division by 2 the right most bit of x. Thus, the right most bit of 33 is 1
because 33% of 2 is 1 and
right most bit of 28 is 0 because 28% is 0.
Suppose we want to find the binary representation of 35. First we divide 35
by 2. The quotient is
17 and the remainder, right most bit of 35 is 1. Next we divide 17 by 2. The
quotient is 8 and
remainder, that is right most bit of 17 is 1. Next we divide 8 by 2. The
quotient is 4 and the re-
mainder that is the right most bit of 8 is 0. We continue this process until
the quotient is 0.
Thus, to convert an integer “num” in base 10 into the equivalent binary
number we first convert
quotient “num/2” into an equivalent binary number, and then append the
rightmost bit of “num”
to the binary representation of “num/2”.
Recursive Algorithm :
decToBin is equal to num if num = 0
decToBin is equal to decToBin(num/base, base) followed by
cout << remainder if num >0
Write a recursive function void decToBin () having two input parameters
num and base and
hence calculate the binary number.
Exercise 20 (Generating a pattern)
Write an iterative function void printPattern(num) that takes as a
parameter a non-
negative integer and generates the following pattern of stars to generate
the following pat-

tern. Then try and convert it into a recursive function that takes as a
parameter a non-
negative integer and generates the following pattern of stars. E.g. if the
non-negative integer is
5, then following pattern is generated:
*****
****
***
**
*
*
**
***
****
***
Write a program
that inputs a
series of integers
and passes them
one at a time to
function
isEven
, which uses the
modulus operator
to determine
whether an
integer is even.
The function
should take an
integer argument
and return
true
if the integer is
even and
false
ist of c++ language function and recursion programming exercises

1. Write C++ program to check even or odd using functions


2. Write C++ to check prime and armstrong numbers using function
3. Write C++ program to find cube of a number using function
4. Write C++ Program to convert binary number to decimal
5. Write C++ Program to convert decimal number to binary using function
6. Write C++ program to find Length of the String by passing String/Character
7. Write C++ program to print all strong numbers between 2 numbers
8. Write C++ program to find prime numbers in given range using functions
9. Write C++ program to find diameter, circumference and area of circle using function
10. Write C++ program to print perfect numbers between given interval using function
11. Write C++ program to find power of a number using recursion
12. Write C++ program to find sum of natural numbers in given range using recursion
13. Write C++ program to print even or odd numbers in given range using recursion
14. Write C++ program to find reverse of a number using recursion
15. Write C++ program to find LCM of two numbers using recursion
16. Write C++ program to find HCF of two numbers using recursion
17. Write C++ program to print elements of array using recursion
18. Write C++ program to find sum of array elements using recursion
19. Write C++ program to generate nth fibonacci term using recursion
20. Write C++ program to find factorial of a number using recursion
21. Write C++ program to check palindrome number using recursion
22. Write C++ program to find maximum and minimum elements in array using recursion

List of C++ language Pointer Exercise

1. Write C++ program to swap two numbers using pointers


2. Write C++ program to add two numbers using pointers
3. Write C++ program to Sum of Array Elements using Pointers
4. Write C++ program to find length of string using pointer
5. Write C++ program to copy one string to another string using pointer
6. Write C++ program to concatenate two strings using pointer
7. Write C++ program to print the elements of the array in reverse order using a pointer

List of C++ language array programs with an examples

1. Write a C++ program to print all negative elements in an array


2. Write C++ program to count total number of negative elements in array
3. Write C++ program to read and print elements of array
4. Write C++ program to find sum of all elements of an array
5. Write C++ program to count even and odd elements in an array
6. Write C++ program to find maximum and minimum element in array
7. Write C++ program to insert an element in array
8. Write C++ program to print all unique element in an array
9. Write C++ program to sort an array in ascending order
10. Write C++ program to copy all elements of one array to another
11. Write C++ program to count number of each element in an array
12. Write C++ program to delete all duplicate elements from an array
13. Write C++ program count total duplicate elements in an array
14. Write C++ program to merge two sorted array
15. Write C++ program to put even and odd elements of array in two separate array
16. Write C++ program to find reverse of an array
17. Write C++ program to left rotate an array
18. Write C++ program to right rotate an array

otherwise. 2. An
application of
function
floor
is rounding a
value to the
nearest integer.
The statement y
= floor( x + .5 );
rounds the
number x to the
nearest integer
and assigns the
result to y. Write
a program that
reads several
numbers and
uses the
preceding
statement to
round each of
these numbers to
the nearest
integer. For each
number
processed, print
both the original
number and the
rounded number.
3. Write a
function
integerPower(
base
,
exponent
)
that returns the
value of
base
exponent
.
For example,
integerPower(3, 4)
=3*3*3*3
. Assume that
exponent
is a positive,
nonzero integer
and that
base

is an integer. Do
not use any math
library functions.
4.
(Parking Charges)
A parking
garage charges a
$2.00 minimum
fee to park for up
1.Write a Banking Application Program in C++ using Switch Case and functions for each.1 – Deposit
function2 – Withdraw function3 – Balance_Check function ( Shd print Name (XXX), Account Number
(101), Balance,TotalAdditions and Total Deductions)*Note: repeat the choice until 3, initialize
balance=500Condition:1. Minimum Balance should be 500 INR2. Interest to be added for every
transaction for about 1.5% if the balance is <10,000 & >500 and 2% if>=10,0003. Transaction could not
be made if balance is 0.4. Penalty of 50 INR to be deducted for the next transaction if balance <
minimum balance

1.
Create a class named 'Student' with a string variable 'name' and an integer variable 'roll_no'.
Assign the value of roll_no as '2' and that of name as "John" by creating an object of the class
Student.

2.
Assign and print the roll number, phone number and address of two students having names
"Sam" and "John" respectively by creating two objects of the class 'Student'.

3.
Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5 units by
creating a class named 'Triangle' with a function to print the area and perimeter.

4.
Write a program to print the area and perimeter of a triangle having sides of 3, 4 and 5 units by
creating a class named 'Triangle' with the constructor having the three sides as its parameters.

5.
Write a program to print the area of two rectangles having sides (4,5) and (5,8) respectively by
creating a class named 'Rectangle' with a function named 'Area' which returns the area. Length
and breadth are passed as parameters to its constructor.

6.
Write a program to print the area of a rectangle by creating a class named 'Area' having two
functions. First function named as 'setDim' takes the length and breadth of the rectangle as
parameters and the second function named as 'getArea' returns the area of the rectangle. Length
and breadth of the rectangle are entered through keyboard.

7.
Write a program to print the area of a rectangle by creating a class named 'Area' taking the values
of its length and breadth as parameters of its constructor and having a function named
'returnArea' which returns the area of the rectangle. Length and breadth of the rectangle are
entered through keyboard.
8.
Print the average of three numbers entered by the user by creating a class named 'Average'
having a function to calculate and print the average without creating any object of the Average
class.

9.
Print the sum, difference and product of two complex numbers by creating a class named
'Complex' with separate functions for each operation whose real and imaginary parts are entered
by the user.

10.
Write a program to print the volume of a box by creating a class named 'Volume' with an
initialization list to initialize its length, breadth and height. (just to make you familiar with
initialization lists)

11.
Write a program that would print the information (name, year of joining, salary, address) of three
employees by creating a class named 'Employee'. The output should be as follows:
Name Year of joining Address
Robert 1994 64C- WallsStreat
Sam 2000 68D- WallsStreat
John 1999 26B- WallsStreat

12.
Add two distances in inch-feet by creating a class named 'AddDistance'.

13.Write a program by creating an 'Employee' class having the following functions and print the
final salary.
1 - 'getInfo()' which takes the salary, number of hours of work per day of employee as
parameters
2 - 'AddSal()' which adds $10 to the salary of the employee if it is less than $500.
3 - 'AddWork()' which adds $5 to the salary of the employee if the number of hours of work per
day is more than 6 hours.

14.Write a probram with a mother class animal. Inside it define a name and an age variables, and
set_value() function.Then create two bases variables Zebra and Dolphin which write a message telling
the age, the name and giving some extra information (e.g. place of origin

15. Write a program that defines a shape class with a constructor that gives value to width and height.
The define two sub-classes triangle and rectangle, that calculate the area of the shape area (). In the
main, define two variables a triangle and a rectangle and then call the area() function in this two
varibles.

 C++ program to find factorial by defining functions outside the class


 C++ program to find greatest b/w 3 nos. by defining the functions inside class
 C++ program to find reverse of number by defining functions outside class
 C++ program to add two time by Call by reference
 C++ program to add two time by Call by address
 C++ program to find how many times function called by objects
 C++ program to find square of float and integer using inline function
 C++ program to add two complex number passing objects as arguments
 C++ Program to display entered Date
 C++ program to display Student details using class
 C++ Program to find Largest among 3 numbers using classes
 C++ Program to find Sum of odd numbers between 1 and 100 using class
 C++ program to display Entered Time using class
 C++ program to find Largest among 2 numbers using class
 C++ program to Swap two numbers using class
 C++ program for various Mathematical Operations using Switch case
 C++ Program to Compare Two Strings using overloading
 C++ Program to enter student marks and roll no. using Virtual Class
 C++ Program to Print Numbers From 1 to n using class
 C++ Program to calculate Volume of Cube using constructor and destructor
 C++ Program to Perform Complex Operations using Overloading
 C++ Program to determine the Area of Rectangle using constructors
 C++ Program to show Constructor & Destructor Example
 C++ Program to Show Counter using Constructors
 C++ Program to Display Date using Constructors
 C++ program to Display Student Details using constructor and destructor
 C++ Program to enter student details by Passing parameters to constructors
 C++ Program to Show Overload Constructor Example
 C++ Program to show Example of Default copy constructor
 C++ Program to demonstrate Constructor Overloading
 C++ Program To calculate Volume of Box using Constructor
 C++ Program To Calculate Simple Interest using class
 C++ Program To Calculate Electricity Bill Of Person using Class
 C++ program to multiply every member by 10 using class
 C++ program for Simple Queue using Class
 C++ Program to implement B- Trees using Linked Lists
Com (Computer & Computer Applications) (CBCS)
OBJECT ORIENTED PROGRAMMING IN C++ Practical question bank
1. Write a C++ program to reverse a given number.
2. Write a C++ program to add two numbers using class.
3. Write a C++ program to check whether a given number is prime.
4. Write a C++ program to demonstrate the usage of scope resolution
operator.
5. Write a C++ program to check whether a given year is leap year or not.
6. Write a C++ program to add two numbers using functions.
7. Write a C++ program to accept and display the details of a student using
class.
8. Write a C++ program to accept and display the details of an employee
using a class.
9. Write a C++ program to count the number of words and characters in a
given text.
10. Write a C++ program to compare two strings using string functions.
11. Write a C++ program to find the GCD of two numbers.
12. Write a C++ program to calculate the area of rectangle, square using
function overloading.
13. Write a C++ program to add two numbers using pointers.
14. Write a C++ program to find the factorial of a given number.
15. Write a C++ program to search for an element using binary search.
16. Write a C++ program to sort an array in ascending order.
17. Write a C++ program to find the factorial of a given number using
recursion.
18. Write a C++ program to check whether a given number is even or odd.
19. Write a C++ program to demonstrate the usage of Inline function.
20. Write a C++ program to demonstrate parameter passing mechanism
using pass by value
method.
21. Write a C++ program to demonstrate parameter passing mechanism
using pass by address
method.
1.
Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale
which inherits both the above classes. Now, create a function in each of these classes which
prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as
well as Marine Animals" respectively. Now, create an object for each of the above class and try
calling
1 - function of Mammals by the object of Mammal
2 - function of MarineAnimal by the object of MarineAnimal
3 - function of BlueWhale by the object of BlueWhale
4 - function of each of its parent by the object of BlueWhale

2.
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.

3.
We want to calculate the total marks of each student of a class in Physics,Chemistry and
Mathematics and the average marks of the class. The number of students in the class are entered
by the user. Create a class named Marks with data members for roll number, name and marks.
Create three other classes inheriting the Marks class, namely Physics, Chemistry and
Mathematics, which are used to define marks in individual subject of each student. Roll number
of each student will be generated automatically.

4.
We want to store the information of different vehicles. Create a class named Vehicle with two
data member named mileage and price. Create its two subclasses
*Car with data members to store ownership cost, warranty (by years), seating capacity and fuel
type (diesel or petrol).
*Bike with data members to store the number of cylinders, number of gears, cooling type(air,
liquid or oil), wheel type(alloys or spokes) and fuel tank size(in inches)
Make another two subclasses Audi and Ford of Car, each having a data member to store the
model type. Next, make two subclasses Bajaj and TVS, each having a data member to store the
make-type.
Now, store and print the information of an Audi and a Ford car (i.e. model type, ownership cost,
warranty, seating capacity, fuel type, mileage and price.) Do the same for a Bajaj and a TVS
bike.

5.
Create a class named Shape with a function that prints "This is a shape". Create another class
named Polygon inheriting the Shape class with the same function that prints "Polygon is a
shape". Create two other classes named Rectangle and Triangle having the same function which
prints "Rectangle is a polygon" and "Triangle is a polygon" respectively. Again, make another
class named Square having the same function which prints "Square is a rectangle".
Now, try calling the function by the object of each of these classes.

6.
All the banks operating in India are controlled by RBI. RBI has set a well defined guideline (e.g.
minimum interest rate, minimum balance allowed, maximum withdrawal limit etc) which all
banks must follow. For example, suppose RBI has set minimum interest rate applicable to a
saving bank account to be 4% annually; however, banks are free to use 4% interest rate or to set
any rates above it.

Write a program to implement bank functionality in the above scenario. Note: Create few classes
namely Customer, Account, RBI (Base Class) and few derived classes (SBI, ICICI, PNB etc).
Assume and implement required member variables and functions in each class.

 Home
 Tutorials
 Papers
 MCQs
 Research
 Contact

Important Links
 Past Papers
 Research Topics Ideas
 Final Year Projects Ideas
 Computer Science MCQs
 MCQs for different subjects
 All Subjects Tutorials
 Tutorials of Computer Science

Past Papers of Object-Oriented Programming

Past Papers of Object-Oriented Programming


This is just a sample paper of Object-Oriented Programming. Nature of papers questions can
depend on your university or instructor that how he is taking the course content. Now let’s see a
sample paper of Object-Oriented Programming.

Paper 1: Object-Oriented Programming


Course Title: Object-Oriented Programming Course Code: Confidential

Discipline /Program : BSCS Total Marks:30


Time allowed: 2 Hour Instructor’s Name: Confidential

Note:

Attempt All Questions. Marks are written adjacent to each question.

Question No 1 (6)

What is operator overloading? Why we use operator overloading? Differentiate between the
followings;

1. Function overloading and function overriding


2. Constructor overloading and operator overloading

Question No 2 (6)

What is polymorphism? Write a program using polymorphism in which user enters the number if
the number is positive and the number is also even, then print the cube of the number and if the
number is odd and negative then print the square of the number.

Question No 3 (6)

Write a program using multi-level inheritance in which user enter a number, the program will
show the table of the given number from 1 to 10.

Question No 4 (6)

What is output for the following programs?

A.

C++

floa t x=5.999;
floa t *y,*z;
y=&x;
z=y;

1 float x=5.999;

2 float *y,*z;

3 y=&x;

4 z=y;

5 cout<<x<<","<<*(&x)<<","<<*y<<","<<*z<<"\n";
B.

C++

int tra c k[]={10,20,30,40},*strike r;


striker=tra c k;
trac k[1]+=30;
c out<<"Strike r>"<<*strike r<<end

1 int track[]={10,20,30,40},*striker;

2 striker=track;

3 track[1]+=30;

4 cout<<"Striker>"<<*striker<<endl;

5 *striker-=10;

6 striker++;

7 cout<<"Next@"<<*striker<<endl;

8 striker+=2;

9 cout<<"Last@"<<*striker<<endl;

10 cout<<"Reset To"<<track[0]<<endl;

Question No 5: (6)

Give one programming example of constructor overloading and function overloading.

Paper 2: Object-Oriented Programming


Course Title: Object-Oriented Programming Course Code: Confidential

Discipline /Program : MCS Total Marks:30

Time allowed: 2 Hour Instructor’s Name: Confidential

Note:

Attempt All Questions. Marks are written adjacent to each question.

Question No 1 (6)

What are single and multiple inheritances. Write a program to find the grades of a student using
multiple inheritances according to the following rules;
Grade A if marks are > 80

Grade B if marks are >70 and < 80

Grade C if marks are > 50 and <70

Grade F if marks are < 40

Question No 2 (6)

What is Multilevel inheritance? Write a program using multi-level inheritance in which the user
enters the number, calculates the cube of the number, if the cube of the number is greater than
150 then print the square of the resultant cube, otherwise show the message “sorry”.

Question No 3 (6)

Write a program in which users enter 5 numbers using for loop and all these numbers will store
in an array. After that program will add these five numbers and show the result. Your program
must support the concept of operator overloading.

Question No 4 (6)

What is output for the following programs?

A.

C++

int a =32,*ptr=&a ;
c ha r c h='A',&c ho=c h;
c ho+=a;
*ptr+=c h;

1 int a=32,*ptr=&a;

2 char ch='A',&cho=ch;

3 cho+=a;

4 *ptr+=ch;

5 cout<<a<<","<<ch<<endl;

6 return 0;

B.

C++
c onst int i=20;
c onst int *c onst ptr=&i;
(*ptr)++;
int j=15;

1 const int i=20;

2 const int *const ptr=&i;

3 (*ptr)++;

4 int j=15;

5 ptr=&j;

Question No 5: (6) (6)

Give one programming example of function overriding.

Paper 3 – Open Book Paper of Object-Oriented Programming in C++


Course Title: Object-Oriented Programming Course Code: Confidential

Discipline /Program : MCS Total Marks:30

Time allowed: 12 Hours Instructor’s Name: Confidential

Theory Paper

Q#1 7.5 Marks

Write a C++ program by using classes to show the sum of array rows and columns.

You must write this program by using a constructor and do while loop.

Q#2 7.5 Marks

Write a C++ program by using classes to find the greatest and lowest value from the array. If
the greatest value is greater then 100, then print “its my good luck”, otherwise print ”its my bad
luck”.

You must use while loop and using the user define function. Further user define function must be
accessible by some another friend class.

Q#3 7.5 Marks


Write a C++ program by using classes in which user enter the three angles a1, a2, and a3, and
then program will check that its valid triangle or not. If it’s valid triangle, then find the factorial
of a1 with while loop, and find that a2 is a palindrome number or not. If a2 is palindrome, then
find the factorial of a2.

You must use the concepts of multiple inheritance in the program

Q#4 7.5 Marks

Write a C++ program by using classes in which user enter the number, program will reverse the
number. After reversing the number, show the sum of all numbers. For example if number is
153, the after reverse it will be 351 and the sum will be 9. Now if the sum is a odd number, then
show its odd number, otherwise show even number. Just even odd module must be implemented
with operator overloading.

Further, you are not allowed to use for loop. You can use Do while loop.

Paper 4 – Open Book Paper of Object-Oriented Programming in C++


Course Title: Object-Oriented Programming Course Code: Confidential

Discipline /Program : MCS Total Marks:20

Time allowed: 12 Hours Instructor’s Name: Confidential

Practical Paper

Q#1 10 Marks

Write a C++ program by using classes to delete duplicate elements from an array? After
duplicate elements removal, sort the array in descending order. After sorting the array, copy all
sorted elements of the array1 into the array 2.

Further, you are not allowed to use for loop. You can use while loop, user define functions and
multi level inheritance.

Q#2 10 Marks

Write a C++ program by using classes to take the hours and minutes and the show that whether it
is AM or PM by using the switch statements. Hours must be taken from nearest parent class,
minutes must be taken virtually. If it’s AM then check that hours represent the prime number or
not. Similarly if it’s PM, then check that minutes represent the strong number or not.

Paper 5 – Open Book Conceptual Paper of Object-Oriented Programming in C++


Course Title: Object-Oriented Programming Course Code: Confidential
Discipline /Program : MCS Total Marks:18

Time allowed: 12 Hours Instructor’s Name: Confidential

Theory Paper

Q#1 7.5 Marks

Write a C++ program by using classes to show the sum of array rows and columns.

You must write this program by using constructor and do while loop.

Q#2 7.5 Marks

Write a C++ program by using classes to find the greatest and lowest value from array. If the
greatest value is greater then 100, then print “its my good luck”, otherwise print ”its my bad
luck”.

You must use while loop and using the user define function. Further user define function must be
accessible by some another friend class.

Q#3 7.5 Marks

Write a C++ program by using classes in which user enter the three angles a1, a2, and a3, and
then program will check that its valid triangle or not. If it’s valid triangle, then find the factorial
of a1 with while loop, and find that a2 is a palindrome number or not. If a2 is palindrome, then
find the factorial of a2.

You must use the concepts of multiple inheritance in the program

Q#4 7.5 Marks

Write a C++ program by using classes in which user enter the number, program will reverse the
number. After reversing the number, show the sum of all numbers. For example if number is
153, the after reverse it will be 351 and the sum will be 9. Now if the sum is a odd number, then
show its odd number, otherwise show even number. Just even odd module must be implemented
with operator overloading.

Further, you are not allowed to use for loop. You can use Do while loop.

Paper 6 – Open Book Logical Paper of Object-Oriented Programming in C++


Course Title: Object-Oriented Programming Course Code: Confidential
Discipline /Program : MCS Total Marks:18

Time allowed: 12 Hours Instructor’s Name: Confidential

Theory Paper

Q#1
6marks

Print star pattern in a rectangle using while loop and by using the concept constructor and
destructor

Q#2
6marks

Write a C++ program to check that a number is prime or not. If the number is prime then check
that the prime number is a composite number or not. Write this program with the help of multi-
level inheritance.

Q#3
6marks

Suppose you are developing a hospital management system in which the user enter the patient
and doctor compulsory detail, and then patient checks that the doctor is available or not.

Redundancy is a big issue. So, write your program in C++ in such a way by using the inheritance
that it reduce the redundancy.

You also need to draw the class diagram of the system.

Paper 7 – Guess Paper of Object-Oriented Programming in C++


Course Title: Object-Oriented Programming Course Code: Confidential

Discipline /Program : MCS Total Marks:18

Time allowed: 12 Hours Instructor’s Name: Confidential

Theory Paper

Q#1 7.5 Marks

You must write this program by using constructor and do while loop.
Write a C++ program by using classes in which user enter the number, program will reverse the
number. After reversing the number, show the sum of all numbers. For example if number is
153, the after reverse it will be 351 and the sum will be 9. Now if the sum is a odd number, then
show its odd number, otherwise show even number. Just even odd module must be implemented
with operator overloading.

Further, you are not allowed to use for loop. You can use Do while loop.

Q#2 7.5 Marks

Write a C++ program by using classes in which user enter the three angles a1, a2, and a3, and
then the program will check that it’s valid triangle or not. If it’s the valid triangle, then find the
factorial of a1 with while loop, and find that a2 is a palindrome number or not. If a2 is a
palindrome, then find the factorial of a2.

You must use the concepts of multiple inheritances in the program

Q#3 7.5 Marks

Write a C++ program by using classes to find the greatest and lowest value from the array. If the
greatest value is greater then 100, then print “its my good luck”, otherwise print ” it’s my bad
luck”.

You must use for loop and using the user defined a function. Further user defines function must
be accessible by some another friend class.

Q#4 7.5 Marks

Write a C++ program by using 3 classes to print 3 rectangles of different sizes.

Paper 8 – Guess Paper of Object-Oriented Programming in C++

Course Title:Object Oriented Programming


Total Marks:40
Time allowed: 1 Hour

Q.No.1.

Write a C++ program to display the area of a rectangle by using a class named ‘Area’ with two
member functions. The first function named as ‘Dimension’ will takes the length and breadth of
the rectangle as parameters and the second function named as ‘takeArea’ returns the area of the
rectangle. Assign proper data types to the data members of the classes. There should be two
functions one to input/get data and the other to display the data. In main() create THREE objects
of each class and assign data and then display the data of each object by calling the
corresponding functions. [ 10 ]

Q.No.2.
[20]

1. a) Write a C++ Class having name StaticClass there should be three static data members (x,y,z).
An initial value of 10 should be assigned to each data member. In default constructor x, y, and z
should be incremented by 10, 20, and 30 respectively. Display this data using a static member
function Display(). Create 5 objects and then display the data. Also write down the output
(values of data members) on your answer sheet.
2. b) How private data of a class can be accessed from outside of the class? Briefly define friend
function in C++ with a suitable concise example.

Q.No. 3. Define the following terms and write concise example where necessary.
[10]

1. Constructor
2. Access specifiers and types
3. Data Abstraction along with programming example

Prof.Fazal Rehman Shamil (Available for Professional Discussions)


1. Message on Facebook page for discussions,
2. Video lectures on Youtube
3. Email is only for Advertisement/business enquiries.

Related Posts:

 What is Class and object, How to declare object in c++ oop, Example of class, object and
attributes
 Past Papers of Object oriented analysis and design OOAD
 Polymorphism Mcqs In Object Oriented Programming(OOP)
 Object-Oriented Programming in C++
 Object Oriented Programming C++
 Which of the following is an object oriented programming language?
OOP

 Past Papers(Guess)
 MCQs
 Function overloading
 Classes and Objects
 Private Protected Public
 Private Member Function in C++
 C++ friend class
 Object Declaration
 Constructors
 Constructor overloading
 Destructor
 Inheritance
 Single Inheritance
 Multiple Inheritance
 Multi Level Inheritance
 Function Overriding
 Friend function, Friend classes
 Delete Array Elements using Constructor Destructor and Classes Inheritance in OOP – C++
 HexaDecimal to Binary Classes Constructor Destructor and Inheritance in OOP – C++
 How to Print Diamond Shape with OOP Classes and objects
 Octal to Binary Conversion Program with Classes and Objects in OOP – C++
 How to pass and return object from a function in C++ using classes
 C++ program for factorial using Multi-level inheritance
 C++ program for factorial using Multiple inheritance
 C++ program for factorial using single inheritance
 C++ program for factorial using Constructor Destructor
 Factorial Program in C++ using Class Objects
 Inline Function in C++
 Invocation of constructors and Destructors
 Virtual base class in C++ OOP
 factorial of a no. by defining the member functions outside the class
 Operator Overloading
 Binary Operator Overloading C++ OOP
 Fibonacci Series Using Operator Overloading C++
 Assignment Operator Overloading in C++
 even odd operator overloading
 Types of constructors in C++
 Logical Or operator Overloading C++
 Case Studies Examples Scenarios OOP
 Matrix addition multiplication operator overloading
 String Operator Overloading
 The sum of two prime numbers is 85
 C++ bank account program
 File Handling using File Streams in C++
 Object-Oriented Programming in C++
 Scope resolution operator
Search for

You might also like