Thread: Student Grading System

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    42

    Student Grading System

    I am doing a grading system where students can login using a given password. Students can choose to change their password. Once logged in, students can view their carry marks and final grades for the subjects they have registered. They can either register for two subjects or only one. The system should be able to withhold data for minimum10 students. This are some of the coding but it cannot run.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    
    
    struct studentData
    {
     	char *name;
     	int matric_no;
     	int username[5];
    	char *password;
    }student={"","","","Student1"};
    
    
    int main()
    { 
    	printf("Enter Student name: \n");
    	scanf("%s",student.name);
    	printf("Enter Student Matric No: \n");
    	scanf ("%d",&student.matric_no);
    	printf("Enter Username:");
    	scanf ("%d",&student.username);
    	printf("Enter Password:");
    	scanf("%s",student.password);
    
    
    	if (student.matric_no<=29999)
    	{
    	printf("Year: 4\n");
    	}
    	else if(student.matric_no>=30000 && student.matric_no<=39999)
    	{
    	printf("Year: 3\n");
    	}
    	else if(student.matric_no>=40000 && student.matric_no<=49999)
    	{
    	printf("Year: 2\n");
    	}
    	else(student.matric_no>=50000 && student.matric_no<=59999);
    	{
    	printf("Year: 1\n");
    	}
    
    
    `	if (strcmp(("Student1",student.password)==0)
    	{
    		print("Course Taken");
    	}
    	else
    	{
    		print("Invalid Password");
    	}
    	
    return 0;   
       
    }

  2. #2
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Why isn't it running?
    What's happening that is unexpected?

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    I corrected the printf statement in Line 47 & 51 but it still doesn't run.

    1>trial 1.c1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(11) : warning C4047: 'initializing' : 'int' differs in levels of indirection from 'char [1]'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(11) : warning C4047: 'initializing' : 'int' differs in levels of indirection from 'char [1]'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(11) : warning C4047: 'initializing' : 'int' differs in levels of indirection from 'char [9]'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(16) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdio.h(306) : see declaration of 'scanf'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(18) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdio.h(306) : see declaration of 'scanf'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(20) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdio.h(306) : see declaration of 'scanf'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(22) : warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
    1> c:\program files (x86)\microsoft visual studio 9.0\vc\include\stdio.h(306) : see declaration of 'scanf'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : error C2198: 'strcmp' : too few arguments for call
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(42) : error C2143: syntax error : missing ')' before '{'
    1>Build log was saved at "file://c:\Users\User\Documents\Visual Studio 2008\Projects\ITP Project student\ITP Project student\Debug\BuildLog.htm"
    1>ITP Project student - 2 error(s), 9 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Lines 8 and 11: You should use a char array instead of a char pointer - otherwise, you'd need to allocate memory before using it.
    Line 10: What is the purpose of the "username" array, and why is it an array of int?
    Line 12: The types in the initialization do not match the types in the struct.
    Line 22: You're trying to read an int into the "username" member, but "username" is an array of int. Again, what is the purpose of "username" - it doesn't appear to be for a name.
    Line 39: There is something on this line that shouldn't be there.
    Line 45: You're missing a closing parenthesis.



    It appears that you banged out a bunch of code and wonder why it isn't compiling.

    Programs should be built up gradually, testing along the way. See here for a great example: A development process

    Your first step should be to create a program that does three simple things:
    1. Declare a struct variable
    2. Assign values to that struct
    3. Print the values in that struct

    Compile that, fix any warnings/errors, and test it. When that's working correctly, add a bit more to the program.

    The second step might be to replace the direct assignment with user input (and still print out the results). When that works, add another piece. And so on.

  5. #5
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    Code:
    #include<stdio.h>#include<stdlib.h>
    #include<string.h>
    
    
    struct studentData
    {
        char name[50];
         int matric_no;
         int username;
        char password[20];
    }student={"NULL",0,0,"Student1"};
    
    
    int main()
    { 
        printf("Enter Student name: \n");
        scanf("%s",student.name);
        printf("Enter Student Matric No: \n");
        scanf ("%d",&student.matric_no);
        printf("Enter Username:");
        scanf ("%d",&student.username);
        printf("Enter Password:");
        scanf("%s",student.password);
    
    
        if (student.matric_no<=29999)
        {
        printf("Year: 4\n");
        }
        else if(student.matric_no>=30000 && student.matric_no<=39999)
        {
        printf("Year: 3\n");
        }
        else if(student.matric_no>=40000 && student.matric_no<=49999)
        {
        printf("Year: 2\n");
        }
        else(student.matric_no>=50000 && student.matric_no<=59999)
        {
        printf("Year: 1\n");
        }
    
    
        if (strcmp(("Student1",student.password)==0))
        {
            printf("Course Taken");
        }
        else
        {
            printf("Invalid Password");
        }
        
    return 0;   
       
    }

  6. #6
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    I still can't run the program. Something wrong again?

    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(37) : error C2143: syntax error : missing ';' before '{'1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int'
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : warning C4024: 'strcmp' : different types for formal and actual parameter 1
    1>c:\users\user\documents\visual studio 2008\projects\itp project student\itp project student\trial 1.c(41) : error C2198: 'strcmp' : too few arguments for call

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > Something wrong again?
    Yes, something is wrong - still.

    else clauses don't have conditional expressions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Apart from else not (supposed to be) having a conditional expression, look closely at where your ( and )'s are in the strcmp

  9. #9
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    Okay, I got the above codes corrected. What about this one? I can run it, though.

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    
    
    struct studentData
    {
        char name[50];
        int id;
        int username;
        char password[20];
    }student={"NULL",0,0,"Lecturer1"};
     
     
    int main()
    {
        FILE *fp;
        int i;
        int noOfStudents;
        fp=fopen("database.txt","a");
    
    
        if(fp == NULL)
        {
            printf("File not found.");
        }
        else
        {
            printf("\nEnter number of students to be stored in the file:"); 
            scanf("%d",&noOfStudents);
    
    
            for(i=0;i<=noOfStudents;i++)
            {    
                printf("Enter student name and matric no");
                scanf("%s%d",student.name,&student.id);
                fprintf(fp,"%s\t%d\n",student.name,student.id);
                fclose(fp);
            }
        }
    return 0;
    }

  10. #10
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    The first set of codes is for students. The second set of codes is for lecturers. Lecturers will input all the data and students will be able to view their carry marks and final grade only. How do I go about doing it? Maybe someone can give me an idea.
    Last edited by nadeera; 12-10-2015 at 02:07 AM.

  11. #11
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    I think you should be using arrays of students, not a single student. But maybe I'm wrong because I haven't seen the assignment specification. It does seem silly to read all the students into a single variable though.

  12. #12
    Registered User
    Join Date
    Oct 2015
    Posts
    42
    This is sort of what I came up with for the lecturer's part.

    Code:
    #include<stdio.h>#include<string.h>
    #include<conio.h>
    
    
    struct lecturerData
    {
        char name[50];
        int username;
        char password[20];
    }lecturer={"NULL",0,0,"Lecturer1"};
      
    struct studentData
    {
        char name[50];
         int id;
    }student={"NULL",0};                                                       
     
    int main()
    {
        printf("Enter Lecturer name: \n");
        scanf("%s",lecturer.name);
        printf("Enter Username: \n");
        scanf ("%d",&lecturer.username);
        printf("Credit:4 \n");
        printf("Enter Password: \n");
        scanf("%s",lecturer.password);
     
         if (strcmp("Lecturer1",lecturer.password)==0)
        {
            printf("STUDENT ASSESSMENT AND GRADE REPORTING SYSTEM\n");
            system("cls");
            Marking_Scheme();
        }
        else
        {
            printf("Invalid Password\n");
            return 0;
        }
     return 0;
    }
     
    void marking_scheme()
    {
            float final_mark, midterm_mark, ltq_mark;
            
            printf("ASSESSMENT FOR COURSE MARKING SCHEME"); 
            printf("Enter weightage for final exam mark(%40): \n");
            scanf("%f",&final_mark);
            printf("Enter weightage for midterm mark(20%-30%): \n");
            scanf("%f",&midterm_mark);
            printf("Enter lab test or quiz weightage(<5%) \n");
            scanf("%f",&ltq_mark);
            //printf("");
     }
    
    
    void database()
    {
        FILE *fp;
        int i;
        int noOfStudents;
        fp=fopen("database.txt","a+");
     
     
        if(fp == NULL)
        {
            printf("File not found.");
        }
        else
        {
            printf("\nEnter number of students to be stored in the file:"); 
            scanf("%d",&noOfStudents);
     
     
            for(i=0;i<=noOfStudents;i++)
            {    
                printf("Enter student name and matric no");
                scanf("%s\t%d\n",student.name,&student.id);
                fprintf(fp,"%s\t%d\n",student.name,student.id);
                fclose(fp);
            }
         }
    
    
    }
    Last edited by nadeera; 12-10-2015 at 11:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Student Marks System
    By Tripswitch in forum C Programming
    Replies: 15
    Last Post: 08-07-2014, 03:42 AM
  2. Replies: 17
    Last Post: 11-16-2013, 06:18 PM
  3. Student record system; file handling
    By dirtyhabit_12 in forum C Programming
    Replies: 2
    Last Post: 02-25-2013, 02:20 AM
  4. Student GPA system problems
    By ShiroiShu in forum C Programming
    Replies: 10
    Last Post: 11-28-2011, 10:55 AM
  5. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 05:32 AM