#include <iostream>
using namespace std;
struct student
{
int ID;
char name[80];
char nationality[80];
char gender[2];
};
void insert(student array[]);
void sort(student array[]);
int main()
{
student array[100];
int answer;
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;
cin >>answer;
switch(answer)
{
case 1:
insert(array);
break;
case 2:
sort(array);
break;
}
sort(array);
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');
}
}
void sort(student array[])
{
if(array[i].name[0] < array[i+1].name[0])
{
student temp;
strcpy (temp.name, array[i].name);
strcpy (array[i].name, array[i+1].name);
strcpy (array[i+1].name, temp.name);
}
}
xfreebornx
-23
Light Poster
Recommended Answers
Jump to PostIt might help if you actually asked a question instead of just wacking some code online and hope for the best.
Jump to PostCompare and contrast (sorting wise) :
#include<iostream> #include<vector> #include<ctime> //for time.h #include<algorithm> using namespace std; struct Info { int id; char gender; Info() : id(0) , gender(' ') { } Info(int i, char g) :id(i), gender(g) { } }; bool sortByID(const Info& a, const Info& b) { …
Jump to PostI mentioned it in your last thread and Ancient Dragon mentioned it in your previous thread. Don't just post code with a title and no question. Doing that inevitably leads people to think that you simply want people to write it all for you and post it. Ain't gonna happen.
…
All 9 Replies
Nick Evan
4,005
Industrious Poster
Team Colleague
Featured Poster
xfreebornx
-23
Light Poster
mrnutty
761
Senior Poster
VernonDozier
2,218
Posting Expert
Featured Poster
necrolin
commented:
Well said
+1
xfreebornx
-23
Light Poster
mrnutty
761
Senior Poster
xfreebornx
-23
Light Poster
Nick Evan
commented:
26 posts and still no code-tags
-5
VernonDozier
2,218
Posting Expert
Featured Poster
xfreebornx
-23
Light 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.