c++类的学习

#include<iostream>
#include<stdlib.h>
#include<string>
#include<time.h>
using namespace std;
class Array
{
  public:
     void set();
     void show();
     void find();
     void allshow();
  private:
     int max;
     int array[1000];
};

void Array::set() 
{
   int i;
   srand(time(NULL));
   for( i=0 ;i < 100 ;i++)
      array[i]=rand()%1000;
}
void Array::find()
{
    max=array[0];
    int i;
    for( i=1 ;i < 100; i++)
      if(array[i]>max)
      max=array[i];
}
void Array::show()
{
   cout<<"the max number is:\n"<<max;
   puts("");
}
void Array::allshow()
{
    int i;
    for(i=0;i<100;i++)
     {
      cout<<array[i]<<" ";
      if(i%10==0&&i!=0)
        puts("");
     }
     puts("");
}
int main( )
{
    class Array t;
    t.set();
    t.find();
    t.allshow();
    t.show();
    system("pause");
    return 0;
}

posted on 2011-06-08 21:39  more think, more gains  阅读(188)  评论(0编辑  收藏  举报

导航