programing

Student Data txt 파일 내의 데이터를 읽고 학생의 평균을 계산하려면 어떻게 해야 합니까?또한 구조물을 통해 스위치로 전송합니다.

goodsources 2022. 10. 20. 21:22
반응형

Student Data txt 파일 내의 데이터를 읽고 학생의 평균을 계산하려면 어떻게 해야 합니까?또한 구조물을 통해 스위치로 전송합니다.

           //LIBRARIES
       #include <stdio.h>
       #include <stdlib.h>

      #define Size_MainFuncArray 5   // Constant

                              // Data that needs to be inside the StudentData txt file:
                                                 // Jane 55 51 78
      struct Student {                        // Lungelo 69 84 75
         char StudentName[10];                   // Greg 51 44 52
         int StudentMarks[3];                  // Thando 23 78 61
         float StudentAverage;                   // Bret 44 33 29   //  How do I calculate the 
                                                                   //average of them?
        };

        typedef struct Student Student;

    //Function Prototypes
      int DisplayMenu (void);
      void Read_Data (Student Arr[], int Size);
      void Calculate_StudentAverage (Student Arr[], int Size);
      void Display_Data (Student Arr[], int Size);
      void Write_Graph (Student Arr[], int Size);


   // Main Function
   int main (void)
    {
       int choice = 0;
       Student ESG206B[Size_MainFuncArray];

         while( choice != 4 )

         choice = DisplayMenu();
         scanf( "%d", &choice );

         switch( choice ) {
               case 1:
                   Read_Data( ESG206B, Size_MainFuncArray );
                   Calculate_StudentAverage( ESG206B, Size_MainFuncArray );
                   getch();
                   printf("Data successfully loaded from StudentData.txt");
                   printf("\nPress any key to continue...\n");
                   break;

               case 2:
                   Display_Data( ESG206B, Size_MainFuncArray );
                   break;

               case 3:
                   Write_Graph( ESG206B, Size_MainFuncArray );
                   break;

               case 4:
                   printf( "Bye-bye\n" );
                   break;

              default:
                   printf( "Invalid selection\n" );
                   break;
            }

        return 0;
    }

    // Function Definitions
    int DisplayMenu (void)
    {
       int Select;

         printf("************************************\n");
         printf("*    Welcome to Student Stats      *\n");
         printf("*    Student Number: 222895812     *\n");
         printf("************************************\n");

            putchar( '\n' );
            printf("1. Load Data and Calculate Average\n");
            printf("2. Dispaly Student Data\n");
            printf("3. Save Graph\n");
            printf("4. Exit\n");
            printf("Choice: ");
            fflush(stdin);
            scanf("%d", &Select);

            printf("\nPress any key to continue...\n");
            getch();
            system("cls");

         return Select;
    }
    void Read_Data (Student Arr[], int Size)
    {

         FILE *cfPtr;
         if ((cfPtr = fopen("StudentData.txt","r")) == NULL)
             printf("Data successfully loaded from StudentData.txt");
        else
        {
             while (!feof(cfPtr))
            {
             fscanf(cfPtr,"%s\n", Size);
             printf("Student Name: %s", Size);
            }
         }
    }
    void Calculate_StudentAverage (Student Arr[], int Size)
    {

    }
    void Display_Data (Student Arr[], int Size)
    {

    }
    void Write_Graph (Student Arr[], int Size)
    {

    }

/* 따라야 할 흐름 형식

       1. Libraries
       2. Constant variable (#define Size_MainFuncArray 10) 
       3. Structure and Typedef
       4. Function prototypes (1-5) 
       5. Main function 
       a. Variables (Declare all variables needed in the main function at the start 
          of the main function) 

       b. While and Switch
       c. Return 0 (the end of the main function) 
       6. Function definitions 
        a. DisplayMenu

        b. Read_Data: 
  By using a file pointer, read the contents of the text file, “StudentData.txt”. 
  By using an if-statement, make sure the file opened correctly. Use a whilestatement 
  and 
  the feof-function to read the contents of the text file and
  populate the structure array. Use the Size parameter to make your code 
  modular and reusable. No command prompt input or output functions may 

        c. Calculate_StudentAverage
  Use a counter-controlled for loop to calculate the student mark average. 
  The average is calculated by determining the sum of the structure member 
  variable array called, “StudentMarks” and dividing it with 3. No command 
  prompt input or output functions may be used in this function.

        d. Display_Data:
  Use a counter-controlled for loop to display the contents of the structure 
  array parameter. Use appropriate command prompt output to display the 
  needed data.

        e. Write_Grap:

파일 포인터를 사용하여 텍스트 파일 그래프를 "StudentGraph.txt"라는 텍스트 파일에 씁니다.반복 구조에 대해 카운터 제어를 사용하여 구조 배열의 각 요소를 루프합니다.반복 구조에 대해 다른 카운터 컨트롤을 사용하여 각 학생의 별을 표시합니다.각 학생의 별 수를 확인하려면 아래를 참조하십시오.

예:

         StudentAverage = 55.6
              NumberOfStarts =                RoundDown(StudentAverage/10)
              = RoundDown(55.6/10)
              = RoundDown(5.56)
              = 5 Stars

*/

언급URL : https://stackoverflow.com/questions/73598829/how-do-i-read-the-data-inside-the-student-data-txt-file-and-calculate-the-avera

반응형