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

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...