C++ Practical

4
Date: - 10.04.2015 Practical No 08 Aim: Generating student report, creates a class student, and declares Data Members (student name, roll_no) Member function (Input student name and roll_no, Show student name and roll_no). Class subject ,Data Members(subject name) Member function(Input subject name, Show subject name ),Class internal: Data member(internal marks), member function (input internal marks, show internal marks), class external :data member(external marks), member function(input external marks, show external marks) class total : data member (total marks). Member function (input for (subject, internal marks, external marks), show function (show subject, show internal marks, external marks and total marks)). Use the concept of virtual base class, write a main () function to test the program. Keyword/ Key point: - 1) Virtual Base Syntax:- Child classname :: Virtual ParentClass Theory:- An ambiguity can arise when several paths exist to a class from the same base class. This means that a child class could have duplicate sets of members inherited from a single base class. C++ solves this issue by introducing a virtual base class. When a class is made virtual, necessary care is taken so that the duplication is avoided regardless of the number of paths that exist to the child class. When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base

description

C++`

Transcript of C++ Practical

Date: - 10.04.2015Practical No 08

Aim: Generating student report, creates a class student, and declares Data Members (student name, roll_no) Member function (Input student name and roll_no, Show student name and roll_no). Class subject ,Data Members(subject name) Member function(Input subject name, Show subject name ),Class internal: Data member(internal marks), member function (input internal marks, show internal marks), class external :data member(external marks), member function(input external marks, show external marks) class total : data member (total marks). Member function (input for (subject, internal marks, external marks), show function (show subject, show internal marks, external marks and total marks)). Use the concept of virtual base class, write a main () function to test the program.

Keyword/ Key point: - 1) Virtual Base

Syntax:- Child classname :: Virtual ParentClass

Theory:-

An ambiguity can arise when several paths exist to a class from the same base class. This means that a child class could have duplicate sets of members inherited from a single base class.C++ solves this issue by introducing a virtual base class. When a class is made virtual, necessary care is taken so that the duplication is avoided regardless of the number of paths that exist to the child class. When two or more objects are derived from a common base class, we can prevent multiple copies of the base class being present in an object derived from those objects by declaring the base class as virtual when it is being inherited. Such a base class is known as virtual base class. This can be achieved by preceding the base class name with the word virtual.

Code :- #include#includeclass student{protected:char s_name[20];int roll_no;public:void get_student(){couts_name;coutroll_no;

}void show_student(){cout