OOP: Batch-23, Lecture-01

#include<iostream>
using namespace std;
class Teacher; // class declaration
//declaration and definition
//class member: private, public, protected
class Student //Structure / Template for an object
{
int roll; // data member/attribute/property
char name[30];
char section;
float cgpa;

public:
void get_data() // member function definition inside the class
{
cout << “Enter roll: “;
cin >> roll; // cin input object
cout <<“Enter Name: “;
cin >> name;
}
void show_data(); // member function declaration
float get_cgpa();
}s1;

//defining a member function outside the class
void Student::show_data() // :: >> scope resolution
{
cout << ” — Student info — “<<endl;
cout << “Roll: ” << roll << endl; // endl == ‘\n’
cout << “Name: ” << name << endl;
}

int main()
{
Student s2; // Single object / variable
Student s[60]; // Array of object

cout<<“Enter student 1 info: “;
s1.get_data(); // accessing member via object

cout<<“Enter student 2 info: “;
s2.get_data();

cout<<“Enter student 3 info: “;
s[0].get_data();

s1.show_data();
s2.show_data();
s[0].show_data();

//s3 = s1 + s2; // Operator Overloading

return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>