two dimensional array

I programmed something that will group numbers from 11001 to 111999 but I wanted it to run like this:

for example if lets make the range of numbers from 11001 to 110020... and I wanted them to be grouped in 3

Group 1 (7 people)
110002 1-6
110008 1-2
110009 1-3
110013 1-4
110015 1-5
110016 1-7
110019 1-1

Group 2 (7 people)
110001 2-1
110003 2-6
110005 2-4
110010 2-2
110012 2-5
110017 2-3
110020 2-7

Group 3 (6 people)
110004 3-2
110006 3-6
110007 3-1
110011 3-4
110014 3-5
110018 3-3

the program should randomly divide the numbers [110001-111999] into several groups and the numbers should be arranged from an ascending order [I finished this part already]


so this is what I did:

#include <cstdlib> //needed for srand and rand functions
#include <iostream> //needed for cout and cin
#include <algorithm> //needed for the shuffle function
#include <ctime> // needed since we used time function

using namespace std;
//function prototypes
void OnlyOne(int B);
void MoreThanOne(int Array[], int numElements);
void bubble_sort(int Array[],int N);

int main(int argc, char *argv[]) //int/main function
{
//declaration of variables
char repeat;
int batch;
int RandNum[1999] = {0}; //initializing values in the array to 0

//start of int function
do
{
int batch;
cout << "Hello! Do you wish to divide the ID #s into 1";
cout << " (press 1) or many (press 2) batches?: "; //I did this just to have the
//batch input/cin in the void function (MoreThanOne(RandNum, batch))
cin >> batch;
if(!cin.fail())//if the cin value is appropriate as what is declared, which is int.
if(batch == 1)
{
cout << "Batch 1 students are: " << endl;
OnlyOne(batch); //void
}
else if(batch == 2)
{
MoreThanOne(RandNum, batch); //void
}
else
{
cout << "Invalid!" << endl; //reaction
cin.clear(); //clears the cin
cin.sync(); //ignores the stream
}

cout << "Try Again? (Y): ";
cin >> repeat;
} while (toupper(repeat) == 'Y'); //looping the program to start again if user wants to

system("PAUSE");
return EXIT_SUCCESS; //end of int/main function
}

void OnlyOne(int B) //simply displays ID numbers from 110001 to 111999
{
int x = 1;
cout << "The only batch which contains 1999 elements: " << endl;
for (x = 1; x < 2000; x += 1)
{
cout << x+110000 << endl;
}
}

void MoreThanOne(int Array[], int numElements) //function to be use when division of ID NUMBERS
//is necessary
{
//array setting {ordered}
for(int x = 0; x < 1999; x += 1)
{
Array[x] = x+110001;
}

//Shuffling Array[x]
srand(static_cast<int>(time(0))); //shuffle using time
for (int i=0; i<1999; i++)
{
int r = i + (rand() % (1999-i)); // Random remaining position.
int temp = Array[i]; Array[i] = Array[r]; Array[r] = temp;
}//end of shuffling the Array[x]

int batch;
cout << "Hello user! Please enter the number of batches you want to have (2 to 1999): ";
cout << endl;
cin >> batch;
//start of batching , initial step
int N = 1999 % batch; //number of repetitions the...
int L = 1999/batch + 1; //this
int K = (1999-L*N)/(batch-N); //number of id left
int Z = batch - N; //number of batches holding the number of id left
for (int n = 0; n < N; n++) //repetition of batches
{
//pointers
cout << "Batch " << n + 1 << " with " << L << " elements:" << endl;
int size = L;
int start = n*L;
int end = size +n*L;
int *batchArray = new int[size];

for (int i = 0; i < size; i++)
{
batchArray[i] = Array[i + start];
}

bubble_sort(batchArray,L);
for (int i=0; i < size; i++)
{
cout << batchArray[i] << endl;
}
delete[] batchArray;

}

//additional batches
for (int j = 0; j < batch - N; j++) // repetition of batch
{
cout << "Batch " << j+ N +1 << " with " << K << " elements:" << endl;
int size = K;
int startb = j*K+N*L;
int endb = size + j*K +N*L;
int *batchArray = new int [size];
for ( int i = 0; i < size; i++)
{
batchArray [i] = Array[i + startb];
}

bubble_sort(batchArray, K);
for (int i=0; i < size; i++)
{
cout << batchArray[i] << endl;
}
delete[] batchArray;
}
}

void bubble_sort(int Array[],int N)
{
int sub=0;
int temp = 0;
int maxSub= N;
char swap='Y';
int lastSwap=0;
while(swap=='Y')
{
swap='N';
sub=0;
while (sub < N-1)
{
if(Array[sub]>Array[sub+1])
{
temp=Array[sub];
Array[sub]=Array[sub+1];
Array[sub+1]=temp;
swap='Y';
lastSwap=sub;
}
sub+=1;
}
}
}



so my problems are...
*I am having problems in indicating the number of students per group
*I am also having problems in two dimensional arrays [It's kinda new to me]
since in every group... the numbers or elements should be numbered randomly too -depending on the number of students in the group [as seen in my example above]. well... *I'm having problems in doing this too.





please help me.




Topic archived. No new replies allowed.