#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;
}
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');
}
}
xfreebornx
-23
Light Poster
Recommended Answers
Jump to PostOne, mark your old threads dealing with this question solved so people don't waste time commenting on them there instead of here.
Two, what's the question?
Jump to PostThere is no loop in your main function, so if someone wants to see the changes, he can't.
You could sort the names by making a a loop with i as the index of the array, then just look at array and array [i+1] and see which one should …
Jump to Postthen compare the first character of the name variable of the array
if(array[i].name[0] < array[i+1].name[0]){ // the switching stuff }
Jump to PostI'll try to explain:
you need to see which object comes first in the alphabet
So you compare the first letters of the names, then you determine which one should be first.If the name of object1 is bbbb and object2 is aaaa then you need to switch …
All 13 Replies
VernonDozier
2,218
Posting Expert
Featured Poster
xfreebornx
-23
Light Poster
Tigran
14
Junior Poster in Training
xfreebornx
-23
Light Poster
Tigran
14
Junior Poster in Training
xfreebornx
-23
Light Poster
Tigran
14
Junior Poster in Training
xfreebornx
-23
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
xfreebornx
-23
Light Poster
xfreebornx
-23
Light Poster
VernonDozier
2,218
Posting Expert
Featured Poster
A.Ali
0
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.