sort array

so i am new to C+ and i need help understanding and doing an assignment.
Here is the assignment:

Create a class called SortArray;
Your class has a property for an array of size 10. It also has functions or methods. Initialize the array to a set of random integers. Write a function called moveUP that takes the number with the lowest value and moves it to the top of the array (position 0).
It has it written out pretty well for you. Create a class that has an array member of size 10. Either init the array in the constructor or write a function to do it. Then write a function that finds the smallest element of the array, and swap places with the 0th element.
i don't know how to create a class
Paying attention in class generally helps. Anyways:
http://www.cplusplus.com/doc/tutorial/classes/

1
2
3
4
5
6
7
8
9
10
class SortArray
{
    public:
      SortArray();
      void sampleMethod();

    private:
      int sampleMember;

};


Should be enough to get you started.
Hey here's a little reference..."bubble sort algorithm"

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
81
82
#include "iostream"
#include <ctime>
#include <cstdlib>
using std::cout;
using std::endl;

///Sort Array Class
class SortArray
{
    private:
            int randomArrayOfTen[10];
    public:
            void MoveUp();
            void OutputNumbers();
            void GenerateRandomNumbers();
};

int main()
{
    SortArray cSort;
    srand(time(0));

    ///Gets ten random numbers from 1 through 100
    cSort.GenerateRandomNumbers();
    cout<<"The numbers before they are sorted"<<endl;

    ///Outputs The Numbers Before Sorting Them
    cSort.OutputNumbers();
    cout<<endl<<endl;

    ///Sorts Numbers
    cSort.MoveUp();
    cout<<"The numbers after they have been sorted"<<endl;

    ///Outputs Number After They Have Been Sorted
    cSort.OutputNumbers();

    cout<<endl;

    return 0;
}

void SortArray::MoveUp()
{
    int placeHolder;

    for(int g=0; g<10; g++)
    {
        ///Since I am comparing array positions next to eachother I initialize the variable numberAbove to one higher than g
        for(int numberAbove=g+1; numberAbove<10; numberAbove++)
        {
            ///If the number lower in array position is higher in value than number higher in array position...proceed to switch
            if(randomArrayOfTen[g] > randomArrayOfTen[numberAbove])
            {
                ///Puts Lesser Value Into A Placeholder
                placeHolder = randomArrayOfTen[numberAbove];

                ///Puts Bigger Value In Upper Position
                randomArrayOfTen[numberAbove] = randomArrayOfTen[g];

                ///Puts Lesser Value in Lower Position
                randomArrayOfTen[g] = placeHolder;
            }
        }
    }
}

void SortArray::GenerateRandomNumbers()
{
    for(int i=0; i<10; i++)
    {
        randomArrayOfTen[i] = rand() % 100 + 1;
    }
}

void SortArray::OutputNumbers()
{
    for(int j=0; j<10; j++)
    {
        cout<<randomArrayOfTen[j]<<endl;
    }
}

Topic archived. No new replies allowed.