Anyone knows C programming thoroughly

Discussion in 'Education & Personal Growth' started by Nriincal, Mar 12, 2015.

  1. Nriincal

    Nriincal Senior IL'ite

    Messages:
    17
    Likes Received:
    13
    Trophy Points:
    18
    Gender:
    Female
    Hi,

    I am learning C programming and I have an assignment to code in C
    the assignment is


    Create a program to calculate letter grade scores for students in a class; the letter grade is based on average of three tests; the program should ask user to enter the maximum score possible for each test. Once the maximum possible score for each test has been entered, the program should prompt for student information:
    Student Information:
    Student’s first name, student’s last name and then scores for each test (each score must be read using a function).
    After score for the 3 tests has been entered, the following output will be displayed: Student Name: First Name, Last Name
    Average Score: Average of the 3 tests, up to 2 decimal points.
    Letter Grade: letter grade is evaluated according to the following table:
    90 or higher A
    80 – 89.99 B
    70 – 79.99 C
    60 – 69.99 D
    Less than 60 F
    The program should then prompt user “Calculate another student grade: (press Y for Yes, press N for No)”:
     If the user input is “Y” or “y”, program should prompt for student information (see above).
     If the user input in “N” or “n”, program should end.
    Test score reading function
    Prompt user to enter score for a test – the function should validate that the score entered is correct:
     Must be positive number
     Cannot be more than the maximum score for the test.


    For e.g. if the maximum score for test 1 is 35, then the valid score is 0 – 35; similarly if maximum score for test 2 is 50, then the valid score is 0 -50.


     If an invalid score has been entered, display an message “Invalid score, the valid range is : “ ; using the example above if I enter, 44 as test 1 score, then message will be “Invalid score, the valid range is 0-35”


    So here to input the test score we need functions.
    If anyone can help me with the algorithm/structure for the code, I mean when to use what...I can try writing the code.

    so far I can't make out the structure of the code

    thank you
     
    Loading...

  2. sha2

    sha2 Senior IL'ite

    Messages:
    31
    Likes Received:
    11
    Trophy Points:
    23
    Gender:
    Female
    ...........
     
  3. Akanksha1982

    Akanksha1982 IL Hall of Fame

    Messages:
    3,633
    Likes Received:
    4,991
    Trophy Points:
    308
    Gender:
    Female
    Not sure how generic you want this to be. But here is something you can do. I am writing pseudo code here. I haven't used c in a long time, but can help you if you need further help.

    #include <stdio.h>

    void readMaxscoresforTest(double *t1, double *t2, double *t3)
    {
    printf("Enter Test1 high score");
    scanf("%f", &t1);
    printf("Enter Test1 high score");
    scanf("%f", &t2);
    printf("Enter Test1 high score");
    scanf("%f", &t3);
    }


    int main()
    {
    double test1score = 0;
    double test2score = 0;
    double test3score = 0;
    double test1highscore;
    double test2highscore;
    double test3highscore;

    char firstname[50];
    char lastname[50];
    char letterGrade;

    readMaxscoresforTest(&test1highscore, &test2highscore, &test3highscore);

    ......
    }

    Is this something you are looking for? If so, i can help you more.
     
    1 person likes this.
  4. Nriincal

    Nriincal Senior IL'ite

    Messages:
    17
    Likes Received:
    13
    Trophy Points:
    18
    Gender:
    Female
    Thank you sha2 and Akansha1982 for the replies.
     
  5. Nriincal

    Nriincal Senior IL'ite

    Messages:
    17
    Likes Received:
    13
    Trophy Points:
    18
    Gender:
    Female
    Akansha thank,you your code is making sense to me.
    There are clarifications in the assignment by our prof...


    1. Instead of asking the first and last name, just ask for the initials as we haven't covered strings in the class yet. So, first name and last name initials as character.


    2. Also average score direction is not clear - it should have been weighted score; Weighted Score = ([Sum of the 3 test scores]/[Sum of maximum score for the 3 tests])*100


    3. Use the weighted score to evaluate the letter grade.




    So here I am assuming the user will enter the max score for all the tests, then the student's first initial and last initial, then and finally individual test scores for the three tests which need to be in a max score range. If invalid data entered then error MSG prompt


    what i am confused about and need help is how to use function here. Our prof said "By read, I mean read the user input ; as the statements to read the test score is the same, using a function to read the test score will minimize the number of statement in the program."


    So pls if you could help me further it will be greatly appreciated. Thank you for your time.
    I am thinking of using else-if for letter grading
    I don't know what loop to use here?
    And the overall format of the code


    So far our course has covered loops, if else-if, function, switch in C programming
     
    1 person likes this.
  6. Nriincal

    Nriincal Senior IL'ite

    Messages:
    17
    Likes Received:
    13
    Trophy Points:
    18
    Gender:
    Female
    I need to submit this assignment by Friday :-(
     
  7. Akanksha1982

    Akanksha1982 IL Hall of Fame

    Messages:
    3,633
    Likes Received:
    4,991
    Trophy Points:
    308
    Gender:
    Female
    #include <stdio.h>


    double ReadTestScore(char* prompt)
    {
    double testscore;
    printf("%s", prompt);
    scanf("%f", &testscore);
    return testscore;
    }


    double ReadIndividualScore(char* prompt, double maxscore)
    {
    double testscore;


    do
    {
    printf("%s", prompt);
    scanf("%f", &testscore);
    if ((testscore < 0) || (testscore > maxscore))
    {
    printf("Invalid Score. Valid Range is %f:%f",0,maxscore);
    }
    } while ((testscore >= 0) && (testscore <= maxscore));


    return testscore;


    }


    char GetLetterGrade(double averageScore)
    {
    if (averageScore >= 90) return 'A';
    if ((averageScore >= 80) && (averageScore < 90)) return 'B';
    if ((averageScore >= 70) && (averageScore < 80)) return 'C';
    if ((averageScore >= 60) && (averageScore < 70)) return 'D';
    if (averageScore < 60) return 'F';

    }


    double RoundAverageTo2Decimal(double average)
    {
    return ((int)(average *100))/100;
    }


    int main()
    {
    double test1score = 0;
    double test2score = 0;
    double test3score = 0;
    double test1highscore;
    double test2highscore;
    double test3highscore;
    double average;
    char nextstudent = 'Y';
    char firstinitial;
    char lastinitial;
    char lettergrade;


    test1highscore = ReadTestScore("Enter Test1 high score");
    test2highscore = ReadTestScore("Enter Test2 high score");
    test3highscore = ReadTestScore("Enter Test3 high score");


    while ((nextstudent == 'Y') || (nextstudent == 'y'))
    {
    printf("Enter student's first initial");
    scanf("%c", &firstinitial);
    printf("Enter student's last initial");
    scanf("%c", &lastinitial);
    test1score = ReadIndividualScore("Enter %c %c test1score", test1highscore);
    test2score = ReadIndividualScore("Enter %c %c test2score", test2highscore);
    test3score = ReadIndividualScore("Enter %c %c test3score", test3highscore);
    average = (test1score + test2score + test3score)/(test1highscore + test2highscore + test3highscore);
    average = RoundAverageTo2Decimal(average);
    lettergrade = GetLetterGrade(average);
    printf("Student Initials %c %c",firstinitial, lastinitial);
    printf("Average Scorer of 3 tests: %f", average);
    printf("Letter Grade: %c", lettergrade);
    printf("Calculate another Student grade: (Press Y for Yes and press N for NO)");
    scanf("%c", &nextstudent);
    }


    }



    Hope this helps. I don't have a C compiler so haven't compiled or run the code. If you are having compiler problems, pm me with the error and i will help out. Good luck.
     
    4 people like this.
  8. VanithaSudhir

    VanithaSudhir Platinum IL'ite

    Messages:
    1,846
    Likes Received:
    3,977
    Trophy Points:
    283
    Gender:
    Female
    Aks,
    You have given her the complete code.. :)
    I think you should encourage her to code and debug herself.

    Just my thoughts. I always make my trainees to code.. however it is.. I used to spend time debugging their code..& reviewing them.along with them. so that they also learn.
    In many instances,.. I have deleted the entire code.. and rewritten..but I wanted to really help them to learn programming :)
     
  9. Nriincal

    Nriincal Senior IL'ite

    Messages:
    17
    Likes Received:
    13
    Trophy Points:
    18
    Gender:
    Female
    Thanks a ton A1982, I am working on it....will get back to you....perhaps you can be my mentor:)
     
  10. Akanksha1982

    Akanksha1982 IL Hall of Fame

    Messages:
    3,633
    Likes Received:
    4,991
    Trophy Points:
    308
    Gender:
    Female
    Writing the first program is very daunting. I remember those days when I was afraid of writing the program. I had a fear that i will spoil the computer and smoke will come out. :rotfl I am sure when she overcomes the hurdle, she will be more confident.
     
    Anvitha and Nriincal like this.

Share This Page