943,649 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1444
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 21st, 2009
0

student grading system

Expand Post »
Project Title : Student Grading System
Purpose : Calculate the grade and sort the student matrix in descending

example Input file : studentsmark.txt
example Output file: studentresult.txt

How the user operate the software:
1) user run the software
2) an interface show on the screen
3) user keyin Input file name (example:studentsmarks.txt)
4) user keyin Output file name (example:studentresult.txt)
5) user select function to calculate and sort
6) Then an output file stored student result generated
7) user can select option to continue another input file or quit the software

Formular:
1) please exam studentsmark.txt and studentresult.txt
2) the result listing in the studentresult.txt must be sort by student matrix
3) Grade : MARKS >= 80 Then A
MARKS >= 75 Then A-
MARKS >= 70 Then B+
MARKS >= 65 Then B
MARKS >= 60 Then B-
MARKS >= 55 Then C+
MARKS >= 50 Then C
MARKS >= 45 Then C-
MARKS >= 40 Then D+
MARKS >= 35 Then D
MARKS < 35 Then E

input file : studentsmark.txt
01234012345678901234567890123456789
0123401234567890123456789012345678901234567890123456789012345678901234567890123456789
No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%)
1 BK20008 4 3 5 18 18
2 BK20002 5 5 4 10 8
3 BK20003 3 4 5 18 10
4 BK20006 4 3 4 20 14
5 BK20005 5 4 3 13 17
6 BK20004 2 5 2 4 16
7 BK20007 3 4 4 21 14
8 BK20001 4 3 5 11 15
9 BK20009 3 2 4 10 10
10 BK20010 4 3 3 23 18

i have written the first part that is to read the file content
but obviously it cannot run

  1. #include <stdio.h>
  2.  
  3.  
  4. void main (void)
  5. {
  6. char matrix[200];
  7. int i, j, num_elem, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
  8. FILE *infile;
  9.  
  10. infile = fopen("studentsmark.txt","r");
  11.  
  12. i=1;
  13.  
  14. while( fscanf(infile,"%d %s %d %d %d %d %d %d",&no[i],&matrix[i], &quiz_1[i], &quiz_2[i], &quiz_3[i], &project[i], &midT[i]) !=EOF) i++;
  15.  
  16. num_elem = i;
  17.  
  18. for(j=1;j<num_elem;j++)
  19. {
  20. printf("%d %s %d %d %d %d %d %d\n",no[j], matrix[i], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
  21. }
  22.  
  23. fclose(infile);
  24.  
  25. }

it only can run if i remove the 1st line and matrix coloum, please tell me what to do..i'm real weak in programming..
Last edited by gseed87; Mar 21st, 2009 at 5:38 pm.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009
Mar 21st, 2009
0

Re: student grading system

Is all this stuff:
  1. 01234012345678901234567890123456789
  2. 0123401234567890123456789012345678901234567890123456789012345678901234567890123456789
  3. No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%)
part of the input file? If so, you have to add some code to read (and ignore) it before trying to read in the real data.

num_elem serves no real purpose, since you already have the value you need in i.

For the student ids, you want an array of strings, not one big string, so change char matrix[200] to char matrix[10][20] . (Perhaps the first dimension should be something bigger than 10 in case there will be more than 10 students.)

Array numbering starts at 0, not 1, so the initial value of i should be 0. Similarly, in the for loop the initial value of j should be 0.

Your fscanf statement and your printf statement both have an extra %d.

In the fscanf parameter list, use matrix[i] (no "&") since matrix[i] is already an address -- it's the address of the ith string -- after you change matrix to a 2-dimensional array as I suggested above.
Reputation Points: 23
Solved Threads: 18
Junior Poster
r.stiltskin is offline Offline
105 posts
since Feb 2009
Mar 22nd, 2009
0

Re: student grading system

thanks, i will try working on it with your suggestion


the input file include

012340123456789012345678901234567890123456789012345678
No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%) )

it only has 1 number line. sry i accidently add extra one line, the number line is for coloum reference
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009
Mar 22nd, 2009
0

Re: student grading system

this is my corrected code

  1. #include <stdio.h>
  2.  
  3.  
  4. int main ()
  5. {
  6. char matrix[20][200];
  7. int i, j, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20];
  8. FILE *infile;
  9.  
  10. infile = fopen("studentsmark.txt","r");
  11.  
  12. i=0;
  13.  
  14. while( fscanf(infile,"%d %s %d %d %d %d %d",&no[i], matrix[i], &quiz_1[i], &quiz_2[i], &quiz_3[i], &project[i], &midT[i]) !=EOF) i++;
  15.  
  16.  
  17.  
  18. for(j=0;j<i;j++)
  19. {
  20. printf("%d %s %d %d %d %d %d\n",no[j], matrix[j], quiz_1[j], quiz_2[j], quiz_3[j], project[j], midT[j]);
  21. }
  22.  
  23. fclose(infile);
  24. }

but i still i am unable to read tis line
No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%)

what should i add to make the program read it and ignore it so i can read on the real data i need, i really have no idea...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009
Mar 22nd, 2009
0

Re: student grading system

There are many ways to do this. Probably getc or fgetc would be the simplest for you. Look at a reference for stdio.h functions, for example this one, to see how to use those functions: http://www.cplusplus.com/reference/clibrary/cstdio/

By the way, it seems to me that you also have to get rid of the line
  1. 012340123456789012345678901234567890123456789012345678
I don't understand what purpose that line serves, but you certainly don't want to read it into any of your existing variables. You can use the same function, e.g. getc , to take care of both header lines.
Reputation Points: 23
Solved Threads: 18
Junior Poster
r.stiltskin is offline Offline
105 posts
since Feb 2009
Mar 22nd, 2009
0

Re: student grading system

thanks again, i will try

  1. 012340123456789012345678901234567890123456789012345678

this line is for column reference, that is what told by my lecturer..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009
Mar 22nd, 2009
0

Re: student grading system

Click to Expand / Collapse  Quote originally posted by gseed87 ...
code]012340123456789012345678901234567890123456789012345678[/code]

this line is for column reference, that is what told by my lecturer..
Yes, you said that already, but it still makes no sense to me for that to be in the input file. Surely, the program doesn't need that to figure out which data is in which column of the file. A file doesn't actually have columns at all -- it is just a continuous stream of bytes representing characters which we interpret as rows and columns based on the location of newline characters, blank space characters, etc.

So, if your assignment requires that to be in the file, I assume your instructor's intention was simply for you to learn how to write a program that can handle an input file in which different lines are formatted differently. And unless you have some other information that you haven't posted, the program doesn't have to use the data in those first two lines, but still must read them in order to get to the "real" data that follows.
Reputation Points: 23
Solved Threads: 18
Junior Poster
r.stiltskin is offline Offline
105 posts
since Feb 2009
Mar 22nd, 2009
0

Re: student grading system

Well, it donst make any sense of the input file that your trying to read with regards to the student grade information. If I was you, i would go your lecture and speak about on how the input file should be read. And how the file had been formatted with reference to the student grade information.

If you know that, then it makes it ease to read the chucks of the file where each chuck would be the information about one student!

-ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Mar 23rd, 2009
0

Re: student grading system

now my program able to read the input file, i add some code written by other forumer, but i could'nt understand how it actually run..looks like it skips the first 2 line and read the rest...

  1. #include <stdio.h>
  2.  
  3.  
  4. void main (void)
  5. {
  6. char matrix[20][200], line[100][100];
  7. int i, j, x, no[20], quiz_1[20], quiz_2[20], quiz_3[20], project[20], midT[20], final[20];
  8. FILE *infile;
  9.  
  10. infile = fopen("studentsmark.txt","r");
  11.  
  12. x=0;
  13. while (fgets(line,100,infile)!=NULL)
  14. {
  15.  
  16. x++;
  17. if(x==1)
  18. {
  19.  
  20. }
  21.  
  22. else{
  23. i=0;
  24. while( fscanf(infile,"%d %s %d %d %d %d %d %d",&no[i],matrix[i], &quiz_1[i], &quiz_2[i], &quiz_3[i], &project[i], &midT[i], &final[i]) !=EOF)
  25.  
  26.  
  27.  
  28. printf("%d %s %d %d %d %d %d %d\n",no[i], matrix[i], quiz_1[i], quiz_2[i], quiz_3[i], project[i], midT[i], final[i]);
  29. i++;
  30.  
  31.  
  32.  
  33.  
  34. }
  35.  
  36. }
  37. fclose(infile);
  38. }

this is the code i add

  1. int x = 0;
  2. while (fgets(line,100,infile)!=NULL)
  3. {
  4. x++;
  5. if(x==1)
  6. {
  7. }
  8. else{
  9. }
  10.  
  11. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009
Mar 23rd, 2009
0

Re: student grading system

this is the actual file i need to read..

  1. 0123401234567890123456789012345678901234567890123456789012345678901234567890123456789
  2. No Matrix quiz1(5%) quiz1(5%) quiz1(5%) Proj(25%) MidT(20%) Final(40%)
  3. 1 BK20008 4 3 5 18 18 36
  4. 2 BK20002 5 5 4 10 8 30
  5. 3 BK20003 3 4 5 18 10 35
  6. 4 BK20006 4 3 4 20 14 36
  7. 5 BK20005 5 4 3 13 17 28
  8. 6 BK20004 2 5 2 4 16 10
  9. 7 BK20007 3 4 4 21 14 32
  10. 8 BK20001 4 3 5 11 15 31
  11. 9 BK20009 3 2 4 10 10 20
  12. 10 BK20010 4 3 3 23 18 22
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gseed87 is offline Offline
6 posts
since Mar 2009

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: Alien numbers problem
Next Thread in C Forum Timeline: execute some code just before stopping program using CTRL-C





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


Follow us on Twitter


© 2011 DaniWeb® LLC