Write a program that will demonstrate the access of member functions by objects

Bismillahir Rahmanir Rahim
Assignment 1:
Write a program that will demonstrate the access of member functions by objects. The program that uses the following properties- class name- A,  integer type private member variable- b, two public member functions-set_data(int value), getdata(), four objects- e, f, g, h. The output will be:
140
99
38
28


 Solution:

#include<iostream.h>
class A
{
 int b;
 public:
 int set_data(int value)
 {
   b=value;
   return b;
 }
 void get_data()
 {
  cout<<b<<endl;
 }
};
void main()
{
 A e,f,g,h;
 e.set_data(140);
 f.set_data(99);
 g.set_data(38);
 h.set_data(28);
 e.get_data();
 f.get_data();
 g.get_data();
 h.get_data() ;
}

Socializer Widget By Blogger Yard
SOCIALIZE IT →
FOLLOW US →
SHARE IT →