i insert the different id , but the program out with pointer value
anyone know why ???

#define MAX 6
#define size 10

using namespace std;

struct student {
string name;
int id;
string prog;
double cgpa;


class stinfo {
        student data[size];
        int last;
        void add(string name, int id, string prog, double cgpa);
        void printAll(int count);
        void selectionSort(int count);


int min(int a[], int pos){
    int min=99999;
    int i;
    int c;
    for(i =pos; i<MAX;i++){
    return c;

stinfo :: stinfo()
    last = 0 ;

void stinfo::add(string name, int id,string prog, double cgpa)
    if (last == size) {
    return ;
data[last].name = name;
data[last].id = id;
data[last].prog = prog;
data[last].cgpa = cgpa;
}           // all infomation are in data 

void stinfo::selectionSort(int count) 
    int A[size];
    int i,j, temp;
    for (int p=0; p<last; p++)
        A[p]= data[p].id;

     for (i=0; i<MAX; i++)
         j = min(A,i);
            temp = A[j];
            A[j] = A[i];
            A[i] = temp;
        for (int q=0; q<count; q++)

void stinfo::printAll(int count)
    if (last == size){
        return ;

        for (int i =0; i<count; i++)


int main()

    char ans;
    string name1,prog1;
    int id1;
    double cgpa1;
    int count = 0;

    stinfo st;

    cout <<">>>>>  STUDENT INFOMATION RECORDING SYSTEM  <<<<< "<<endl;

    cout <<"A.) Insert NEW Student Record."<<endl
         <<"B.) print all Student Record."<<endl;

    cout <<"Please Choice ONE Option : ";
    cin >>ans;

    switch ( ans )
    case 'a':
    case 'A':
        cout <<endl;
        cout <<">>>>> INSERT NEW STUDENT INFORMATION <<<<<"<<endl;

        cout <<"NAME : ";
        cin >>name1;

        cout <<"ID: ";
        cin >>id1;

        cout <<"PROGRAMME : ";
        cin >>prog1;

        cout <<"CGPA: ";
        cin >>cgpa1;

        st.add ( name1,id1,prog1,cgpa1 );

        cout <<endl
             <<"INSERT COMPLETE... "<<endl
        count ++;

    case 'b':
                                // sort at here

    case 'c':



        default :
        cout <<"Please Try Again..."<<endl

    }while ( toupper(ans) !='F' ) ;

        cout <<"EXIT The Program..."<<endl

    return 0;


You will get a much better response if you improve your questions. Here is how you can improve your questions:

1) Show us the code. You already do this. Good.
2) Tell us exactly what input you type in.
3) Tell us what you saw happen, and what you think should have happened.

  1. system("pause");

Avoid using system calls in your program.
system("PAUSE") is certainly less than ideal. Using a call to system creates a subprocess, which on windows is fairly expensive and in any case not terribly cheap on any operating system.

You may check out the reasons, in details here.

Avoid using system calls in your program.

Too vague, and Walt's rationale (from the link) is largely moot:

  1. "It's not portable." The system() function is inherently non-portable because its argument is dependent on available system console commands. Though it's wise to acknowledge this when choosing to use it, I wouldn't claim portability as a reason to avoid something unless there's an equally good and portable solution. Walt's stated solution is the portable way to simulate the behavior of system("PAUSE"), but it's not equally good because you have to consider extraneous characters in the input stream.

  2. "It's a very expensive and resource heavy function call." That's easily the dumbest reason for avoiding system("PAUSE") if you take half a second to think about what system("PAUSE") does. As an argument against system() in general it's appropriate, but not for system("PAUSE") specifically.

  3. "You must include a header you probably don't need: stdlib.h or cstdlib" Oh no, you must include a standard header that contains commonly used functions and types. The horror! ;) Who is Walt to say that the header isn't needed for other things? Further, if you choose to use the system() function then that header is needed anyway, so it's not really an argument against system(), it's just fluff to make the short list longer.

I'd say avoid using the system() function in favor of a system call that you know won't execute a malicious program of the same name. Walt doesn't address this at all, but it's by far the most persuasive argument against the system() funciton. The problem with stuff like system("PAUSE") is I could easily write a malicious program, call it PAUSE.exe, and put it in a place that ensures your code will run it. Your code will run it with whatever permissions the user running your program has, which could be devastating if you have root permissions.

The problem with system() is that it's inherently insecure. That alone is the only reason you need to avoid it.