C++ program Classes with arrays as data members

0
1243

C++ program Classes with arrays as data members

CONSTRUCTION:

  1. Start the program.
  2. Include the header files.
  3. Create the class array with data member member function getdata(), putdata().
  4. Create array of object for the class name array in the main function.
  5. Get input for max size of array elements.
  6. Get the input for elements to be shared in array.
  7. Print incremented value of array elements using member function
  8. Stop the program.

PROGRAM:

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

class array
{
int x;
public:

void getdata()
{
cin>>x;
}

void putdata()
{
cout<<x+20<<"\n";
}};

void main()
{
int i,n;
clrscr();
array a[20];
cout<<"\nEnter maximun size of array";
cin>>n;
cout<<"\nEnter elements one by one";
for(i=0;i<n;i++)
{
a[i].getdata();
}
cout<<"\n The input elements incremented by 20 are:::\n";
for(i=0;i<n;i++)
{
a[i].putdata();
}
getch();
}

Leave a Reply