Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- class student{
- string name;
- int rollno;
- public:
- void initialize(string n,int r);
- void display();
- };
- void student::initialize(string n,int r){
- name=n;
- rollno=r;
- }
- void student::display(){
- cout<<"Student Details : \n";
- cout<<"Roll No : "<<rollno<<endl;
- cout<<"Name : "<<name<<endl;;
- }
- int main()
- {
- int n,i;
- string nam;
- int roll;
- cout<<"Enter the no of students...";
- cin>>n;
- student s[n];
- student *ptr,*p[n];
- cout<<"\nEnter the student details one by one..";
- for(i=0;i<n;i++){
- cout<<"\nEnter the roll no followed by name ";
- cin>>roll>>nam;
- s[i].initialize(nam,roll);
- p[i]=&s[i];
- }
- cout<<"\nDisplaying the Student database by using a single pointer to an array of objects";
- ptr=s;
- for(i=0;i<n;i++){
- ptr->display();
- ptr++;
- }
- cout<<"\nDisplaying the Student database by using array of pointers\n";
- for(i=0;i<n;i++){
- p[i]->display();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement