Data Structure Skills Examination System

Keywords: C Windows ascii REST Excel

Through one month's efforts, the data structure skills examination system was finally implemented in C++ language (including C language interpolation). The greatest advantage of the system is that it can detect whether students have inserted U disk when answering questions, and open auxiliary tools such as word and notebook. This system is divided into two parts, one is student-side, the other is teacher-side.

The student end is mainly the student input the student number and name (to test it). According to the ASCII code 8 corresponding to the last four digits of the student number, the result of the problem extraction can be achieved (also can be improved to IP reading questions). Two questions can be selected from the question bank and one question can be answered randomly. After the completion of the answer, the selected questions can be selected to avoid the situation that will not be done after the selection of the questions. The countdown time is 60 minutes. If the timeout is over, the maximum allowable time is 20 minutes. After the answer, the program and encrypted student information can be sent to the teacher automatically.

The function of the teacher end is to get the students'files, open their CPP and information files in turn, and input the results, and finally generate the students' performance forms. Reduced the need to go to the students to watch the program, record the results of the trouble.

 

Some considerations of the system are as follows:

  1. The files need to be placed in the folder of the D-disk data structure skills examination. The folder contains a folder named Ti and the TXT text of xuehao and xingming. The Ti folder contains test questions in the naming format of 1.txt,2.txt, etc. xuehao releases the student's school number and the student's name.
  2. The cpp file generated by the student side needs to be opened manually. If it is reopened during the period, the countdown starts again.
  3. If the student side detects the U disk, word and so on, it will shield the questions, and then the examination can be continued only after it is legal.
  4. Teachers need to change the new candidate information file in the D-disk data structure skills examination folder into a shared mode.
  5. Once the number of students read by the teacher is fixed, the system will read the corresponding number from beginning to end, regardless of the upload time.

 

Student ends:

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<time.h>
#include<string.h>
#include <fstream>
#include<conio.h>
#include<Windows.h>
# define NORMAL_SIZ BUFSIZ 
#define CHMSK_KEY 0xa5
char buf[NORMAL_SIZ]; 
using namespace std;



//Display the test content on the screen 
int duquwenben(string a)
{
      FILE *fp;
          fp=fopen(a.c_str(),"r");
          char buf[1024];
          while((fgets(buf,1024,fp))!=NULL)
          {
                 
             printf("%s",buf);
          }
		  printf("\n");
		  return 0;
}




//Read Driver State 
int GetDriverInfo(LPSTR szDrive)
	  {
		  UINT uDriverType;
		  uDriverType = GetDriveType(szDrive); 
		  if(uDriverType==DRIVE_REMOVABLE) return 1;
		  else return 0;                                                                                          
	 }


//Determine whether there is a U disk insertion
int checkUdisk()
{
	CHAR szLogicDriveStrings[1024];
	PCHAR szDrive;
	GetLogicalDriveStrings(1023,szLogicDriveStrings); 
	szDrive = (PCHAR)szLogicDriveStrings;
   for(int i=0;i<7;i++) 
   {
   	if(GetDriverInfo(szDrive)) return 1;
	szDrive += (lstrlen(szDrive)+1);
   }
   return 0;
}

//Determine whether to open word, PPT and notepad 
int checkTask()
{
	string temp1,temp2,temp3;
	temp1="tasklist | find ";
	temp2=temp1+"\"WINWORD\" "+"> 1.txt";
	system(temp2.c_str());
	temp2=temp1+"\"POWERPNT\" "+">> 1.txt";
	system(temp2.c_str());
	temp2=temp1+"\"note\" "+">> 1.txt";
	system(temp2.c_str());
	ifstream test;
	test.open("1.txt");
	while(!test.eof())
	{
		test>>temp3;
		if(temp3.length()>3)
		{
			return 1; 
			break;
		}
		
	}
	test.close();
	return 0;	
} 



//Store students'related content in xinxi text document 
void xinxi(){
	FILE *fp=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","w+");
	fprintf(fp,"%s","d:\\Data Structure Skills Examination\\");
	fclose(fp);
}
 
//Login interface and determine whether it conforms to information  
void denglu1(char b[]){
	
	FILE *fp=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","w+");
	FILE *fq=fopen("d:\\Data Structure Skills Examination\\xingming.txt","r");
	char m[4],ch,s[100];
	int i=0,k=0,n,x=0,y,len;
//	m1[0]='\n';		
	printf("Please enter your name.:");	
	for(int v=0;v<3&&k==0;v++){
		gets(b);
		fclose(fq);
		FILE *fq=fopen("d:\\Data Structure Skills Examination\\xingming.txt","r");

		 while(fgets(s,100,fq) != NULL){
		 len = strlen(s);
		 s[len-1] = '\0';
		 if(strcmp(b,s)==0){
			 fputs(b,fp);
			 k=1;
			 break;
		 }
	 }

		if(k==0&&v<2)
		printf("Please re-enter:");
	}
	fclose(fp);
	fclose(fq);
	if(k==0)
		exit(0);

}


//Log on to the student number interface and determine if it meets the information  
void denglu2(char c[]){
	FILE *fp=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","a+");
	FILE *fq=fopen("d:\\Data Structure Skills Examination\\xuehao.txt","r");
	char m[4],ch,s[100];
	int i=0,k=0,n,x=0,y,len;		
	printf("Please enter your student number.:");	
	for(int v=0;v<3&&k==0;v++){
		gets(c);
		fclose(fq);
		FILE *fq=fopen("d:\\Data Structure Skills Examination\\xuehao.txt","r");

		 while(fgets(s,100,fq) != NULL){
		 len = strlen(s);
		 s[len-1] = '\0';
		 if(strcmp(c,s)==0){
			 fprintf(fp,"\n");
			 fputs(c,fp);
			 k=1;
			 break;
		 }
	 }

		if(k==0&&v<2)
		printf("Please re-enter:");
	}
	fclose(fp);
	fclose(fq);
	if(k==0)
		exit(0);
}




//Draw questions according to the student's school number 
int chuti(int a ){
	
	int b;
	a=a%8;
	b=a+10;
	FILE *fp=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","a+");
    string	tempIdd;
	string tempId="d:\\Data Structure Skills Examination\\Ti\\1.txt";
	fprintf(fp,"\n");
	
	fprintf(fp,"%s","The questions the students took were:");
	printf("\n The questions are:%d Title and paragraph%d topic\n",a+1,b+1);
	fprintf(fp,"%s","The first");
	fprintf(fp,"%d",a+1);
	fprintf(fp,"%s","Title and paragraph");
	fprintf(fp,"%d",b+1);
	fprintf(fp,"%s","topic");
	fprintf(fp,"\n");
	switch(a){
	case 0:
		tempId="d:\\Data Structure Skills Examination\\Ti\\1.txt";
		break;
	case 1:
		tempId="d:\\Data Structure Skills Examination\\Ti\\2.txt";break;
	case 2:
		tempId="d:\\Data Structure Skills Examination\\Ti\\3.txt";break;
	case 3:
		tempId="d:\\Data Structure Skills Examination\\Ti\\4.txt";break;
	case 4:
		tempId="d:\\Data Structure Skills Examination\\Ti\\5.txt";break;
	case 5:
		tempId="d:\\Data Structure Skills Examination\\Ti\\6.txt";break;
	case 6:
		tempId="d:\\Data Structure Skills Examination\\Ti\\7.txt";break;
	case 7:
		tempId="d:\\Data Structure Skills Examination\\Ti\\8.txt";break;
	case 8:
		tempId="d:\\Data Structure Skills Examination\\Ti\\9.txt";break;
	case 9:
		tempId="d:\\Data Structure Skills Examination\\Ti\\10.txt";break;
	case 10:
		tempId="d:\\Data Structure Skills Examination\\Ti\\11.txt";break;
	case 11:
		tempId="d:\\Data Structure Skills Examination\\Ti\\12.txt";break;
	case 12:
		tempId="d:\\Data Structure Skills Examination\\Ti\\13.txt";break;
	case 13:
		tempId="d:\\Data Structure Skills Examination\\Ti\\14.txt";break;
	case 14:
		tempId="d:\\Data Structure Skills Examination\\Ti\\15.txt";break;
	case 15:
		tempId="d:\\Data Structure Skills Examination\\Ti\\16.txt";break;
	case 16:
		tempId="d:\\Data Structure Skills Examination\\Ti\\17.txt";break;
	case 17:
		tempId="d:\\Data Structure Skills Examination\\Ti\\18.txt";break;
	}
	duquwenben(tempId);
	
	
	printf("***********************************************************      \n");   
	switch(b){
	case 0:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\1.txt";
		break;
	case 1:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\2.txt";break;
	case 2:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\3.txt";break;
	case 3:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\4.txt";break;
	case 4:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\5.txt";break;
	case 5:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\6.txt";break;
	case 6:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\7.txt";break;
	case 7:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\8.txt";break;
	case 8:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\9.txt";break;
	case 9:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\10.txt";break;
	case 10:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\11.txt";break;
	case 11:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\12.txt";break;
	case 12:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\13.txt";break;
	case 13:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\14.txt";break;
	case 14:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\15.txt";break;
	case 15:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\16.txt";break;
	case 16:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\17.txt";break;
	case 17:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\18.txt";break;
	}
	duquwenben(tempIdd);

	if(checkUdisk()){
		printf("No insertion u disc,Please unplug and try again\n"); 
		while(checkUdisk())
			Sleep(1);
		
	}


	fclose(fp);
//	system(f);
	return 0;
}



//If there are exceptions during the period, the title will be redisplayed 
int chongchuti(int a){
	int b;
	a=a%8;
	b=a+10;
	string tempId,tempIdd;
	tempId="d:\\Data Structure Skills Examination\\Ti\\1.txt";
	
	printf("\n The questions are:%d Title and paragraph%d topic\n",a+1,b+1);
	switch(a){
	case 0:
		tempId="d:\\Data Structure Skills Examination\\Ti\\1.txt";
		break;
	case 1:
		tempId="d:\\Data Structure Skills Examination\\Ti\\2.txt";break;
	case 2:
		tempId="d:\\Data Structure Skills Examination\\Ti\\3.txt";break;
	case 3:
		tempId="d:\\Data Structure Skills Examination\\Ti\\4.txt";break;
	case 4:
		tempId="d:\\Data Structure Skills Examination\\Ti\\5.txt";break;
	case 5:
		tempId="d:\\Data Structure Skills Examination\\Ti\\6.txt";break;
	case 6:
		tempId="d:\\Data Structure Skills Examination\\Ti\\7.txt";break;
	case 7:
		tempId="d:\\Data Structure Skills Examination\\Ti\\8.txt";break;
	case 8:
		tempId="d:\\Data Structure Skills Examination\\Ti\\9.txt";break;
	case 9:
		tempId="d:\\Data Structure Skills Examination\\Ti\\10.txt";break;
	case 10:
		tempId="d:\\Data Structure Skills Examination\\Ti\\11.txt";break;
	case 11:
		tempId="d:\\Data Structure Skills Examination\\Ti\\12.txt";break;
	case 12:
		tempId="d:\\Data Structure Skills Examination\\Ti\\13.txt";break;
	case 13:
		tempId="d:\\Data Structure Skills Examination\\Ti\\14.txt";break;
	case 14:
		tempId="d:\\Data Structure Skills Examination\\Ti\\15.txt";break;
	case 15:
		tempId="d:\\Data Structure Skills Examination\\Ti\\16.txt";break;
	case 16:
		tempId="d:\\Data Structure Skills Examination\\Ti\\17.txt";break;
	case 17:
		tempId="d:\\Data Structure Skills Examination\\Ti\\18.txt";break;
	}
	duquwenben(tempId);
	
	
	printf("***********************************************************      \n");   
	switch(b){
	case 0:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\1.txt";
		break;
	case 1:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\2.txt";break;
	case 2:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\3.txt";break;
	case 3:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\4.txt";break;
	case 4:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\5.txt";break;
	case 5:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\6.txt";break;
	case 6:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\7.txt";break;
	case 7:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\8.txt";break;
	case 8:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\9.txt";break;
	case 9:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\10.txt";break;
	case 10:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\11.txt";break;
	case 11:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\12.txt";break;
	case 12:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\13.txt";break;
	case 13:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\14.txt";break;
	case 14:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\15.txt";break;
	case 15:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\16.txt";break;
	case 16:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\17.txt";break;
	case 17:
		tempIdd="d:\\Data Structure Skills Examination\\Ti\\18.txt";break;
	}
	duquwenben(tempIdd);
	return 0;

}




//Documents that generate student information will be encrypted 
void jiami(){
	FILE *fp = fopen("d:\\Data Structure Skills Examination\\xinxi.txt", "rb+");  
    int n;  
      
    while ((n = fread(buf, 1, NORMAL_SIZ, fp)) > 0)  
    {  
        int i;  
         
        for (i = 0; i < n; i++)  
        {  
            buf[i] ^= CHMSK_KEY;  
        }  
          
        if (fseek(fp, -n, SEEK_CUR) == -1)  
        {  
            perror("fseek");  
        }  
          
        n = fwrite(buf, 1, n, fp);  
        fflush(fp);//If this sentence is not added, then if the file size is smaller than the library function buffer (default is BUFSIZ size), the actual write operation is not written in, resulting in the next read or success, so the program will not exit.  
        buf[0] = 0;  
    }  
	
    fclose(fp);  
}


//Countdown time, 1 hour 
void daojishi(int a,int m[0],int sec[0]){
	m[0]=59,sec[0] = 59;
    printf("\n");
	while(m[0]>=0){
		sec[0] = 59;
    while(sec[0] > 0)
    {
        if(_kbhit())
            break;
            
        printf("\r%2d:%2d",m[0],sec[0]);
        Sleep(1000);
        sec[0]--;
        if(sec[0]%10==0){
		
		if(checkUdisk()){
			system("cls");
			while(checkUdisk()){
			Sleep(1);
			
			printf("No insertion u disc,Please unplug and try again\n");
			system("cls");
			}
			chongchuti(a);
			printf("       Remaining time");
		}
		if(checkTask())
	{
		system("cls");
		while(checkTask()) {
			Sleep(1);
			printf("Prohibition of use word,ppt,txt file,Please login again after closing\n"); 
			system("cls");
			
		}
		chongchuti(a);
		printf("       Remaining time");
		
	}
}
	

		

	
    } 
    if(_kbhit())
            break;
//    printf("***%d\n",m[0]);
//    printf("***%d\n",sec[0]);
    if(m[0]==0&&sec[0]==1)
		break;

	
	m[0]--;
	
	
	}
/*    if(sec > 0)
    {
        system("cls");
        //print_jiayou();
    }
    else
        printf("\n Overtime! "";*/
    
  //  getchar();
  if(m[0]!=0&&sec[0]!=1)
	 getchar();

    


}


//If more than an hour, a maximum of 20 minutes overtime is allowed. 
void chaoshi(int a,int m1[0],int sec1[0]){

	m1[0]=19,sec1[0] = 59;
    printf("\n");
	while(m1[0]>=0){
		sec1[0] = 59;
    while(sec1[0] > 0)
    {
        if(_kbhit())
            break;
          printf("\r%2d:%2d",m1[0],sec1[0]);
            printf("      timeout\n");
	
        Sleep(1000);
        sec1[0]--;
        if(sec1[0]%10==0){
		
		if(checkUdisk()){
			system("cls");
			while(checkUdisk()){
			Sleep(1);
			
			printf("No insertion u disc,Please unplug and try again\n");
			system("cls");
			}
			chongchuti(a);
			printf("       timeout");
		}
		if(checkTask())
	{
		system("cls");
		while(checkTask()) {
			Sleep(1);
			printf("Prohibition of use word,ppt,txt file,Please login again after closing\n"); 
			system("cls");
			
		}
		chongchuti(a);
		printf("       timeout");
		
	}
}
	

		

	
    } 
    if(_kbhit())
            break;
//    printf("***%d\n",m[0]);
//    printf("***%d\n",sec[0]);
    if(m1[0]==0&&sec1[0]==1)
		break;

	m1[0]--;

	}
/*    if(sec > 0)
    {
        system("cls");
        //print_jiayou();
    }
    else
        printf("\n Overtime! "";*/
    
  //  getchar();
  if(m1[0]!=0&&sec1[0]!=1)
	 getchar();
	


}








int main(){
	char a[10000];
	int b[10],c[2];
	char d[4],e[14];
	char g[20];
	char f[12];
	char s[25];
	int n,x=0,l;
	int m[1],sec[1];
	int m1[1],sec1[1];
	xinxi();
	FILE *fx=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","r+");
	fgets(f,25,fx);
	fclose(fx);
	/*Check if there is a U disk and related files open*/ 
	if(checkUdisk()){
		printf("No insertion u disc,Please unplug and try again\n"); 
		while(checkUdisk())
			Sleep(1);	
	}
	if(checkTask()){
		printf("Prohibition of use word,ppt,txt file,Please close and try again\n"); 
			while(checkTask())
			Sleep(1);
	}

	/*Login interface*/ 
	system("cls");
	denglu1(e);
	denglu2(d);
	int mg=d[10]+d[11]+d[12]+d[13];//Get the student's number 


	//cpp file for student number generation 
	FILE *fc=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","r+");
	if(checkUdisk()){
		printf("No insertion u disc,Please unplug and try again\n"); 
		while(checkUdisk())
			Sleep(1);
		
	}
	fgets(s,25,fc);/*Read the first line to array s with fgets*/
	n=strlen(s);	
	x +=n;
	fseek(fc,x+1,SEEK_SET);/*Move the file pointer to the next line*/
	fgets(s,25,fc);/*Read the second line to array s with fgets*/
	for(int v=0;v<15;v++){
		f[20+v]=s[v];
	}
	f[34]='.';
	f[35]='c';
	f[36]='p';
	f[37]='p';
	f[38]='\0';
	fflush(stdin);
	FILE *mv=fopen(f,"w+");
	fclose(mv);
	fclose(fc);
	if(checkUdisk()){
		printf("No insertion u disc,Please unplug and try again\n"); 
		while(checkUdisk())
			Sleep(1);
		
	}
	
	
	
	
	
	
	chuti(mg);//Draw questions
	/*Countdown begins*/ 
	printf("\n The exam starts in 60 minutes. Now there is the rest.:");
	daojishi(mg,m,sec);
	m[0]=59-m[0];
	sec[0]=59-sec[0];
	if(m[0]==0&&sec[0]==58)//If the countdown has not stopped, the timeout time is automatically recorded 
		chaoshi(mg,m1,sec1);
	else{
		m1[0]=19;
		sec1[0]=59;
	}
	if(sec[0]==59){
		m[0]++;
		sec[0]=0;
	}
	m1[0]=19-m1[0];
	sec1[0]=59-sec1[0];
	if(sec1[0]==59){
		m1[0]++;
		sec1[0]=0;
	}
	fflush(stdin);
	//Enter the selected title 
	FILE *fg=fopen("d:\\Data Structure Skills Examination\\xinxi.txt","a+");
	printf("Please enter the selected title.:");
	scanf("%d",&l);
	while(l!=mg%8+1&&l!=mg%8+11){
		printf("Please enter the selected title.:");
		scanf("%d",&l);
	}
	fprintf(fg,"%s","The Title chosen by the students is ____________:");
	fprintf(fg,"%d",l);
	fprintf(fg,"\n");
	fprintf(fg,"%s","The time for students to do the exercises is:");
	fprintf(fg,"%d",m[0]);
	fprintf(fg,"%s",":");
	fprintf(fg,"%d",sec[0]);
	fprintf(fg,"\n");
	fprintf(fg,"%s","Students overtime for problem solving:");
	fprintf(fg,"%d",m1[0]);
	fprintf(fg,"%s",":");
	fprintf(fg,"%d",sec1[0]);
	fclose(fg);
	
	//Upload to LAN Classroom End 
	string teachIp="\\\\172.17.1.41\\Examinee information";
	string sss(f);
	string dosStr2="copy "+sss+" "+teachIp;
	if(system(dosStr2.c_str())!=0){
		printf("Upload failed, please upload manually");
		puts(f);
	}
	else 
		printf("Upload success\n");
	f[34]='.';
	f[35]='t';
	f[36]='x';
	f[37]='t';
	f[38]='\0';

	jiami();//Generate student information file and encrypt it 
	rename( "d:\\Data Structure Skills Examination\\xinxi.txt",f);
	fclose(fc);
	string ddd(f);
	string dosStr="copy "+ddd+" "+teachIp;
	if(system(dosStr.c_str())!=0){//Failure to upload, prompt manual upload and file location 
		printf("Upload failed, please upload manually");
		puts(f);
	}
	else 
		printf("Upload success\n");
	Sleep(30000);
	return 0;

}

 

 

 

Teacher:

#include<stdio.h>
#include<string.h>
#include<io.h>
#include <stdlib.h>
#include<time.h> 
#include<windows.h>
#include<iostream>
#include<conio.h> 
#include<string.h>
#define NORMAL_SIZ BUFSIZ    
#define CHMSK_KEY 0xa5
using namespace std;
char buf[NORMAL_SIZ];
#define number 300 // / number of rows imported    


//Read text content 
int duquwenben(string a)
{
      FILE *fp;
          fp=fopen(a.c_str(),"r");
          char buf[1024];
          while((fgets(buf,1024,fp))!=NULL)
          {
                 
             printf("%s",buf);
          }
		  printf("\n");
		  return 0;
}


//Decrypting the Student-side Information 
void jiemi(char a[]){
	
	FILE *fp = fopen(a,"rb+");  
    int n;  
      
    while ((n = fread(buf, 1, NORMAL_SIZ, fp)) > 0)  
    {  
        int i;  
         
        for (i = 0; i < n; i++)  
        {  
            buf[i] ^= CHMSK_KEY;  
        }  
          
        if (fseek(fp, -n, SEEK_CUR) == -1)  
        {  
            perror("fseek");  
        }  
          
        n = fwrite(buf, 1, n, fp);  
        fflush(fp);//If this sentence is not added, then if the file size is smaller than the library function buffer (default is BUFSIZ size), the actual write operation is not written in, resulting in the next read or success, so the program will not exit.  
        buf[0] = 0;  
    }  
  
    fclose(fp);





}

//Get the number of students dynamically until the conditions are met 
int presencename(){
	system("dir d:\\Data Structure Skills Examination\\Examinee information\\*.cpp /b > d:\\Data Structure Skills Examination\\Examinee information\\cpp.dat");	
	FILE *fp=fopen("d:\\Data Structure Skills Examination\\Examinee information\\cpp.dat","r");
	char m[4],ch,s[100];
	int i=0,k=0,n,x=0,y,len,b;
	string note="d:\\Data Structure Skills Examination\\Examinee information\\cpp.dat";
	printf("Please enter the number of students.:");	
	scanf("%d",&b);
	while(1){
    	 if(_kbhit())
            break;
		 i=0;
		 fclose(fp);
		 system("dir d:\\Data Structure Skills Examination\\Examinee information\\*.cpp /b > d:\\Data Structure Skills Examination\\Examinee information\\cpp.dat");	
		 FILE *fp=fopen("d:\\Data Structure Skills Examination\\Examinee information\\cpp.dat","r");
		 while(fgets(s,100,fp) != NULL){
		 	len = strlen(s);
		 	s[len-1] = '\0';
		 	i++;
		 	if(i>=b)
		 		break;
		}
		 duquwenben(note);
		 printf("The number of students is now:%d\n",i);
		 if(i==b)
		 	break;
		 Sleep(10000);
		 system("cls");
	}
	getchar();
	return b;
}

	
//Read the student information, open. cpp and related information files in turn, and enter the results.	
void read(int num){
	/*Put the file name of the student's information in a txt file*/
	system("dir d:\\Data Structure Skills Examination\\Examinee information\\*.cpp /b > d:\\Data Structure Skills Examination\\Examinee information\\cpp1.dat");
 	char str[50]={"d:\\Data Structure Skills Examination\\Examinee information\\"},str1[num][30],date[number][11],str2[50];
 	double price[number][6];
 	float z ;
 	char f[40],m[1],n[15],v[7];;
 	FILE *in,*fp,*fq;
 	char ch;
 	int j;
 	in=fopen("d:\\Data Structure Skills Examination\\Examinee information\\cpp1.dat","r");
 	if(in==NULL){//If the generated new file fails, exit the system 
  		printf("can't open the file999.");
  		exit(0);
 	}
 	/*Excel file to generate student's grade, named student's grade*/
 	fq=fopen("d:\\Data Structure Skills Examination\\Student achievement.csv","w+");
	fprintf(fq,"%s","Full name");
	fprintf(fq,",");
	fprintf(fq,"%s","Student ID");
	fprintf(fq,",");
	fprintf(fq,"%s","achievement");
	fprintf(fq,"\n");
	fclose(fq);
 	for(int i=0;i<num;i++){	
		fflush(stdin);
		fq=fopen("d:\\Data Structure Skills Examination\\Student achievement.csv","a+");
  		fscanf(in,"%s",&str1[i][0]);
  		strcat(str,&str1[i][0]);
		system(str);//Open the student's cpp file 
		for( j=0;str[j]!='\0';j++);
		strcpy(str2,str);
		str2[j-1]='t';
		str2[j-2]='x';
		str2[j-3]='t';
		jiemi(str2);
		system(str2);//Open the student's txt file 
		fflush(stdin);
		fp=fopen(str2,"r");
		int k=0;
		fflush(stdin);
		fread(m,7,1,fp);
		m[6]='\0';
		fflush(stdin);
		fprintf(fq,m);//Write in the student's name 
		fflush(stdin);
		fclose(fq);
		fq=fopen("d:\\Data Structure Skills Examination\\Student achievement.csv","a+");
		fprintf(fq,",");
		fread(n,14,1,fp);
		n[14]='\0';
		fprintf(fq,"'");
		fprintf(fq,n);//Write in student number 
   		for(int i=0;i<number;i++){
    		fscanf(fp,"%s",&date[i][0]);
    		for(j=0;j<6;j++)
     			fscanf(fp,"%lf",&price[i][j]);
		}
   		fclose(fp);
   		fclose(fq);
   		fflush(stdin);
  		printf("Please enter your score.:");
  		scanf("%f",&z);
  		fq=fopen("d:\\Data Structure Skills Examination\\Student achievement.csv","a+");
		fprintf(fq,",");
  		fprintf(fq," %f",z);//Write in students'grades 
  		fprintf(fq,"\n");
		fclose(fq);
  		strcpy(str,"d:\\Data Structure Skills Examination\\Examinee information\\");
 	}
 	fclose(in);
}	

int main(){

    read(presencename());//Automatic access to files and input 
	return 0;


}			


	
	

 

 

 

If you have any questions, you are welcome to point out.

Posted by briant on Wed, 20 Mar 2019 17:15:27 -0700