Help me If you want to earn money

Hey guys I have assignment due tomorrow night. Sorry my english limited I dont understand the assignment well.

Here is assignment.

Write a well-documented C++ program named sorter.cpp that sorts an array of randomly selected integers.
Your program will declare an array of 25 integers and then fill the array with random values. The program will first display the unsorted array and pauses. Nest it will sort the array into ascending order and then display the sorted array.
You will fill the array with a separate function so the array will have to be passed to the filler function. Your program will also contain a function that displays an array.
You will create a function that sorts an array using the bubble sort algorithm. One additional function will be necessary to accomplish sorting. You will need a function which your sort routine can call to swap two values when necessary.
You should use the srand() and rand() functions in the C stdlib library to seed the random number generator and extract a pseudo-random number. The prototype for srand() and rand() are shown below:
# include <cstdlib>
int rand ( void );
void srand (unsigned int seed );
Each function you write should be prototyped and have its own header block describing how the function behaves. Don't forget to document all variables in every function. Use only local variables.


and
Bubble Sort Algorithm
LOOP UNTIL NO MORE SWAPS
INITIALIZE SWAP COUNTER
INITIALIZE POSITION INDEX TO START OF ARRAY
LOOP UNTIL END OF ARRAY
IF VALUE AT CURRENT POSITION IS GREATER THAN VALUE AT NEXT POSITION
SWAP VALUES
INCREMENT SWAP COUNTER
END IF
INCREMENT POSITION INDEX
END LOOP
END LOOP



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <cstdlib>
#include <ctime>
#define ASIZE 25
#define SCALE 100
using namespace std;

void fillarray(int a[], int n);
void sortarray(int a[], int n);
void printarray(int a[], int n);
void initialize(int a[]);
int getrandom(int use[]);

int main()
{
int size=ASIZE; /* SIZE FOR ARRAY */
int array[size]; /* ARRAY OF DATA */
fillarray(array, size);
printarray(array, size);
sortarray(array, size);
printarray(array, size);
return 0;
}

/* SORT ARRAY OF SIZE N */
void sortarray(int a[], int n)
{
int r, s, t; /* LOOP ITERATERS */
int tmp; /* FOR SWAPPING */

for (r=n/2; r>0; r/=2) {
for (s=r; s<n; s++) {
tmp = a[s];
for (t=s; t>=r && tmp<a[t-r]; t-=r)
{
a[t] = a[t-r];
}
a[t] = tmp;
}
}
}

/* PRINT ARRAY OF SIZE N */
void printarray(int a[], int n)
{
for (int x=0; x<n; x++)
{
cout << a[x];
if (x<n-1)
cout << ",";
}
cout << "\n";
}

/* FILL ARRAY OF SIZE N WITH RANDOM NUMBER */
void fillarray(int a[], int n)
{
int unique[SCALE]; /* array to make all unique */
initialize(unique);
srand((unsigned long int) time(NULL));
for (int x=0; x<n; x++)
a[x]=getrandom(unique);
}

int getrandom(int use[])
{
int n;
do
n=rand()%SCALE;
while (use[n]==1);
use[n]=1;
return n;
}

/* FILL ARRAY WITH 0 TO GARANTEE UNIQUENESS */
void initialize(int a[])
{
for (int x=0; x<SCALE; x++)
a[x]=0;
}



I tried to do something but I am pretty sure its not rite. So person who help me to finish this must have PAYPAL account so i can send payment and my budge is $25 for this.
Last edited on
Any HELPS?
Sorry bud. I'm only 10, and a beginner soo.... sorry.
I'm not sure why you are creating a unique array and fillin it with zero.
What should I do I dont understand the assignment well.
The bubble sort algorythm just compares two entries at a time and swaps the two in the direction that the list should be sorted.
I sent you PM can you pls check it
Still need help
Except for the array declaration, the program you gave seems correct.
Change the array declaration at line 17 to int array[ASIZE];

I tried to do something but I am pretty sure its not rite.

Why are you so sure that its not correct ?

P.S.: People want to help others who want to learn. No need to pay for that.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <algorithm> // for std::swap()

void sortarray(int a[], int n)
{
    bool swapping = true;

    while (swapping)
    {
        swapping = false;

        for (int i=0; i < n-1; ++i)
            if (a[i] > a[i+1])
            {
                swap(a[i], a[i+1]);
                swapping = true;
            }
    }
}


Close enough. Although the for() loop should be rewritten as a while().
Save your money for buying your evaluator.
Topic archived. No new replies allowed.