Thread: GradeInfo

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    21

    GradeInfo

    I need help to start this program that works with I/O files. I have attached what i got so far and need some help. Where do i go from here?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Next time post the code normally. You shouldn't make us download a program this small.

    Grade System.c:

    Code:
    // Created by <Name Edited>
    // Program: Grade Report
    // Program due 07/14/2008
    
    #include <stdio.h>
    #include <stdlib.h>
    
    int main (void){
        
        int quizzes[6];
        int assignments[4];
        int exams [3];
        double overall_avg;
        double quiz_grade_avg;
        double assign_grade_avg;
        double exam_grade;
        char final_grade [4];
        
        
           					
        FILE* fin;
        FILE* fout;
        
        fin = fopen("input.txt", "r");
        fout = fopen("gradereport.txt", "w");
        
        
        
    
    
    system("PAUSE");
    return 0;
    
    }
    Problem.txt:

    Sample Input File
    10 30 60
    6
    9 10 7 10 17 8
    10 10 10 10 20 10
    4
    98 73 100 44
    100 75 100 50
    3
    87 97 134
    100 100 150













    Sample Output File
    Quizzes
    =======
    Quiz # 1: 9 / 10
    Quiz # 2: 10 / 10
    Quiz # 3: 7 / 10
    Quiz # 4: 10 / 10
    Quiz # 5: 17 / 20
    Quiz # 6: 8 / 10
    -------
    Total Quiz Grade: 61 / 70 = 87.14%

    Assignments
    ===========
    Assignment # 1: 98 / 100
    Assignment # 2: 73 / 75
    Assignment # 3: 100 / 100
    Assignment # 4: 44 / 50
    -------
    Total Assignment Grade: 315 / 325 = 96.92%

    Exams
    =====
    Exam # 1: 87 / 100
    Exam # 2: 97 / 100
    Exam # 3: 134 / 150
    -------
    Total Exam Grade: 318 / 350 = 90.81%

    Overall score: 92.31%
    Final Grade: A
    This program should be pretty simplistic. All you really need to do is process the input file and just act on it as you receive information. The format of the file should be the same, so just focus on reading it.

    Here's one hint: It appears that this problem requires you to use dynamic memory, since it appears that the input file is telling you how many of each type of test you will be processing. This makes it much easier for you, provided you know how to use malloc() and free().

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    21
    I agree, but we have not covered DMAs and malloc so i can not use that.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    You got 4 days to learn it. Start reading.

  5. #5
    Registered User
    Join Date
    Oct 2007
    Posts
    21

    4 days

    How you know i have 4 days ?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by kirksson View Post
    How you know i have 4 days ?
    Because your program says that it's due on the 14th?

    The only real alternative to dynamic memory is to pick a number "big enough" that you know will hold all the values (instead of using 6, 4, and 3 per the example). Perhaps the official assignment sheet has some guidance there.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    To give you an idea of how much work this is, an implementation that meets most requirements could be written in one afternoon, in about 108 lines of code. It would probably take you longer than that and probably more lines of code, but again, you have about 3 days to finish this, so that's not an issue.

    Just make sure you keep working at it, and use all the references and language material at your disposal.

  8. #8
    Registered User
    Join Date
    Oct 2007
    Posts
    21

    Direction

    Well, i need just a direction to start so i can pick up from there. What i understand so far is that:
    1. I need 3 arrays
    2. While loop

    I am not sure how to sort out the input sheet or where to begin, i know YOU can write in in one afternoon but cut me some slack at least, these are my baby steps....idea I need- Yoda.

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by kirksson View Post
    Well, i need just a direction to start so i can pick up from there. What i understand so far is that:
    1. I need 3 arrays
    Are you sure? If you don't know how many numbers there are, how you can make an array to hold it? (Hint: you can't.)

  10. #10
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Yes, I'm willing to cut you some slack, but obviously not actually do the work, so let's go through this assignment a little logically and see if we can work up some ideas for you.

    You have three types of tests:

    1. Quizzes
    2. Assignments
    3. Exams


    If you notice something, they are all technically the same thing. An individual test, no matter what kind of the three it is, for this program is represented by just a score. A score is represented by the mark achieved and the total of that particular test. This must be recorded as two integers. Because of the nature of this, you might want to make a struct to hold it. This struct can represent one type of test of any kind.

    Because of this ability of representing any of the three tests in the same kind of struct, you can actually write very generic code that handles everything here. This might be a little more advanced for you at present, but it greatly simplifies the problem if you can separate the idea of separate tests here and realize that they are technically the same thing, just three ways of going about it.

    So anyway, as far as the input goes, this is how I interpreted it:

    1. The first three ints are actually the weights of the totals of each type of test (ie. final grade = 10% for quizzes, 30% for assignments, and 60% for exams)
    2. For each type of test [quizzes, assignments, and exams]:
      1. The number of tests.
      2. The scores the student achieved on each particular test.
      3. The total of each particular test.


    The way your program could work is generally as follows:

    1. Read the weights.
    2. For each type of test [quizzes, assignments, and exams]:
      1. Read number of tests.
      2. Allocate a block of memory large enough to hold records for each individual test. (ie. in the sample there will be 6 quizzes)
      3. Read in all of the test scores.
      4. Read in all of the test totals.
      5. Calculate the total for that particular test by weight and add it to a double (that was originally init'ed to 0).
      6. Deallocate your block of memory.
    3. Print overall total.
    4. Calculate final letter grade by overall percentage.


    This is more than enough to get you started. Let's see some code here. Get working. You still have time to do a really good job if you work on it right now.

  11. #11
    Registered User
    Join Date
    Oct 2007
    Posts
    21

    How to incorporate fin to fout

    I have this part figured out, now if i scan in "fin" it doe not pull out any data to fout....
    What am i doing wrong or missing...?

  12. #12
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by kirksson View Post
    What am i doing wrong or missing...?
    The reading-in part. You don't ever read the grades in from your input file; how can you then write them out to your output file?

  13. #13
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    First of all, you didn't listen to me, and you're still attaching code instead of posting it.

    Second of all, you're doing the following wrong:

    Code:
    : In function `main':
    :31: warning: int format, pointer arg (arg 3)
    :31: warning: too few arguments for format
    :32: warning: too few arguments for format
    :33: warning: too few arguments for format
    :34: warning: too few arguments for format
    :35: warning: too few arguments for format
    :36: warning: too few arguments for format
    :39: warning: too few arguments for format
    :43: warning: too few arguments for format
    :44: warning: too few arguments for format
    :45: warning: too few arguments for format
    :46: warning: too few arguments for format
    :49: warning: too few arguments for format
    :53: warning: too few arguments for format
    :54: warning: too few arguments for format
    :55: warning: too few arguments for format
    :58: warning: too few arguments for format
    :60: warning: ISO C90 does not support the `&#37;lf' printf format
    :60: warning: too few arguments for format
    :61: warning: int format, pointer arg (arg 3)
    :10: warning: unused variable `tests'
    :11: warning: unused variable `test_avg'
    :11: warning: unused variable `exam_avg'
    :11: warning: unused variable `quiz_avg'
    :11: warning: unused variable `final_avg'
    :13: warning: unused variable `i'
    :14: warning: unused variable `quiz'
    :15: warning: unused variable `assignment'
    :16: warning: unused variable `exam'
    Thirdly:

    Code:
    fprintf(fout,"Quiz # 1:  %d / %d \n",fin);
    Apparently you haven't been writing much code this semester since this just screams ignorance, laziness, or some other such indication that you are probably not using much of your time for this course in a productive manner. That fprintf() format string requires 2 integers to be passed after the string literal, not a FILE *. This is rather basic.

    All in all, I can't say that you will get much of this done in time for tomorrow to hand it in. If you want to pass this course, I suggest you do the following:

    • Crack open your book(s) and start reading.
    • Turn up the warning level on your compiler(s) (ie. -Wall -ansi -pedantic are good flags for GCC/MinGW/etc.).
    • Code.
    • Test yourself by seeing if you can remember simple details of the language. Remembering how to write a printf() statement with various data types, for example, should be handy to know off hand.
    • Code.
    • Start your next assignment early if you have anymore left.
    • Code.
    • Study hard for any tests coming up, and make sure you know the material that the test will be covering.
    • Code.

  14. #14
    Registered User
    Join Date
    Oct 2007
    Posts
    21

    I really need help over here

    Can you at least write some of the code so i can get a clue. We never had to read in the numbers onlu letters, this one is really tough. Trust me, otherwise i would not have post it.
    You can call me lazy but i ve been on this already for 72 hrs and my head is numb.
    If you can help, please do otherwise save me from cheap comments.
    You were once in my shoes i would assume.....now i bow.......

  15. #15
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by kirksson View Post
    Can you at least write some of the code so i can get a clue.
    That is what your professor does in class, I imagine. I provided you an entire layout of how to write the program step by step. All you had to do was translate it from what I wrote to C.

    Quote Originally Posted by kirksson View Post
    We never had to read in the numbers onlu letters, this one is really tough. Trust me, otherwise i would not have post it.
    I doubt the veracity of this, but even so, it doesn't take much to read a number vs a letter. You should have a C textbook handy.

    Quote Originally Posted by kirksson View Post
    You can call me lazy but i ve been on this already for 72 hrs and my head is numb.
    Well, if your head goes numb while writing garbage, I can't imagine the stress you'll be under while trying to write real code.

    My point was about how you wrote code that isn't very close to being valid, and then asked us to tell you what was wrong. If I wrote a somewhat random sentence in English and asked you where I was going wrong with learning English, you probably wouldn't know where to start to even correct me. That is more or less the type of thinking one might see when they look at your code.

    Quote Originally Posted by kirksson View Post
    If you can help, please do otherwise save me from cheap comments.
    You were once in my shoes i would assume.....now i bow.......
    With regards to bowing, you should be bowing before God and praying you pass this course instead of begging us to help you. And even better would be that you pray that you do good with your time in life.

    I have tried to help, but that is the key word. I can only help you. If I write the code for you, I'm not helping. And yes, I was once a pathetic newbie that didn't have a clue about the language, but I learned it by working at it. I didn't learn it from a forum, from begging people to write code for me, or anything else of that nature. I had some resources to learn from, and I took advantage and learned it.

    Your motivation to learn C is nowhere near the level of where it should be. If you can't be motivated to learn, or at least industrious enough to work at it, you will not master it. You should be asking yourself why you're taking the course and what you really want in life in terms of a job if you happen to be in anything CS-related.

    My comments may be harsh sounding to you, perhaps because you might not be used to hearing people be completely honest with you, but if you can look at your situation objectively, I think you will find out what I'm saying can help you in the long run. So think about it. You have to turn your situation around quickly. If you can't write code for a non-pressure assignment, how will you write it during any tests? If you can't write code during the tests, then what? You can't pass the course, and you'll be wasting your time.

Popular pages Recent additions subscribe to a feed