Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Inheritance

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Inheritance

1. Describe use of protected access specifier used in the class.(2m)


2. Explain the access specifiers in C++
3. Give output for following code:(2m)
class student
{
int roll no; char name [14];
} s[6];
void main( )
{ cout <<sizeof(s);
}
4. Write syntax to define a derived class.(2m)

5. Write a C++ program to declare a class ‘College’ with data members as name and college
code. Derive a new class ‘student’ from the class college with data members as sname and
roll no. Accept and display details of one student with college data.

6. Write a C++ program to implement inheritance shown in following figure:


Accept and display data of one teacher and one student using object of class ‘Info’.

Class : Teacher
Class : Student datamember
datamember : Name
: sname rollno.
empid

Class : Info

7. Write a C++ program to implement following inheritance. Accept and display data for one
programmer and one manager. Make display function virtual.

Class : Employee Data : empid


Member : empcode

Class : Programmer Class : Manager


Datamember : Skill Datamember : department

8. Write C++ program for following multilevel inheritance. Accept and display data for one car
with all details./ Explain multilevel inheritance with an example
Class : Carmanufacturer
datamember : Name

Class : Carmodel

datamember : Model name,


Model no.

Class : Car

datamember : Car no., colour

9. What is inheritance? Give different types of inheritance.


10. Write a C++ program to implement multiple inheritances as shown in Figure No. 1. Accept
and display data of test marks and sport’s marks using object of class ‘result’.

Class name: Test Class name: Sports

Data members: Data members :


marks1, marks2 Sportscore

Class name: Result

Data members: Total

11. State different types of visibility mode in inheritance.


12. Write a program on hybrid inheritance.
13. Write a C++ program to implement following inheritance: Refer Fig. No. 1
Accept and display total of one object of result.

Science Maths
Phy marks Alg marks
Chy marks Geo marks

Result

Total
14. Write a program to implement inheritance as shown in figure No. 2. Assume suitable
member function. Accept and display data of one Teacher and one Officer

Staff

Code

Teacher Officer

Subject Grade

15. What is multilevel inheritance? Draw the diagram to show multilevel inheritance. using
classes with data member and member function(2m)
16. Write a program to implement single inheritance from the following Refer Figure No. 1/
Write a program on single inheritance.

Class name: Employee


Member variables:
Emp_id ,name

Class name: Employee _info


Member variables:
Basic_salary

17. Write a program to implement the following hierarchy using suitable member functions.
Refer Figure No. 2

Class name: Student


Member variables:
Rollno,Name

Class name: Test Class name: Sports


Member variables: Member variables:
Marks1,marks2 Score

Class name: Result


Member variables:
Total
18. Write a C++ program to declare a class COLLEGE with members as college code. Derive a
new class as STUDENT with members as studid. Accept and display details of student along
with college for one object of student
19. Describe with examples, passing parameters to base class constructor and derived class
constructor by creating object of derived class

Pointer
20. Explain reference and dereference operators w.r.t. pointer(2m)
21. List two memory management operators available in C++. Also state its use.
22. Write a C++ program to declare a class train with members as train no and name. Accept and
display data for one object of train. Use pointer to object to call functions of class.
23. Describe ‘this’ pointer in C++ with an example
24. Write a program to declare a class ‘item’ containing data members as ‘item_name’, ‘code’,
‘price’. Accept and display the information for one object using pointer to that object
25. State the advantages of pointer.
26. Write a program to declare a class ‘book’ containing data members as ‘title’, ‘author-name’,
‘publication’, ‘price’. Accept and display the information for one object using pointer to that
object
27. Give meaning of following statements(2m)
int * ptr, a = 5;
ptr = & a ;
cout << * ptr ;
cout << (* ptr) + 1

Polymorphism
28. With suitable example, describe effect of ++ and – – operators used with pointer in pointer
arithmetic.
29. Write a C++ program to swap two integer numbers and swap two float numbers using
function overloading. (Hint : overload swap function)
30. Write a C++ program to overload binary operator ‘+’ to concatenate two strings.
31. Write a program to overload the ‘—’ unary operator to negate the values
32. Define polymorphism with it’s types
33. Explain the rules of virtual function
34. State the need of virtual function in C++.
35. Explain abstract class with suitable example.
36. Differentiate between compile time polymorphism and run time polymorphism.
37. Describe the concept of virtual base class with suitable example.

File Operations
38. Write a C++ program to count number of spaces in text file
39. Write a C++ program to append data from abc .txt to xyz .txt file
40. Write a C++ program to write ‘Welcome to poly’ in a file. Then read the data from file and
display it on screen.
41. Give the syntax and use of fclose( ) function.(2m)
42. Write a C++ program for write into a file using file operations
43. Write a program for get and put functions
44. Write a program for closing a file.
45. List c++ stream classes along with their function. (any two classes)
46. Explain ios :: app and ios :: in flags
47. Write a C++ program to copy the contents of a source file student 1.txt to a destination file
student 2.txt using file operations
48. Write a program to count the number of lines in file

You might also like