Wednesday, 11 March 2015

Write a program that will demonstrate arrays of object

Write a program that will demonstrate arrays of object. The program that uses the following properties - class name- efg, integer type private member variable- x. Two public member function - inputdata(int a), outputdata(). inputdata(int a) get the value of a from main() and assigned it for x. inputdata()function will displays output as 0 1 2 3 4 5 6 7. Inside main(), it used arrays of object like zz[8].

#include <iostream>
using namespace std;
class efg
{
private:
                int x;
public:
                void inputdata(int);
                void outputdata(void);
};
void efg :: inputdata(int a)
{
                x=a;
}
void efg :: outputdata(void)
{
                cout << x << " ";
}
int main()
{
                efg zz[8];
                for(int i=0;i<8;i++)
                {
                                zz[i].inputdata(i);
                }
                for(int i=0;i<8;i++)
                {
                                zz[i].outputdata();

                }
                return 0;

}

No comments:

Post a Comment