Monday, 1 October 2012

Array Reading by For Loop


#include<iostream.h>
const int size = 10;
class array
{
private:
int a[size];
int n;
public:
array()
{
for ( int i=0; i<size; i++ )
{
a[i];
n = 0;
}
}
void read()
{
int num;
cout<<"how many values you want to insert ?? "<<endl;
cin>>num;
for ( int i = 0; i<num; i++)
{
cout<<"Enter value: "<<endl;
cin>>a[i];
}
n = num;

}
void display ()
{
for (int i = 0; i<n; i++ )
cout<<a[i]<<endl;
}

};
void main()
{
array arr;
arr.read();
cout<<"The entered values are: "<<endl;
arr.display();
}

No comments:

Post a Comment