Expt 11

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

11.

Write a C++ program to create three objects for a class named count object with
data members such as roll_no & Name. Create a members function set_data() for
setting the data values & display ( ) member function to display which object has
invoked it using this pointer.

#include<iostream.h>
#include<conio.h>
#include<string.h>

class CountObject {
private:
int roll_no;
char Name[50];

public:
void set_data(int roll, const char* name);
void display();
};

void CountObject::set_data(int roll, const char* name) {


roll_no = roll;
strcpy(Name, name);
}

void CountObject::display() {
cout << "roll Number:"<<roll_no << "\nName: " << Name << " \n" ;
}

int main() {
clrscr();

CountObject obj1, obj2, obj3;

obj1.set_data(1, "Abhishek C");


obj2.set_data(2, "Abhishek N");
obj3.set_data(3, "Aditya");

obj1.display();
obj2.display();
obj3.display();

getch();
return 0;
}

You might also like