각기 다른 객체를 만들려고합니다. 각 객체에는 임의의 값을 가진 숫자의 구조체 배열이 있습니다. 컴파일 후 모든 객체의 배열 내부에 같은 번호의 시퀀스가 생깁니다.
배열 안에 고유 한 일련의 숫자를 가진 다른 개체를 만드는 방법이 있습니까?고유 한 난수를 갖는 구조의 배열을 사용하여 여러 객체 만들기
#include <iostream>
#include <time.h>
#include <stdlib.h>
using namespace std;
struct storeTwoValue
{
int x;
int y;
};
class practice{
public:
storeTwoValue storageArray[10];
void valueGenerator()
{ srand(time(NULL));
for (int i = 0; i< 10; i++)
{
storageArray[i].x = rand()%10 +1;
storageArray[i].y = rand()%7 + 1;
}
}
void print()
{
cout<<"x"<<" "<<"y"<<endl;
for (int i = 0; i< 10; i++)
{
cout<<storageArray[i].x <<" ";
cout<< storageArray[i].y << endl;
}
cout<<endl;
}
};
int main()
{
for(int i=0; i<3; i++)
{ practice A;
A.valueGenerator();
A.print();
}
return 0;
}