C++ Questions
C++ Questions
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.
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.
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
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
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 enter 5 numbers & display first and last only
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
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
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
Advertisement
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
Figure 1
Figure 2
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
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.
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
Note:
Question No 1 (6)
What is operator overloading? Why we use operator overloading? Differentiate between the
followings;
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)
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++
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)
Note:
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
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)
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;
3 (*ptr)++;
4 int j=15;
5 ptr=&j;
Theory Paper
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.
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.
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.
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.
Theory Paper
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.
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.
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.
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.
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.
Theory Paper
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.
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.
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.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
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