sorting array with respect to name and CGPA

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
0
  #11
Nov 23rd, 2008
I have tried many times but I do able to solve my problem.
please write me how can i begin with structure and cin.getline
for three data(name,gender and age)
the sorting part is simple I try it by bible sort .
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: sorting array with respect to name and CGPA

 
0
  #12
Nov 23rd, 2008
If I understood correctly your question you are asking how to use getline with some member variable of a struct.

Look at this and you should figure out with ease how to finish:
  1. std::string nonMemberString;
  2. nonMemberString = "Some text";
  3. std::cout << std::endl << nonMemberString << std::endl;
  4. std::cout << "Insert some other text" << std::endl;
  5. getline(cin, nonMemberString);

this will store the hard coded string "Some text" into the non member string nonMemberString and print it out, and then will get user input with getline.

On the other hand, we have
  1. struct example {
  2. std::string memberString
  3. someType otherStuff;
  4. };
  5.  
  6. int main(void) {
  7. example myExample;
  8. myExample.memberString = "Some text";
  9. std::cout << std::endl << myExample.memberString << std::endl;
  10. std::cout << "Insert some other text" << std::endl;
  11. // ... now it should be evident how to use getline
  12. return 0;
  13. }

Compare the two and you will sort things out in a blink.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
0
  #13
Nov 24th, 2008
Originally Posted by mrboolf View Post
If I understood correctly your question you are asking how to use getline with some member variable of a struct.

Look at this and you should figure out with ease how to finish:
  1. std::string nonMemberString;
  2. nonMemberString = "Some text";
  3. std::cout << std::endl << nonMemberString << std::endl;
  4. std::cout << "Insert some other text" << std::endl;
  5. getline(cin, nonMemberString);

this will store the hard coded string "Some text" into the non member string nonMemberString and print it out, and then will get user input with getline.

On the other hand, we have
  1. struct example {
  2. std::string memberString
  3. someType otherStuff;
  4. };
  5.  
  6. int main(void) {
  7. example myExample;
  8. myExample.memberString = "Some text";
  9. std::cout << std::endl << myExample.memberString << std::endl;
  10. std::cout << "Insert some other text" << std::endl;
  11. // ... now it should be evident how to use getline
  12. return 0;
  13. }

Compare the two and you will sort things out in a blink.
*********************************************
Please help me I have try As i can but I solve some part from your explanation help me so much
and it is here
#include<iostream.h>
struct student{
char name[20];
char gender;
float cgpa;
};
void main()
{
student data[20];
for(int i=0;i<20;i++)
{
cout<<"enter student name"<<i+1<<endl;
cin>>data[i].name;
cout<<"enter student gender"<<i+1;
cin>>data[i].gender;
cout<<"enter student cgpa"<<i+1;
cin>>data[i].cgpa;
}
}
please I will submitt it tomorrow
so I have to oirder it now
thank you
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
-1
  #14
Nov 24th, 2008
I have been working on it for thee days but I do not come across my broblem
Please help me by writing full program how can I order with respect to students name or CGPA depending on the user interest I try it like this.
#include<iostream.h>
struct student{
char name[20];
char gender;
float cgpa;
};
void main()
{
student data[20];
for(int i=0;i<20;i++)
{
cout<<"enter student name"<<i+1<<endl;
cin>>data[i].name;
cout<<"enter student gender"<<i+1;
cin>>data[i].gender;
cout<<"enter student cgpa"<<i+1;
cin>>data[i].cgpa;
}
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 320
Reputation: cikara21 is an unknown quantity at this point 
Solved Threads: 63
cikara21's Avatar
cikara21 cikara21 is offline Offline
Posting Whiz

Re: sorting array with respect to name and CGPA

 
0
  #15
Nov 24th, 2008
Maybe this can help..
  1. // ..
  2. cin.getline(data[i].name,30);
  3. // ...
Last edited by cikara21; Nov 24th, 2008 at 1:15 pm.
.:-cikara21-:.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
0
  #16
Nov 25th, 2008
I have try it so many times and write the following program but it is still not working as i want to program.
please add some mising program to it .
**************************
#include<iostream>
#include<iomanip>
struct student{
char name[20];
char gender;
int cgpa;
};
using namespace std;
int main()
{
student data[4];
student de;
for(int i=0;i<3;i++)
{
cout<<"enter student "<<i+1<<" name :";
cin>>data[i].name;
cout<<"enter student "<<i+1<<" gender :";
cin>>data[i].gender;
cout<<"enter student "<<i+1<<" cgpa :";
cin>>data[i].cgpa;

}
for(int r=1;r<=4;r++)

for(int j=1;j<=4;j++)
{
int k;
k=strncmp(data[j].name,data[j+1].name,25);
if(k>0)
{
int v;
v=data[j].cgpa;
data[j].cgpa =data[j+1].cgpa;
data[j+1].cgpa =v;
char c;
c=data[j].gender ;
data[j].gender =data[j+1].gender ;
data[j+1].gender =c;
strcpy(de.name,data[j].name);
strcpy(data[j].name,data[j+1].name);
strcpy(data[j+1].name,de.name);
}
}


for(int m=1;m<=4;m++)
{
cout<<"Name "<<data[m].name<<endl;
cout<<"Gender "<<data[m].gender<<endl;
cout<<"CGPA "<<data[m].cgpa<<endl;
}

return 0;

}
how can I modify it?
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
0
  #17
Nov 25th, 2008
Help how can you sort
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,861
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 301
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is online now Online
Roasting Maven

Re: sorting array with respect to name and CGPA

 
0
  #18
Nov 25th, 2008
Originally Posted by sisse56 View Post
Help how can you sort
The art of sorting
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 182
Reputation: mrboolf will become famous soon enough mrboolf will become famous soon enough 
Solved Threads: 18
mrboolf mrboolf is offline Offline
Junior Poster

Re: sorting array with respect to name and CGPA

 
3
  #19
Nov 25th, 2008
Ok, I'll try to be nice:

1 - Don't (repeat: don't) PM for help. I'm not your friend nor your tutor.

2 - Moreover, don't (repeat: don't) ever ask things like "please write for me the full program. ". I was tempted to write on purpose a program full of errors and then send it to you. There's not a single person that has to do you homework except you.

I hope this is clear enough (either it is or not: read the forum rules, all of them)
Also niek_e's signature is a very valid starting point.

Coming back to your program:

1 - Ask specific question. Don't just throw in a piece of code asking things like "How can you sort" or "How can I modify it".

2 - Try something on your own and post it with explanation of what it does and what you expected it to do instead. Include error messages, if any.

3 - If absolutely clueless on where to start, explain what you have considered and why you have discarded that idea(s)

4 - Last but not least: wrap your code in code tags!
Last edited by mrboolf; Nov 25th, 2008 at 7:47 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 12
Reputation: sisse56 has a little shameless behaviour in the past 
Solved Threads: 0
sisse56 sisse56 is offline Offline
Newbie Poster

Re: sorting array with respect to name and CGPA

 
0
  #20
Nov 25th, 2008
I have solved it thank you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC