fork download
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. class Person{
  6. char name[20];
  7. int age;
  8. char aadhar[13];
  9.  
  10. public:
  11.  
  12. Person(char const *name,int age,char const *aadhar){
  13. strcpy(this->name,name);
  14. this->age=age;
  15. strcpy(this->aadhar,aadhar);
  16. // cout << "in Person's Parameterised Constructor" << endl;
  17. }
  18.  
  19. Person(){
  20. strcpy(this->name,"");
  21. this->age=0;
  22. strcpy(this->aadhar,"");
  23. // cout << "in Person's Default Constructor" << endl;
  24. }
  25.  
  26. protected:
  27.  
  28. void getName(char const *name){
  29. strcpy(this->name,name);
  30. }
  31.  
  32. void displayName(){
  33. cout << "\n\nDetails of person: Name- " << name << "\n";
  34. }
  35.  
  36. void getAge(int age){
  37. this->age=age;
  38. }
  39.  
  40. void displayAge(){
  41. cout << "Age- " << age << "\n";
  42. }
  43.  
  44. void getAadhar(char const *aadhar){
  45. strcpy(this->aadhar,aadhar);
  46. }
  47.  
  48. void displayAadhar(){
  49. cout << "Aadhar- " << aadhar << "\n";
  50. }
  51. };
  52.  
  53. class library{
  54. char book[20];
  55. int issue_id;
  56.  
  57. public:
  58.  
  59. library(char const *book,int issue_id){
  60. strcpy(this->book,book);
  61. this->issue_id=issue_id;
  62. }
  63.  
  64. library(){
  65. strcpy(this->book,"");
  66. this->issue_id=0;
  67. }
  68.  
  69. protected:
  70.  
  71. void getBook(char const *book){
  72. strcpy(this->book,book);
  73. }
  74.  
  75. void displayBook(){
  76. cout << "Book- " << book << "\n";
  77. }
  78.  
  79. void getIssue_id(int issue_id){
  80. this->issue_id=issue_id;
  81. }
  82.  
  83. void displayIssue_id(){
  84. cout << "Issue Id- " << issue_id << "\n";
  85. }
  86. };
  87.  
  88. class Student : Person,library{
  89. int roll_no;
  90. char course[10];
  91. float marks;
  92.  
  93. public:
  94.  
  95. Student(char const *name,int age,char const *aadhar,int roll_no,char const *course,float marks,char const *book,int issue_id):Person(name,age,aadhar),library(book,issue_id){
  96. this->roll_no=roll_no;
  97. strcpy(this->course,course);
  98. this->marks=marks;
  99. // cout << "in Student's Parameterised constructor" << endl;
  100. }
  101.  
  102. Student():Person(),library(){
  103. this->roll_no=0;
  104. strcpy(this->course,"");
  105. this->marks=0.0;
  106. }
  107.  
  108. void getRoll(char const *name,int age,char const *aadhar,int roll_no){
  109. this->roll_no=roll_no;
  110. getName(name);
  111. getAge(age);
  112. getAadhar(aadhar);
  113. }
  114.  
  115. void displayRoll(){
  116. displayName();
  117. displayAge();
  118. displayAadhar();
  119. cout << "RollNo.- " << roll_no << "\n";
  120. }
  121.  
  122. void getCourse(char const *course){
  123. strcpy(this->course,course);
  124. }
  125.  
  126. void displayCourse(){
  127. cout << "Course- " << course << "\n";
  128. }
  129.  
  130. void getMarks(float marks,char const *book,int issue_id){
  131. this->marks=marks;
  132. getBook(book);
  133. getIssue_id(issue_id);
  134. }
  135.  
  136. void displayMarks(){
  137. cout << "Marks- " << marks << "\n";
  138. displayBook();
  139. displayIssue_id();
  140. cout << "\n";
  141. }
  142. };
  143.  
  144. int main(){
  145.  
  146. // Parameterised constructor object
  147.  
  148. Student std("Vikas",39,"ACIS1983318Y",28,"DVLSI",99.5,"The Jungle Book",1203);
  149. std.displayRoll();
  150. std.displayCourse();
  151. std.displayMarks();
  152.  
  153. // Default constructor object
  154.  
  155. Student std1;
  156. std1.getRoll("Shashank",5,"AXPY125449SA",24);
  157. std1.getCourse("DVLSI");
  158. std1.getMarks(91.3,"Julius Caesar",1508);
  159. std1.displayRoll();
  160. std1.displayCourse();
  161. std1.displayMarks();
  162. }
  163.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout

Details of person: Name- Vikas
Age- 39
Aadhar- ACIS1983318Y
RollNo.- 28
Course- DVLSI
Marks- 99.5
Book- The Jungle Book
Issue Id- 1203



Details of person: Name- Shashank
Age- 5
Aadhar- AXPY125449SA
RollNo.- 24
Course- DVLSI
Marks- 91.3
Book- Julius Caesar
Issue Id- 1508