473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help me in developing my print function possible sort function

17
I have been tasked with finishing the following C program. I need to develop the sort by birthday function and the print grade function. I have been working on the print function for the last week and it seems like everything I try doesn't work. I guess I am not understanding how to deal with structures. Please if someone could please help me out I would appreciate it.
Thank you.

Expand|Select|Wrap|Line Numbers
  1.  #include <stdio.h> 
  2.  
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define CLASS_SIZE 2
  7. // maximum class size
  8.  
  9. struct test{
  10. //declare structures
  11.     float quiz1;
  12.     float quiz2;
  13.     float quiz3;
  14.     float average;
  15.     float GP;
  16. };
  17.  
  18. struct date{
  19.  
  20.     int month;
  21.     int day;
  22.     int year;
  23. };
  24.  
  25. struct student_data{
  26.  
  27.     char *last_name;
  28.     int student_id;
  29.     char grade;
  30. };
  31.  
  32.  
  33. void getGrade();
  34. // function prototypes
  35. void sort();
  36. void swapd (struct date *s1, struct date *s2);
  37. void swaps (struct student_data *s1, struct student_data *s2);
  38. void swapt (struct test *s1, struct test *s2);
  39. void prn_student_data();
  40.  
  41. struct student_data *students[CLASS_SIZE];
  42. // structure declarations
  43. struct date dob[CLASS_SIZE];
  44. struct test tests[CLASS_SIZE];
  45.  
  46.  
  47. int main(void)
  48. // begin execution
  49. {
  50.     char temp[30];
  51.     int i;
  52.     float total=0;
  53.  
  54.     printf("\n\n This program will compute, sort by birthday, and
  55. display a\n"    // user prompt
  56.         " students average letter grade, quiz average? and grade
  57. point obtained\n"
  58.         " from 3 quizzes.\n\n");
  59.  
  60.     for(i=0; i<(CLASS_SIZE); i++)
  61. //get student info
  62.     {
  63.         printf("\n\nEnter Student #%d's Last Name: ", i+1);
  64. // user prompt
  65.         scanf("%s", temp);
  66. // user input
  67.         students[i]=(struct student_data*)malloc(sizeof(struct
  68. student_data));    // allocate memory for structure
  69.         students[i]->last_name=(char*)malloc(strlen(temp));
  70. // allocate memory for pointer last name in structure
  71.         strcpy(students[i]->last_name, temp);
  72. // copy from temp to struct member -last name
  73.  
  74.         printf("Enter Students ID Number: ");
  75. //input student ID
  76.         scanf("%d", &students[i]->student_id);
  77.  
  78.         printf("\nEnter Students Birthday (mm/dd/yyyy): \n");
  79. //input birthday info
  80.         printf(" ** Dont forget the forward slashes **: ");
  81.         scanf("%d/%d/%d", &dob[i].month, &dob[i].day, &dob[i].year);
  82.  
  83.         printf("\n\nEnter quiz scores from 0 to 100\n");
  84.         printf("\nEnter score obtained for quiz #1: ");
  85. //input scores from quizzes
  86.         scanf("%f", &tests[i].quiz1);
  87.         printf("\nEnter score obtained for quiz #2: ");
  88.         scanf("%f", &tests[i].quiz2);
  89.         printf("\nEnter score obtained for quiz #3: ");
  90.         scanf("%f", &tests[i].quiz3);
  91.  
  92.         total = (tests[i].quiz1)+(tests[i].quiz2)+(tests[i].quiz3);
  93. //compute quiz total and average
  94.         tests[i].average = (total/3);
  95.         system("cls");
  96.     }
  97.  
  98.     getGrade();
  99. //call functions
  100.     sort();
  101.     prn_student_data();
  102.  
  103.     return 0;
  104. }
  105.  
  106.  
  107. void getGrade()
  108. //grade conversion function
  109. {
  110.     int i;
  111.  
  112.     for(i=0; i<(CLASS_SIZE); i++)
  113.  
  114.     {
  115.         if (tests[i].average >= 90.0)
  116.             students[i]->grade = 'A', tests[i].GP = 4;
  117.         else if (tests[i].average >= 80.0)
  118.             students[i]->grade = 'B', tests[i].GP = 3;
  119.         else if (tests[i].average >= 70.0)
  120.             students[i]->grade = 'C', tests[i].GP = 2;
  121.         else if (tests[i].average >= 60.0)
  122.             students[i]->grade = 'D', tests[i].GP = 1;
  123.         else
  124.             students[i]->grade = 'F', tests[i].GP = 0;
  125.     }
  126. }
  127.  
Sep 29 '06 #1
3 2637
D_C
293 100+
You do not pass any data to the print student function. Since the array that holds all student data is not static, your function has absolutely no idea of knowing where the data is to print. Either you could make the array of student structs static, pass the array (or each entry) by address (and as const too), or you could change the student struct to a class and make a print() method.

Also, in order sort by year, then month, then day, first sort by day, then by month, then by year. Make sure to use a stable sort.
Sep 30 '06 #2
rwise5
17
You do not pass any data to the print student function. Since the array that holds all student data is not static, your function has absolutely no idea of knowing where the data is to print. Either you could make the array of student structs static, pass the array (or each entry) by address (and as const too), or you could change the student struct to a class and make a print() method.

Also, in order sort by year, then month, then day, first sort by day, then by month, then by year. Make sure to use a stable sort.
Do you suggest that I use typedef to do this? I have been reviewing my notes and text book, but seems like I should really get involed with this program.
Thank you and take care.
Oct 6 '06 #3
D_C
293 100+
Look at things in terms of priorities. Using typedef *should* simplify the declaration of data/structs. However, it is not necessary. All the data in your array of student structs is held somewhere in memory. You have to deliver your data to your print function somehow. That is absolutely necessary. There are several things you could do:
  • declare the array as static
  • pass by value each Student struct
  • pass by address each Student struct
  • pass by address the array of Student structs
  • change Student from a struct to a class, and implement a print function
Oct 6 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
12
by: Anthony Jones | last post by:
Just a bit of background: I'm one of a group of FORTRAN programmers, looking to switch to C++. We are trying to write a few simple examples to demonstrate the power of the language to our manager,...
1
by: Rob | last post by:
Hi everyone, I'm having some big JS problems - my function is making my html code vanish, and I need help! Here's the code, try it for yourself. You'll notice that when you click either links...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
5
by: singhm | last post by:
Hi guys so I have a trianlge program having hard time finishing this though, I have to develop a program which is the following: Write a program that will allow the user to enter the 3 lengths...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
3
by: =?ISO-8859-1?Q?Une_B=E9v?==?ISO-8859-1?Q?ue?= | last post by:
Mo <Mehile.Orloff@gmail.comwrote: may be the iteration should be inside your function qryFunc ? or, return $fQuery (when no error) and then : $reponse=qryFunc($select, $from);
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.