ALGORITHM OF DIFFERENT C++ PROGRAMMES

(1)Algorithm to implement a class template

Sol:

1. create a template class
2. then create a class c
Private section:-
A array a[5]specification with anomous type T
Public section:-
(a) A member function get() for input the array.
(b) A member function show() for display.

3. In main we create a class object a of integer type i.e ca and a nother object of float type
4. Then we call the two function get() and show throw these object.
5. End of programe.



(2)Algorithm to implement a function template
sol:
1. Define the prefix template
2. Create a function sum of template type with template argume nt i.e.
T sum(T a, T b)
3. Then take another template type variable and add a& b and return c i.e.
C= a+b
4. In main call the sum function first with integer variable then character variable 7 get desire output.
5. End of programe.



(3)Algorithm to implement exception handling in a prog
Sol:

1. initialize x,y,z with float data type
2. enter the value of x ,y, & z.
3. then initlize try block & check whether x equal to y .
4. If x is equal to y then throw exception x-y.
5. Else z/x-y.
6. This exception throw by throw statement caught by catch block & execute it.
7. End of the programe.



(4)Algorithm to implement a virtual base class
Sol:-

1. create a base class stu
Protected section: data member rno of integer type.
Public section:

( a) member function getrno ()for input rno
(c) member function putrno() for displat rno.
2. create another class test & make it virtual to base class stu which is inherited in public mode
Protected: data members m1 7 m2 of integer type.
Public:

(a) member function getmarks(int x, int y) input the marks in two subject.
(b) member function putmarks() for display the marks.

3. create another class sport & make it virtual to base class stu which is inherited in public mode
Protected: data members score of integer type.
Public: (a) member function getscore(int n) input the score.
(b) member function putscore() for display the score.

4. in main create an object of class test t & another object of class sport s.
5. throw t & s we call the member function of classes and get our result.
6. end of programe.



(5).Algorithm to implement hybrid inheritance
Sol:
1. create a class student
protected section: a string of name[20].
Public section:

(a)member function getname () for input name
(b) member function showname() for display name.
2. create an another class test publically inherit student and make it virtual
Protected section: data member marks1, marks2 of integer type.
Public section:

(a) member function getmarks() for input marks
(b) member function showmarks() for display marks.
3. create another class game publicaly inherit student and make it virtual
Protected section: data member score of integer type.
Public section:

(a) member function getscore() for input score.
(b) member function showscore() for display score.
4. create an another class which publically inherited classes test & game it show hybrid inheritance
Private section: datamember total of integer type.
Public section:

(a) member function showresult() which show the total marks
(b) call showname(),showmarks() & show scrore().
5 in main create an object of class result as st.
6 call getname().
7. call getmarks().
8. call getscore().
9. call showresult().
10. end of programe

 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments