Pages

Sunday, May 18, 2025

Object-Oriented Programming: Creating a Student Class from Person Base Class (Assignment Question 3)

 #include <iostream>

using namespace std;

class Person {
public:

    string name; // mistakes -> char name();
    int age; // mistakes -> int age();
};

class Student : public Person {
public:
     void displayStudentInfo(string id) {
        cout << "(" << name << "\", " << age << " ,\"" << id << "\")";  // in order to put double quotations please put \ then " so-> \" this is how it will work
        }
       
};



int main() {
    Student student;
    student.name = "\"Deb";
    student.age = 17;
    student.displayStudentInfo("S12345");

    return 0;
}

OUTPUT:
("Deb", 17 ,"S12345")

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...