#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');
}
}
xfreebornx -23 Light Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
xfreebornx -23 Light Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
xfreebornx -23 Light Poster
dgr231 22 Junior Poster in Training
xfreebornx -23 Light Poster
mrnutty 761 Senior Poster
xfreebornx -23 Light Poster
xfreebornx -23 Light Poster
mrnutty 761 Senior Poster
hao001 -7 Newbie Poster
VernonDozier 2,218 Posting Expert Featured Poster
hao001 -7 Newbie Poster
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.