943,754 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 2026
  • C RSS
Apr 19th, 2007
0

Hospital Record.. double array.. help

Expand Post »
Hi everyone... again me... My new project is harder
project wants to you how many records do you want to enter (easy part) surname name years doctor and illness. then asks to you 3 choices.
1- ascend surname
2- ascend doc
3- descend year
... and I guess I cant think wright way... anyway... my questions are.....
*-I can find biggest year I can make it descending but how can I put it with other arrays together??
*- How can the project recognize which letter is first?? is it first a or b? how can I find it and again how can I write... (surname and doctors name..)
*- is that way true or am I completly wrong way??????
please help.......


  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct myType{
  4. char sname[20];
  5. char name[20];
  6. double old;
  7. char doc[20];
  8. char ill;
  9. }table;
  10. int main(){
  11. int i,j,a,b,k;
  12. double big=0;
  13. printf("Please give the number of data records:\n");
  14. scanf("%d",&a);
  15. table table1[a];
  16. printf("Please give %d patient records in the form:\n",a);
  17. printf("sname---name---y.o.b.---doc---ill:\n");
  18. for (i=0;i<a;i++){
  19. scanf("%s %s %lf %s %s",
  20. &table1[i].sname,
  21. &table1[i].name,
  22. &table1[i].old,
  23. &table1[i].doc,
  24. &table1[i].ill
  25. );}
  26. printf("Please give a sort order code according to menu:\n");
  27. printf(" Surname ascending : 1\n");
  28. printf(" Doctor ascending : 2\n");
  29. printf(" Year-of-birth descending : 3\n");
  30. scanf("%d",&b);
  31. while(b<=3){
  32. switch(b){
  33. //Surname ascending
  34. case 1 :
  35. break;
  36. //Doctor ascending
  37. case 2 :
  38. break;
  39. //Year-of-birth descending
  40. case 3 :
  41. for(k=0;k<a;k++){
  42. if(table1[k].old>=big)
  43. big=table1[k].old;
  44. }
  45. break;}}
  46. if(b>3){
  47. printf("Just enter 1,2 or 3\n");}
  48.  
  49.  
  50.  
  51. system("PAUSE");
  52. return 0;
  53. }
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 19th, 2007
0

Re: Hospital Record.. double array.. help

input for example can be like that....
surname name year-of-birth doctor illness
Can Murat 1976 Cerrarioğlu cancer
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis

if we choose 3 outpu should be
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis
Can Murat 1976 Cerrarioğlu cancer

I can make it (descending)1979-1977-1976 but how can I write whole line.....
and if I chose 1or 2 output should be (choose=1)
Can Murat 1976 Cerrarioğlu cancer
Kaya Osman 1979 Altınel cancer
Pelin Mine 1977 Peyter osteoporosis

how can I make it c recognize that "can" should before than "kaya" ??????
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 19th, 2007
0

Re: Hospital Record.. double array.. help

last question I heard some bubblesort thing.. what is it.. is it suitable for me???
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 19th, 2007
0

Re: Hospital Record.. double array.. help

last question I heard some bubblesort thing.. what is it.. is it suitable for me???
yes jerry, it would be very suitable for you. you would enter the struct (with name, year, doctor, illness as member variables) into an array and use a bubble sort (not the best sort unless you have only a handful of records; but probably the easiest one to learn as your first sort) to sort on the required field.
note: use the strcmp function to compare strings, < or > operator would do for the year (number). try googling on "bubble sort" "C" "tutorial" and see what comes up.
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Apr 19th, 2007
0

Re: Hospital Record.. double array.. help

ok I am on it thnx......
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 20th, 2007
0

Re: Hospital Record.. double array.. help

Anyone to help me??? I couldnt undertstand strcmp properly and I am stuck now I have to finish it this sunday please help...... I need advice lots of advices
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 20th, 2007
0

Re: Hospital Record.. double array.. help

strcmp() compares two strings and returns an integer that indicates whether string1 is less than string2, the same as string2, or greater than string2. For example
  1. char string1[] = "John";
  2. char string2[] = "Mary";
  3.  
  4. int n = strcmp(string1, string2); // 0 return value means the two strings are the same

As vijayan mentioned the bubble sort is the easiest to code and use. There are hundreds of examples if you learn to use google. Just read any of these links.
Last edited by Ancient Dragon; Apr 20th, 2007 at 10:58 am.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Apr 20th, 2007
0

Re: Hospital Record.. double array.. help

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)
Last edited by jerryseinfeld; Apr 20th, 2007 at 11:09 am.
Reputation Points: 8
Solved Threads: 0
Junior Poster in Training
jerryseinfeld is offline Offline
55 posts
since Apr 2007
Apr 20th, 2007
0

Re: Hospital Record.. double array.. help

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)
  1. char john[] = "john" ;
  2. char mary[] = "mary" ;
  3. int result = strcmp( john, mary ) ;
  4. if( result < 0 ) cout << john << " should be before " << mary << '\n' ;
  5. else if( result > 0 ) cout << john << " should be after " << mary << '\n' ;
  6. else /* result == 0 */ cout << john << " compares equal to " << mary << '\n' ;
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Apr 20th, 2007
0

Re: Hospital Record.. double array.. help

ok thats what I said... in here we can find same amount of words. But I dont want to find same word.. I want to find which one is first? I mean how can program recognize the john should be before than mary?? because it starts j which is before than m(mary)
If you only have two names then vijayan's previous answer will do. But if you have an array of names or structures then use the bubble sort previous mentioned (twice) to arrange the names in alphabetical order, then the first name in the list will be the name you will want.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Can Templates Have prototypes ?
Next Thread in C Forum Timeline: How random is random?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC