Step 1: Start the program.
Step 2: Declare the base class student.
Step 3: Declare and define the function get() to get the student details.
Step 4: Declare the other class sports.
Step 5: Declare and define the function getsm() to read the sports mark.
Step 6: Create the class statement derived from student and sports.
Step 7: Declare and define the function display() to find out the total and average.
Step 8: Declare the derived class object,call the functions get(),getsm() and display().
Step 9: Stop the program.
PROGRAM:
01 | #include<iostream.h> |
02 | #include<conio.h> |
03 |
04 | class student |
05 | { |
06 | protected: |
07 | int rno,m 1 ,m 2 ; |
08 | public: |
09 | void get() |
10 | { |
11 | cout<< "Enter the Roll no :" ; |
12 | cin>>rno; |
13 | cout<< "Enter the two marks :" ; |
14 | cin>>m 1 >>m 2 ; |
15 | } |
16 | }; |
17 | class sports |
18 | { |
19 | protected: |
20 | int sm; // sm = Sports mark |
21 | public: |
22 | void getsm() |
23 | { |
24 | cout<< "\nEnter the sports mark :" ; |
25 | cin>>sm; |
26 |
27 | } |
28 | }; |
29 | class statement:public student,public sports |
30 | { |
31 | int tot,avg; |
32 | public: |
33 | void display() |
34 | { |
35 | tot=(m 1 +m 2 +sm); |
36 | avg=tot/ 3 ; |
37 | cout<< "\n\n\tRoll No : " <<rno<< "\n\tTotal : " <<tot; |
38 | cout<< "\n\tAverage : " <<avg; |
39 | } |
40 | }; |
41 | void main() |
42 | { |
43 | clrscr(); |
44 | statement obj; |
45 | obj.get(); |
46 | obj.getsm(); |
47 | obj.display(); |
48 | getch(); |
49 | } |
Enter the Roll no: 100
Enter two marks
90
80
Enter the Sports Mark: 90
Roll No: 100
Total : 260
Average: 86.66
Tidak ada komentar:
Posting Komentar