Thread: Suggestions for a programming assignment.

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    6

    Suggestions for a programming assignment.

    I'm trying to write program using classes to create a grade book.

    This is what I have so far:

    Code:
    #include <stdio.h>
    
    
    void addGrade(float grades[],int counter);
    void removeGrade(float grades[],int counter);
    void sortGrade(float grades[],int counter);
    void printGrade(float grades[],int counter);
    void findMinMax(float grades[],int counter);
    void calcAverage(float grades[],int counter);
    
    
    main()
    {
        float grades[15]={87,69,98,48};
        int counter=4;
        int option;
        //Main Menu 
        do
        {printf("Select one of the options:\t");
        scanf("%d",&option);
        fflush(stdin);
        switch(option)
        {
            case 1:     //add Grades
                printf("Add Grades\n");
                addGrade(grades,counter);
                break;
            case 2://Remove Grades
                printf("Remove Grades\n");
                removeGrade(grades,counter);
                break;
            case 3://Sort Grades
                printf("Sort Grades\n");
                sortGrade(grades,counter);
                break;
            case 4://Print Grades
                printf("Print Grades\n");
                printGrade(grades,counter);
                break;
            case 5://Find Max Min
                printf("Find Max/Min Grades\n");
                findMinMax(grades,counter);
                break;
            case 6://Calculate Average
                printf("Calculate Average\n");
                calcAverage(grades,counter);
                break;
            case 7:
                printf("Bye Bye Mr. American Pie!\n");
                break;
                    
        }while(option!=7);
    void addGrade(float grades[],int counter);
    {
        //Calculate the number of free locations
        int number=15-counter;
        //get number of grades from user
        int numbgrade;
        //get grades
        int i;
        for(i=0;i<numbgrade;i++)
            scanf("%f",&grades[counter+numbgrade+i]);
        counter=counter+numbgrade;
    }
    void removeGrade(float grades[], int counter);
    {
        int number;//get index number of grades
        scanf("%d",&number);
        printf("Are you sure to remove %f\n",grades[number]);
        printf("yes or no\n");
        int i;
        for(i=number;i<14;i++)
        grades[i]=grades[i+1];
        //validation of that number
        //remove grade
    }
    void sortGrade(float grades[],int counter);
    {
        //bubble sort grades
    }
    void printGrade(float grades[],int counter);
    {
        int x;
        for(x=0;x<15;x++);
        printf("%f %d",grades, counter);
    }
    void findMinMax(float grades[],int counter);
    {
        //find min max in slides
    }
    void calcAverage(float grades[],int counter);
    {
        //calculate average
    }
    The ones with comment sections ares the ones I will be filling the codes in. I'm trying to figure out how to write my remove function. Thank you in Advance. Note: If it is vague I will try to post the actual question from my assignment.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    A few observations

    1) Get out of the habit of leaving main()'s return type off. Yes, compilers accept it. For people, it is bad practice for several reasons. People are more important than compilers.

    2) Don't use fflush(stdin). Ever. fflush() has undefined behaviour for any input stream. There is a FAQ somewhere on this site with information about realistic alternatives.

    3) At a guess, your remove function will need to shuffle array elements (e.g. if element 3 is removed, shuffle elements 4 .... to the left.).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-26-2009, 08:54 AM
  2. Programming font suggestions
    By gin in forum Tech Board
    Replies: 2
    Last Post: 07-03-2008, 09:43 AM
  3. Replies: 12
    Last Post: 05-23-2006, 11:49 PM
  4. Help with Programming Assignment
    By JHaney in forum C++ Programming
    Replies: 18
    Last Post: 11-08-2005, 03:45 AM
  5. Suggestions Please: Gameboy Programming
    By Dirty Harry in forum Game Programming
    Replies: 2
    Last Post: 08-14-2002, 10:15 AM