100% found this document useful (2 votes)
5K views

C++ Practical Assignment

The document outlines 25 programming problems of varying complexity that involve concepts like arithmetic operations, conditional statements, loops, functions, classes, objects, inheritance, operator overloading, arrays, and more. For each problem, sample code and output is provided.

Uploaded by

vjagarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
5K views

C++ Practical Assignment

The document outlines 25 programming problems of varying complexity that involve concepts like arithmetic operations, conditional statements, loops, functions, classes, objects, inheritance, operator overloading, arrays, and more. For each problem, sample code and output is provided.

Uploaded by

vjagarwal
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 47

1. Write a program to perform addition of two numbers.

Output:-

2. Write a program to find greatest from three numbers.

Object Oriented Programming…… Page 1


Object Oriented Programming…… Page 2
Output:-

Object Oriented Programming…… Page 3


3. Write a program to solve quadratic equation. Where if discriminate
negative then print roots are are imaginary and either discriminate zero or
positive then calculate roots.

Object Oriented Programming…… Page 4


Output:-1st

Output:-2nd

Object Oriented Programming…… Page 5


4. Write a program to print Fibonacci series.

Output:-

Object Oriented Programming…… Page 6


5. Input a number and print its table in following format.

Output:-

Object Oriented Programming…… Page 7


6. Write a program of student mark sheet where Physics, Chemistry and
Math’s are the subject as input.

Object Oriented Programming…… Page 8


Object Oriented Programming…… Page 9
Output:-

Object Oriented Programming…… Page 10


7. Define a class "Bank" with following data members Acc-no, Name of
Depositor, A/C Balance, Write member function to perform following
task.

Object Oriented Programming…… Page 11


Object Oriented Programming…… Page 12
Output:-

Object Oriented Programming…… Page 13


8. Program for parameterized constructors.

Object Oriented Programming…… Page 14


Output:-

Object Oriented Programming…… Page 15


9. WAP to use reference variable.

Object Oriented Programming…… Page 16


Output:-

Object Oriented Programming…… Page 17


10. WAP to pass 2 objects to member function sum of class test for one
integer private data. Sum receives values of x for 2 objects, sum them
and return the object to calling portion. Input () receives values of x for
both the objects.

Object Oriented Programming…… Page 18


Output:-

Object Oriented Programming…… Page 19


11. Write a program in C++ to overload the binary operator ‘+’.
Overload an operator binary ‘+’.
Overload operator binary ‘+’ (addition).

Object Oriented Programming…… Page 20


Object Oriented Programming…… Page 21
Output:-

Object Oriented Programming…… Page 22


12. Create class "multi" with 2 data members x and y. Class has multiple
constructor and i.e. one default constructor and another parameterized,
which receives value of x and y. show() display the value accordingly.

Object Oriented Programming…… Page 23


Output:-

Object Oriented Programming…… Page 24


13. Accessing different data types with public access specifies.

Object Oriented Programming…… Page 25


Output:-

Object Oriented Programming…… Page 26


14. Single inheritance constructor & destructor execution.

Object Oriented Programming…… Page 27


Output:-

Object Oriented Programming…… Page 28


15. Take a class first in which there is a method in protected section namely
show(). This method prints the message "I am show () method of class
first". Take another class second which publicly inherits the class first.
The class second also contains a method namely show () which prints the
message "Ï am show() method of class second". WAP to call both
methods.

Object Oriented Programming…… Page 29


Output:-

Object Oriented Programming…… Page 30


16. Accessing derived class member using base class pointer.

Object Oriented Programming…… Page 31


Output:-

Object Oriented Programming…… Page 32


17. WAP to enter name using single character variable.

Output:-

Object Oriented Programming…… Page 33


18. Enter a line and count number of words in it.

Output:-

Object Oriented Programming…… Page 34


19. WAP to print user-defined in formations using formatting functions.
Input or assign strings and numbers and define field width for them. Fill
the empty spaces with character and also define size of numerical float
values.

Object Oriented Programming…… Page 35


Output:-

Object Oriented Programming…… Page 36


20. Write a program to calculate matrix of 2x2.

Object Oriented Programming…… Page 37


Output:-

Object Oriented Programming…… Page 38


21. Input a number and check it is prime or not using class module.

Object Oriented Programming…… Page 39


Output:-

Object Oriented Programming…… Page 40


22. Wap to enter n numbers and arrange it in ascending order.

Object Oriented Programming…… Page 41


Output:-

Object Oriented Programming…… Page 42


23. Wap to find factorial of a value.

Output:-

Object Oriented Programming…… Page 43


24. Enter a number and display it in reverse order and display sum of all digit
and display total number of digits in value.

Object Oriented Programming…… Page 44


Output:-

Object Oriented Programming…… Page 45


25. Wap to find input number is single, double, tripple between 0 to 999.

Object Oriented Programming…… Page 46


Output:-

Object Oriented Programming…… Page 47

You might also like