c++ practical assignment

56
1. Write a program to perform addition of two numbers. Output:- Object Oriented Programming…… Page 1

Upload: vjagarwal

Post on 04-Apr-2015

1.510 views

Category:

Documents


6 download

DESCRIPTION

This document contains 25 C++ programs.

TRANSCRIPT

Page 1: C++ Practical Assignment

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

Output:-

Object Oriented Programming…… Page 1

Page 2: C++ Practical Assignment

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

Object Oriented Programming…… Page 2

Page 3: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 3

Page 4: C++ Practical Assignment

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

Page 5: C++ Practical Assignment

Output:-1st

Output:-2nd

Object Oriented Programming…… Page 5

Page 6: C++ Practical Assignment

4. Write a program to print Fibonacci series.

Output:-

Object Oriented Programming…… Page 6

Page 7: C++ Practical Assignment

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

Output:-

Object Oriented Programming…… Page 7

Page 8: C++ Practical Assignment

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

Object Oriented Programming…… Page 8

Page 9: C++ Practical Assignment

Object Oriented Programming…… Page 9

Page 10: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 10

Page 11: C++ Practical Assignment

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

Page 12: C++ Practical Assignment

Object Oriented Programming…… Page 12

Page 13: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 13

Page 14: C++ Practical Assignment

8. Program for parameterized constructors.

Object Oriented Programming…… Page 14

Page 15: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 15

Page 16: C++ Practical Assignment

9. WAP to use reference variable.

Object Oriented Programming…… Page 16

Page 17: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 17

Page 18: C++ Practical Assignment

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

Page 19: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 19

Page 20: C++ Practical Assignment

11. Write a program in C++ to overload the binary operator ‘+’.

Overload an operator binary ‘+’.

Overload operator binary ‘+’ (addition).

Object Oriented Programming…… Page 20

Page 21: C++ Practical Assignment

Object Oriented Programming…… Page 21

Page 22: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 22

Page 23: C++ Practical Assignment

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

Page 24: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 24

Page 25: C++ Practical Assignment

13. Accessing different data types with public access specifies.

Object Oriented Programming…… Page 25

Page 26: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 26

Page 27: C++ Practical Assignment

14. Single inheritance constructor & destructor execution.

Object Oriented Programming…… Page 27

Page 28: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 28

Page 29: C++ Practical Assignment

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

Page 30: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 30

Page 31: C++ Practical Assignment

16. Accessing derived class member using base class pointer.

Object Oriented Programming…… Page 31

Page 32: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 32

Page 33: C++ Practical Assignment

17. WAP to enter name using single character variable.

Output:-

Object Oriented Programming…… Page 33

Page 34: C++ Practical Assignment

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

Output:-

Object Oriented Programming…… Page 34

Page 35: C++ Practical Assignment

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

Page 36: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 36

Page 37: C++ Practical Assignment

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

Object Oriented Programming…… Page 37

Page 38: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 38

Page 39: C++ Practical Assignment

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

Object Oriented Programming…… Page 39

Page 40: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 40

Page 41: C++ Practical Assignment

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

Object Oriented Programming…… Page 41

Page 42: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 42

Page 43: C++ Practical Assignment

23. Wap to find factorial of a value.

Output:-

Object Oriented Programming…… Page 43

Page 44: C++ Practical Assignment

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

Page 45: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 45

Page 46: C++ Practical Assignment

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

Object Oriented Programming…… Page 46

Page 47: C++ Practical Assignment

Output:-

Object Oriented Programming…… Page 47