C++ Program: Concept of Pointers to Objects

 // 13 C++ program - Concept of pointers to objects


/* Create a class containing the following data members Register_No, Name

and Fees. Also create a member function to read and display the data using the

concept of pointers to objects.

*/


#include<iostream.h>

#include<conio.h>


class Student

{

private:

long regno;

char name[20];

float fees;

public:

void readdata( );

void display( );

};


void Student::readdata( )

{

cout<<"Enter the Register Number:"<<endl;

cin>>regno;

cout<<"Enter the Student Name:"<<endl;

cin>>name;

cout<<"Enter the Fees:"<<endl;

cin>>fees;

}


void Student::display( )

{

cout<<"Register Number : "<<regno<<endl;

cout<<"Student Name : "<<name<<endl;

cout<<"Fees : "<<fees<<endl;

}


void main( )

{

Student *S; // Create a pointer to point Student object

clrscr( );


S->readdata( ); // Access Student data member using a pointer

S->display( ); // Display data using a pointer

getch( );

}


Comments

Popular posts from this blog

Karnataka I PUC Computer Science 2024 Study Material | SECOND PUC HANDBOOK EXAM 2025

PYTHON: Tips and Tricks