#include <iostream>
#include<vector>
#include<ctime> 
#include<algorithm>
using namespace std;

struct student
{
  int id;
  char name;
  char nationality;
  char gender;

student() : id(0) , gender(' ') { }
	student(int i, char g) :id(i), name(g) { }  
};

void insert(student array[]);  

bool sortByID(const student& a, const student& b)
{
	return ( a.id < b.id );
}


char sortByName(const student& a, const student& b)
{
	return ( a.name < b.name);
}

char sortByNationality(const student& a, const student& b)
{
	return (a.nationality < b.nationality);
}

void sort(const student& a)
{
	
	cout<<"Welcome to sorting function please do the following[i] = " ;
	cout<<"***************************************************";
	cout << "id : "<<a.id<<"\t"<<"name : "<<a.name<< "nationality: "<<a.nationality<<endl;
}

int main()
{	
	student array[100];
	
	
	cout <<"Welcome to student recording system"<<endl;
	cout <<"Please choose one of the following option"<<endl;
	cout <<"1.Insert new record"<<endl;
	cout <<"2.Delete record"<<endl;
	cout <<"3.Sort record"<<endl;
	cout <<"4.Display record"<<endl;
	
	
	int option = 0;
int quit = -1;
do
{ 
        cout <<"Welcome to student recording system"<<endl;
	cout <<"Please choose one of the following option"<<endl;
	cout <<"1. Insert new record"<<endl;
	cout <<"2. Sort record"<<endl;
    
       cin >> option;

     switch(option)
    {
        case 1:  insert(array);  break;

        case 2: cout<<"you picked sorting\n". 
                     cout<<"Now sorting\n";
                    mySort(array, numberOfElements);
                    cout<<"Sorting done\n";
                    break;
    }

}while(option != quit)


     
     srand( unsigned(time(0)) );
	const int MAX = 4;
	
	student myHouse[MAX];
	
	
	char g[80] = "mfu"; 

	for(int i = 0; i < MAX; i++)
		myHouse[i] = student(rand()%100,g[rand()%3]);

	cout<<"Welcome to sorting function please do the following selection"<<endl;
	cout<<"***************************************************"<<endl;

	cout<<"* 1.Sort by student ID"<<endl;
	std::sort(myHouse,myHouse+MAX,sortByID); 
	

	cout<<"* 2.Sort by student Name"<<endl;
	std::sort(myHouse,myHouse+MAX,sortByName);
	
    cout<<"* 3.Sort by Nationality"<<endl;
    std::sort(myHouse,myHouse+MAX,sortByNationality);
	cout<<"***************************************************"<<endl;
	cout<<"Selection: "<<endl;
	cout<<"\n\n";
     
     
     		 
  insert(array);
  return 0;
}





void insert(student array[])
{
  for(int i=0;i<100;i++)
  {

	  
	cout <<"Enter student ID:"<<endl;
    cin >>array[i].id;
    cin.ignore(100,'\n');
    
    cout <<"Enter student name:"<<endl;
    cin >>array[i].name;
    cin.ignore(100,'\n');
    
    cout <<"Enter student nationality:"<<endl;
    cin >>array[i].nationality;
    cin.ignore(100,'\n');
    
    cout <<"Enter student gender:"<<endl;
    cin >>array[i].gender;
    cin.ignore(100,'\n');
    }
}

Recommended Answers

All 13 Replies

You really aren't the sharpest knife in the shed are you? Why don't you listen to good advice when someone gives it to you?

come on man i check......
i'm new to c++ that's why you see i don't pick up quickly....
pls help me

Let me spell this out for you:

ASK. A. QUESTION.

first i want to link the sort in the main to the 3 sort that i hav created
secondly for the delete option to work in the main......

I have been watching your theads for the last few days, and you really do need to sharpen up and use the great advice that these guys have given you. Throughout your theads you have been given a lot of useful information that you should have incorporated in your program up to this point. It seems as though you are neglecting a good amount of the helpful information that these guys have offered up which is one of the reasons why they are getting frustrated with you.

Similarly, they have told you, time and again, to post an actual question whereas you continue to just post your code and say "tell me how to do this." Even your most recent post: "first i want to link the sort in the main to the 3 sort that i hav created
secondly for the delete option to work in the main......", this is still not a question. It is a statement telling them what you want them to do. Try to rephrase it like so: "I need to do this, here is how I think I should do this: (code). Is this correct? If so, how can I improve on this? If not, what can I do to fix it?"

Everybody is here to help, but only if you show that you're putting in the effort on your end. I'm also new at C++ and you'll see if you look at some of the theads that I've started, everybody has been very helpful when I give them the code, explain what it is supposed to do, what it is actually doing, and ask them a question.

-D

Fixed it a little. Please try the rest on your own, until you really need
help.

#include<iostream>
#include<algorithm> //for std::sort
#include<string>

using namespace std;

struct student
{
  int id;
  string name;
  string nationality;
  string gender; 
};

void insert(student array[],const  unsigned int MAX_STUDENT);  

bool sortByID(const student& a, const student& b)
{
	return ( a.id < b.id );
}


char sortByName(const student& a, const student& b)
{
	return ( a.name < b.name);
}

char sortByNationality(const student& a, const student& b)
{
	return (a.nationality < b.nationality);
}

void mySort(student array[],const unsigned int MAX)
{
	int opt = 0;
	cout<<"Welcome to sorting function please do the following selection"<<endl;
	cout<<"***************************************************"<<endl;
	cout<<"* 1.Sort by student ID"<<endl;
	cout<<"* 2.Sort by student Name"<<endl;
    cout<<"* 3.Sort by Nationality"<<endl;
	cout<<"***************************************************"<<endl;
	cout<<"Selection: ";
	cin >> opt;
	cout<<"\n\n";

	switch(opt)
	{
		case 1: std::sort(array,array+MAX,sortByID); break;
		case 2:	std::sort(array,array+MAX,sortByName); break;
		case 3:	std::sort(array,array+MAX,sortByNationality);break;
	}

}

void display(const student array[], unsigned int MAX);
int main()
{	
	const unsigned int MAX_SIZE = 2;
	student array[MAX_SIZE];

	int option = 0;
	bool exitProgram = false;

	do
	{ 
		cout <<"Welcome to student recording system"<<endl;
		cout <<"Please choose one of the following option\n\n"<<endl;
		cout <<"1.Insert new record"<<endl;
		cout <<"2.Sort record"<<endl;
		cout <<"3.Delete record"<<endl;
		cout <<"4.Display record"<<endl;
		cout <<"0) Exit program\n\n\n";
    
		 cin >> option;

		 switch(option)
		 {
			case 1: insert(array,MAX_SIZE);  break;

			case 2:	cout<<"you picked sorting\n";
					cout<<"Now sorting\n\n\n";
					mySort(array,MAX_SIZE);
					cout<<"Sorting done\n\n\n";
					break;

			case 3: //do delete
			case 4:   display(array,MAX_SIZE); break;

			default : exitProgram = true; break;
		 }

		}while(!exitProgram);     		
	  

	return 0;

}
void insert(student array[],const  unsigned int MAX_STUDENT)
{

	cout<<"\n\n";

  for(unsigned int i = 0 ; i < MAX_STUDENT; i++)
  {

	cout<<"For student #"<<(i+1)<<endl<<endl;;
	cout <<"Enter student ID: ";
    cin >>array[i].id;
    cin.ignore(100,'\n');
	cout<<endl;
    
    cout <<"Enter student name: ";
    cin >>array[i].name;
    cin.ignore(100,'\n');
	cout<<endl;
    
    cout <<"Enter student nationality:  ";
    cin >>array[i].nationality;
    cin.ignore(100,'\n');
	cout<<endl;
    
    cout <<"Enter student gender:  ";
    cin >>array[i].gender;
    cin.ignore(100,'\n');
	cout<<endl;
    }
}

void display(const student array[], unsigned int MAX)
{
	cout<<"\************************************************\\"<<endl;
	for(unsigned int i = 0; i < MAX; i++)
	{		
		cout<<"---------------------------------------------------"<<endl;;
		cout<<"Student #:"<<(i+1)<<endl;
		cout<<"ID# : "<<array[i].id<<endl;
		cout<<"Name : "<<array[i].name<<endl;
		cout<<"Nationality : "<<array[i].nationality<<endl;		
		cout<<"Gender : "<<array[i].gender<<endl<<endl;
		cout<<"---------------------------------------------------"<<endl;;
	
	}
	cout<<"\n\\************************************************\\"<<endl;
}

@firstperson i really appreciate the help
God bless....

@firstperson i really appreciate the help
God bless....

Hope you learn from it. Put comments on the program so its better
and you will learn more.

Hi..i saw this thread randomly..i got some part don't understand:
1)
const unsigned int MAX_SIZE = 2;

student array[MAX_SIZE];

Q: Why MAX_SIZE = 2 ?

2)15: void insert(student array[],const unsigned int MAX_STUDENT);

33: void mySort(student array[],const unsigned int MAX)
55: void display(const student array[], unsigned int MAX);

Q: 1. From the function above, why sometime he use MAX sometime use MAX_STUDENT and MAX_SIZE??
2. Is the function must use "const" / "unsigned int"? Can i just declare like void display( student array[], int MAX);??

That all my questions.LOL..Sry for my stpdity
Hope somebody can answer.

Hi..i saw this thread randomly..i got some part don't understand:
1)
const unsigned int MAX_SIZE = 2;

student array[MAX_SIZE];

Q: Why MAX_SIZE = 2 ?

2)15: void insert(student array[],const unsigned int MAX_STUDENT);

33: void mySort(student array[],const unsigned int MAX)
55: void display(const student array[], unsigned int MAX);

Q: 1. From the function above, why sometime he use MAX sometime use MAX_STUDENT and MAX_SIZE??
2. Is the function must use "const" / "unsigned int"? Can i just declare like void display( student array[], int MAX);??

That all my questions.LOL..Sry for my stpdity
Hope somebody can answer.

Not a problem, but please start your own thread in the C++ section with the same questions rather than continue someone else's thread.

Not a problem, but please start your own thread in the C++ section with the same questions rather than continue someone else's thread.

Okay..thanks ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.