diff --git a/1.cpp b/1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6030ec7030f114dc1771000bb6866bbaa6bca03c --- /dev/null +++ b/1.cpp @@ -0,0 +1,287 @@ +#include +using namespace std; +#include +#include +#include +#include +#include +#include + + +#define CLRSCR system("cls") +#define PRINT_TITLE "\n序号\t考号\t\t姓名\t语文\t数学\t英语\t总分\n" +#define PRINT_FORMAT "%d\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",i,p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define WRITE_FORMAT "%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define READ_FORMAT "%s %s %lf %lf %lf %lf",&p->stu.num,&p->stu.name,&p->stu.Chinese,&p->stu.math,&p->stu.English,&p->stu.count_score + +//定义学生类 +class student +{ +public: + char num[9]; + char name[7];//三个汉字长度为6个字节,应多定义一个字节来存放字符串结束符'\0' + double Chinese; + double math; + double English; + double count_score; +}; + +//定义单链表类 +class node +{ +public: + student stu; + node *next; +}; + +int MySelect(node * head,node *temp) +{ + int i=0; + node *p,*tp=temp; + p=head->next; + FILE *fp; + char file[15]="English.txt"; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + + + while (NULL!=p) + { + if(p->stu.English>100&&p->stu.count_score>300) + { + node *end; + end = (node *)malloc(sizeof(node)); + tp->next=end; + tp=end; + tp->next=NULL; + tp->stu=p->stu; + + if(i==0) + printf (PRINT_TITLE); + i++; + printf(PRINT_FORMAT); + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%lf\t%lf\t%lf\t%lf",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + + } + p=p->next; + } + fclose(fp); + if(i==0) + printf("\n\t英语超过100分且总分成绩超过300分的学生人数为零\n"); + return i; +} + + + +void Fprintf(node *head) +{ + char file[15]="student.txt"; + FILE *fp; + if((fp=fopen(file,"w"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); +} +void InsertSort(node *head)//总分从大到小排序 +{ + node *p,*q,*u,*h,*w,*n; + int j=0; + p=head->next; + while(p!=NULL) + { + j++; + p=p->next; + } + for(int i=0;inext; + for(int z=0;z<=j-2-i;z++) + { + int y=0; + if((q->next->stu.count_score)>(p->next->stu.count_score)) + { + n=q->next; + u=n->next; + w=p->next; + p->next=n; + n->next=w; + q->next=u; + p=p->next; + y=1; + } + if(y==0) + { + p=p->next; + q=q->next; + } + } + } +} + + +void FscanfFromFile(node *head) +{ + char file[20]="student1.txt"; + FILE *fp; + if((fp=fopen(file,"r"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head; + while(!feof(fp)) + { + node *end; + end = (node *)malloc(sizeof(node)); + p->next=end; + p=end; + p->next=NULL; + fscanf(fp,READ_FORMAT); + } + printf("\n\t信息导入成功\n"); + + + InsertSort(head); + Fprintf(head); + fclose(fp); +} + +void ShowList(node *head)//带头结点的链表 +{ + node *p=head->next; + int i=0; + printf ("\t\t\t成绩汇总排序表\n"); + printf (PRINT_TITLE); + while(NULL!=p ) + { i++; + printf (PRINT_FORMAT); + p=p->next; + } + +} + +void FprintfToFile(node *head) +{ + char file[15]; + + printf("\n输入要写入的文件名:"); + scanf("%s",file); + + FILE *fp; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%lf\t%lf\t%lf\t%lf",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); + printf("\n\t数据写入成功\n",file);//printf输出双引号要用转义字\" + +} + + +node *ClearList(node *head) +{ + node *p=head->next; + while(NULL!=p) + { + node *tp=p->next; + free(p); + p=tp; + } + return head->next=NULL; + +} + + + + + +int main() +{ + + node *head; + int i=0; + head = (node *)malloc(sizeof(node)); + strcpy(head->stu.num," "); + strcpy(head->stu.name," "); + head->stu.Chinese=0; + head->stu.math=0; + head->stu.English=0; + head->stu.count_score=0; + node *temp= (node *)malloc(sizeof(node));//保存查找结果的头结点 + + + + printf("欢迎使用\n"); + printf("\n----------------------------------------------\n"); + + + FscanfFromFile(head); + + + + + char charget; + + do + { + printf("\n----------------------------------------------\n"); + printf("\n[1]信息显示\n"); + printf("[2]挑选\n"); + printf("[3]退出程序\n"); + do + { + charget=getch(); + }while((charget!='1')&&(charget!='2')&&(charget!='3')); + + switch(charget) + { + case '1': ShowList(head); + printf("\n按任意键显示上层操作菜单\n"); + getch(); + break; + case '2': MySelect(head,temp); + printf("\n按任意键显示上层操作菜单\n"); + getch(); + break; + }//end switch,结束操作 + + + + }while(charget!='3'); + +return 0; +} \ No newline at end of file diff --git a/2.cpp b/2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..759ff1421e84a9edaa52f748881da5fd232365df --- /dev/null +++ b/2.cpp @@ -0,0 +1,551 @@ + +#include +using namespace std; +#include +#include +#include +#include +#include +#include + +#define CLRSCR system("cls") +#define PRINT_TITLE "\n序号\t考号\t\t姓名\t语文\t数学\t英语\t总分\n" +#define PRINT_FORMAT "%d\t%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",i,p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define WRITE_FORMAT "%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf\n",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define READ_FORMAT "%s %s %lf %lf %lf %lf",&p->stu.num,&p->stu.name,&p->stu.Chinese,&p->stu.math,&p->stu.English,&p->stu.count_score +#include + +string DoubleToString(double d) +{ + //Need #include + using namespace std; + string str; + stringstream ss; + ss<>str; + return str; +} +//定义学生类 +class student +{ +public: + char num[9]; + char name[7];//三个汉字长度为6个字节,应多定义一个字节来存放字符串结束符'\0' + double Chinese; + double math; + double English; + double count_score; +}; + +//定义单链表类 +class node +{ +public: + student stu; + node *next; +}; +int MySelect(node * head,node *temp) //返回查找到符合条件的项目数 +{ + int equal,N; + char CHAR[10]; + + + printf("----------------------------------------------\n\n"); + printf("查找模式:1是相等查找,0是不相等查找\n"); + printf("列名编号:1是考号,2是姓名,3是语文成绩,4是数学成绩,5是英语成绩,6是总分\n"); + printf("\n--------------------------------------------\n"); + + do + { + printf("\n选择查找模式:"); + equal=getche(); + if((equal!='1')&&(equal!='0')) + printf("\n\t输入错误\n"); + }while((equal!='1')&&(equal!='0')); + equal=equal-48; + + + + do + { + printf("\n输入列名编号:"); + N=getche(); + if(N!='1'&&N!='2'&&N!='3'&&N!='4'&&N!='5'&&N!='6') + printf("\n\t输入错误\n"); + }while(N!='1'&&N!='2'&&N!='3'&&N!='4'&&N!='5'&&N!='6'); + switch(N) + { + case '1': N=0;break;//N为字节数 + case '2': N=9;break; + case '3': break; + case '4': break; + case '5': break; + case '6': break; + } + + + + printf("\n输入关键字:"); + scanf("%s",CHAR); + + int i=0,flag; + node *p,*tp=temp; + p=head->next; + + while (NULL!=p) + { + if(N==0||N==9) + { + flag=strcmp((char *)p+N,CHAR);//(char *)p+N为指针位置,比较每一条记录中的考号、姓名等数据是否与输入的关键字相同 + if((abs(flag)+equal)==1)//当equal为1时是相等查找,为0时是不相等查找;当abs(flag)为0时,数据与关键字相同,若为1则不同 + { + node *end; + end = (node *)malloc(sizeof(node)); + tp->next=end; + tp=end; + tp->next=NULL; + tp->stu=p->stu; + + if(i==0) + printf (PRINT_TITLE); + i++; + printf(PRINT_FORMAT); + } + p=p->next; + + } + + else + { + cout.precision(6); + if(N=='3') + { + flag=strcmp( (DoubleToString(p->stu.Chinese).c_str()),CHAR ); + } + + if(N=='4'){ + flag=strcmp( (DoubleToString(p->stu.math).c_str()),CHAR ); + } + + if(N=='5'){ + flag=strcmp( (DoubleToString(p->stu.English).c_str()),CHAR ); + } + + if(N=='6'){ + flag=strcmp( (DoubleToString(p->stu.count_score).c_str()),CHAR ); + } + + if(flag==0)//当equal为1时是相等查找,为0时是不相等查找;当abs(flag)为0时,数据与关键字相同,若为1则不同 + { + node *end; + end = (node *)malloc(sizeof(node)); + tp->next=end; + tp=end; + tp->next=NULL; + tp->stu=p->stu; + + if(i==0) + printf (PRINT_TITLE); + i++; + printf(PRINT_FORMAT); + } + p=p->next; + } + + } + + if(i==0) + printf("\n\t没有查找到符合条件的信息\n"); + +return i; +} + +int SelectScore(node * head) +{ + char CHAR[10]; + + + printf("----------------------------------------------\n\n"); + printf("请输入考号:\n"); + scanf("%s",CHAR); + + int i=0,flag; + node *p; + p=head->next; + + while (NULL!=p) + { + flag=strcmp((char *)p,CHAR);//比较每一条记录中的考号是否与查询的考号相同 + if(flag==0) + { + if(i==0) + printf (PRINT_TITLE); + i++; + printf(PRINT_FORMAT); + } + p=p->next; + + } + + if(i==0) + printf("\n\t没有查找到相应考号的信息\n"); + +return i; +} + + +void InsertSort(node *head)//总分从高到低排序 +{ + node *p,*q,*r,*u; + p=head->next; + head->next=NULL; + while(p!=NULL) + { + r=head; + q=head->next; + + while(q!=NULL&&((q->stu.count_score)>(p->stu.count_score))) + { + r=q; + q=q->next; + } + u=p->next; + p->next=r->next; + r->next=p; + + p=u; + } +} + +void CheckNum(node *head) +{ + /*删除学号重复的条目*/ + node *release,*p; + p=head->next; + int m=0; + while(NULL!=p->next) + { + node *p2=p; + + while(NULL!=p2->next) + { + if(0==strcmp(p->stu.num,p2->next->stu.num)) + { m++; + if(m==1) + printf("\t\t以下条目因考号与前面的信息冲突而没有导入\n"); + + printf("%s\t%s\t%lf\t%lf\t%lf\t%lf",p2->stu.num,p2->stu.name,p2->stu.Chinese,p2->stu.math,p2->stu.English,p2->stu.count_score); + + release=p2->next; + p2->next=p2->next->next; + free(release); + } + p2=p2->next; + } + + p=p->next; + } + + +} + +void Fprintf(node *head) +{ + char file[15]="student.txt"; + FILE *fp; + if((fp=fopen(file,"w"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%.1lf\t%.1lf\t%.1lf\t%.1lf",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); +} +void FscanfFromFile(node *head) +{ + char file[20]="student1.txt"; + FILE *fp; + if((fp=fopen(file,"r"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head; + while(!feof(fp)) + { + node *end; + end = (node *)malloc(sizeof(node)); + p->next=end; + p=end; + p->next=NULL; + fscanf(fp,READ_FORMAT); + } + printf("\n\t信息导入成功\n"); + + + InsertSort(head); + Fprintf(head); + fclose(fp); +} + +void ShowList(node *head)//带头结点的链表 +{ + InsertSort(head); + node *p=head->next; + int i=0; + printf ("\t\t\t成绩汇总排序表\n"); + printf (PRINT_TITLE); + while(NULL!=p ) + { i++; + printf (PRINT_FORMAT); + p=p->next; + } + +} + +void FprintfToFile(node *head) +{ + char file[15]; + + printf("\n输入要写入的文件名:"); + scanf("%s",file); + + FILE *fp; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%lf\t%lf\t%lf\t%lf",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); + printf("\n\t数据写入成功\n",file);//printf输出双引号要用转义字\" + +} + + +node *ClearList(node *head) +{ + node *p=head->next; + while(NULL!=p) + { + node *tp=p->next; + free(p); + p=tp; + } + return head->next=NULL; + +} + +int AddStu(node *head) +{ + cout<<"共需输入多少位学生信息?"<>i; + int u=1; + do + { + node *p,*p2=head,*p3; + p=(node *)malloc(sizeof(node)); + cout<<"请依次输入第"<1) + { + cout<<" 按y继续添加,按其他键停止添加\n\n"<>p->stu.num>>p->stu.name>>p->stu.Chinese>>p->stu.math>>p->stu.English; + p->stu.count_score = p->stu.Chinese + p->stu.math + p->stu.English; + int flag=0; + p2=head; + while(NULL!=p2->next) + { /*找出第一个比新学生的考号大的位置,将新信息放在它前面*/ + if((flag=strcmp(p->stu.num,p2->next->stu.num))<0) + { + p3=p2->next; + p2->next=p; + p->next=p3; + break; + } + + p2=p2->next; + } + + /*如果新添加学生的考号比已有的都大,放置最末尾*/ + if(flag>0) + { + p2->next=p; + p->next=NULL; + } + i--; + u++; + }while(i>0); + + printf("信息添加成功\n"); + printf("\t按任意键返回\n"); + getch(); + + + + return 1; +} + + +int DeleteByNum(node *head) +{ char num[9]; + int flag=1; + node *p=head,*p2; + printf("输入要删除信息的考号:"); + scanf("%s",num); + while(NULL!=p->next) + { + if((flag=strcmp(p->next->stu.num,num))==0) + { + p2=p->next; + p->next=p->next->next; + free(p2); + printf("删除成功\n"); + break; + } + p=p->next; + } + + if(flag!=0) + printf("你输入的考号不存在\n"); + printf("\t按任意键返回\n"); + getche(); + + + + + return 1; +} + + +int main() +{ + + node *head; + int i=0; + head = (node *)malloc(sizeof(node)); + strcpy(head->stu.num," "); + strcpy(head->stu.name," "); + head->stu.Chinese=0; + head->stu.math=0; + head->stu.English=0; + head->stu.count_score=0; + node *temp= (node *)malloc(sizeof(node));//保存查找结果的头结点 + + + + printf("欢迎使用\n"); + printf("\n----------------------------------------------\n"); + + + FscanfFromFile(head); + + + + + char charget; + + do + { + printf("\n----------------------------------------------\n"); + printf("\n[1]信息显示\n"); + printf("[2]信息查找\n"); + printf("[3]查询成绩\n"); + printf("[4]添加信息\n"); + printf("[5]删除信息\n"); + printf("[6]退出程序\n"); + do + { + charget=getch(); + }while((charget!='1')&&(charget!='2')&&(charget!='3')&&(charget!='4')&&(charget!='5')&&(charget!='6')); + + switch(charget) + { + case '1': ShowList(head); + printf("\n按任意键显示上层操作菜单\n"); + getch(); + break; + case '2': if(0!=MySelect(head,temp))//查找结束不为空则进行下面的操作,为空则返回上层菜单 + { + + char charget2; + do + { + printf("\n[1]在此基础上继续查找\n"); + printf("[2]将查找结果写入文件\n"); + printf("[3]退出本次查找\n"); + + + do + { + charget2=getch(); + }while((charget2!='1')&&(charget2!='2')&&(charget2!='3')); + + switch(charget2) + { + case '1': if(0==MySelect(temp,temp)) + { + printf("\n按任意键结束本次查找\n"); + getch(); + charget2='3'; + } + break; + + case '2': FprintfToFile(temp); + charget2='3';//数据写入后,自动结束本次查找 + break; + case '3': ClearList(temp);//结束查找,释放暂存查找结果的链表 + break; + + + }//end switch,结束本次查找 + + } + while(charget2!='3');//如果charget2也用charget的话,在查找中按键3会直接退出程序 + }//end if + break; + case '3': SelectScore(head);break; + case '4': AddStu(head);Fprintf(head);break; + case '5': DeleteByNum(head);Fprintf(head);break; + + + }//end switch,结束操作 + + + + }while(charget!='6'); + +return 0; +} + + + diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\200).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\200).doc" new file mode 100644 index 0000000000000000000000000000000000000000..cf8722a5dbd034ae0f0bacfa99d1e6b2db230f7c Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\200).doc" differ diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\211).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\211).doc" new file mode 100644 index 0000000000000000000000000000000000000000..83d209cc4c54b07fbd8c9b275c3b8c2bc5f0cd7a Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\270\211).doc" differ diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\214).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\214).doc" new file mode 100644 index 0000000000000000000000000000000000000000..30e7e38fe9d5211d7beb93e18a7cdae48a776fe9 Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\214).doc" differ diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\224).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\224).doc" new file mode 100644 index 0000000000000000000000000000000000000000..c8f8d15446de836a8b3d4670678d1b599fb3cd88 Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\344\272\224).doc" differ diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\205\255-\344\270\203).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\205\255-\344\270\203).doc" new file mode 100644 index 0000000000000000000000000000000000000000..dde0953627f899cefc1751e76a95fa77d8f34b17 Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\205\255-\344\270\203).doc" differ diff --git "a/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\233\233).doc" "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\233\233).doc" new file mode 100644 index 0000000000000000000000000000000000000000..8a3d240520571ac3cf85e8548a41af10bf32a8f3 Binary files /dev/null and "b/2013\347\272\247-SISE\351\253\230\350\200\203\351\242\204\345\275\225\346\225\260\346\215\256\344\277\241\346\201\257\347\256\241\347\220\206\347\263\273\347\273\237(\345\233\233).doc" differ diff --git a/project2/DlgProxy.cpp b/project2/DlgProxy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f6a9706c7177d0af0f24ffad98cd4e6068e4813 --- /dev/null +++ b/project2/DlgProxy.cpp @@ -0,0 +1,86 @@ + +// DlgProxy.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "DlgProxy.h" +#include "project2Dlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// Cproject2DlgAutoProxy + +IMPLEMENT_DYNCREATE(Cproject2DlgAutoProxy, CCmdTarget) + +Cproject2DlgAutoProxy::Cproject2DlgAutoProxy() +{ + EnableAutomation(); + + // 为使应用程序在自动化对象处于活动状态时一直保持 + // 运行,构造函数调用 AfxOleLockApp。 + AfxOleLockApp(); + + // 通过应用程序的主窗口指针 + // 来访问对话框。设置代理的内部指针 + // 指向对话框,并设置对话框的后向指针指向 + // 该代理。 + ASSERT_VALID(AfxGetApp()->m_pMainWnd); + if (AfxGetApp()->m_pMainWnd) + { + ASSERT_KINDOF(Cproject2Dlg, AfxGetApp()->m_pMainWnd); + if (AfxGetApp()->m_pMainWnd->IsKindOf(RUNTIME_CLASS(Cproject2Dlg))) + { + m_pDialog = reinterpret_cast(AfxGetApp()->m_pMainWnd); + m_pDialog->m_pAutoProxy = this; + } + } +} + +Cproject2DlgAutoProxy::~Cproject2DlgAutoProxy() +{ + // 为了在用 OLE 自动化创建所有对象后终止应用程序, + // 析构函数调用 AfxOleUnlockApp。 + // 除了做其他事情外,这还将销毁主对话框 + if (m_pDialog != NULL) + m_pDialog->m_pAutoProxy = NULL; + AfxOleUnlockApp(); +} + +void Cproject2DlgAutoProxy::OnFinalRelease() +{ + // 释放了对自动化对象的最后一个引用后,将调用 + // OnFinalRelease。基类将自动 + // 删除该对象。在调用该基类之前,请添加您的 + // 对象所需的附加清理代码。 + + CCmdTarget::OnFinalRelease(); +} + +BEGIN_MESSAGE_MAP(Cproject2DlgAutoProxy, CCmdTarget) +END_MESSAGE_MAP() + +BEGIN_DISPATCH_MAP(Cproject2DlgAutoProxy, CCmdTarget) +END_DISPATCH_MAP() + +// 注意: 我们添加了对 IID_Iproject2 的支持 +// 以支持来自 VBA 的类型安全绑定。此 IID 必须同附加到 .IDL 文件中的 +// 调度接口的 GUID 匹配。 + +// {138BD86D-7208-4D55-92AF-7D388F8DB8CC} +static const IID IID_Iproject2 = +{ 0x138BD86D, 0x7208, 0x4D55, { 0x92, 0xAF, 0x7D, 0x38, 0x8F, 0x8D, 0xB8, 0xCC } }; + +BEGIN_INTERFACE_MAP(Cproject2DlgAutoProxy, CCmdTarget) + INTERFACE_PART(Cproject2DlgAutoProxy, IID_Iproject2, Dispatch) +END_INTERFACE_MAP() + +// IMPLEMENT_OLECREATE2 宏在此项目的 StdAfx.h 中定义 +// {4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4} +IMPLEMENT_OLECREATE2(Cproject2DlgAutoProxy, "project2.Application", 0x4e19aebb, 0xd321, 0x4a0b, 0xb5, 0xb7, 0xb9, 0xbe, 0x7e, 0x72, 0x3e, 0xd4) + + +// Cproject2DlgAutoProxy 消息处理程序 diff --git a/project2/DlgProxy.h b/project2/DlgProxy.h new file mode 100644 index 0000000000000000000000000000000000000000..bc7c6d36274144d019eb0532e783270a30ae248d --- /dev/null +++ b/project2/DlgProxy.h @@ -0,0 +1,43 @@ + +// DlgProxy.h: 头文件 +// + +#pragma once + +class Cproject2Dlg; + + +// Cproject2DlgAutoProxy 命令目标 + +class Cproject2DlgAutoProxy : public CCmdTarget +{ + DECLARE_DYNCREATE(Cproject2DlgAutoProxy) + + Cproject2DlgAutoProxy(); // 动态创建所使用的受保护的构造函数 + +// 特性 +public: + Cproject2Dlg* m_pDialog; + +// 操作 +public: + +// 重写 + public: + virtual void OnFinalRelease(); + +// 实现 +protected: + virtual ~Cproject2DlgAutoProxy(); + + // 生成的消息映射函数 + + DECLARE_MESSAGE_MAP() + DECLARE_OLECREATE(Cproject2DlgAutoProxy) + + // 生成的 OLE 调度映射函数 + + DECLARE_DISPATCH_MAP() + DECLARE_INTERFACE_MAP() +}; + diff --git a/project2/ReadMe.txt b/project2/ReadMe.txt new file mode 100644 index 0000000000000000000000000000000000000000..0e2c14d0409bc2bed3735224e24de7df5a33ec7a --- /dev/null +++ b/project2/ReadMe.txt @@ -0,0 +1,84 @@ +================================================================================ +MICROSOFT 基础类库: project2 项目概述 +=============================================================================== + +应用程序向导已为您创建了这个 project2 应用程序。此应用程序不仅演示 Microsoft 基础类的基本使用方法,还可作为您编写应用程序的起点。 + +本文件概要介绍组成 project2 应用程序的每个文件的内容。 + +project2.vcxproj +这是使用应用程序向导生成的 VC++ 项目的主项目文件。 +它包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 + +project2.vcxproj.filters + 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。 + 它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 + +project2.h +这是应用程序的主要头文件。它包括其他项目特定的头文件(包括 Resource.h),并声明 Cproject2App 应用程序类。 + +project2.cpp +这是包含应用程序类 Cproject2App 的主要应用程序源文件。 + +project2.rc +这是程序使用的所有 Microsoft Windows 资源的列表。它包括 RES 子目录中存储的图标、位图和光标。此文件可以直接在 Microsoft Visual C++ 中进行编辑。项目资源位于 2052 中。 + +res\project2.ico +这是用作应用程序图标的图标文件。此图标包括在主要资源文件 project2.rc 中。 + +res\project2.rc2 +此文件包含不在 Microsoft Visual C++ 中进行编辑的资源。您应该将不可由资源编辑器编辑的所有资源放在此文件中。 + +project2.reg +这是一个示例 .reg 文件,它显示了框架将为您设置的注册设置的种类。可以将它用作 +将与您的应用程序一起使用的 .reg 文件。 + +project2.idl +此文件包含应用程序类型库的接口描述语言源代码。 + + +///////////////////////////////////////////////////////////////////////////// + +应用程序向导创建一个对话框类和自动化代理类: + +project2Dlg.h,project2Dlg.cpp - 对话框 +这些文件包含 Cproject2Dlg 类。该类定义应用程序主对话框的行为。该对话框的模板位于 project2.rc 中,该文件可以在 Microsoft Visual C++ 中进行编辑。 + +DlgProxy.h,DlgProxy.cpp - 自动化对象 +这些文件包含 Cproject2DlgAutoProxy 类。此类称为对话框的自动化代理类,这是因为它负责公开自动化控制器可以用来访问对话框的自动化方法和属性。这些方法和属性不是从对话框类直接公开的,因为在基于模式对话框的 MFC 应用程序中,能够更清楚、更容易地将自动化对象与用户界面分离。 + + +///////////////////////////////////////////////////////////////////////////// + +其他功能: + +ActiveX 控件 +应用程序包括对使用 ActiveX 控件的支持。 + +///////////////////////////////////////////////////////////////////////////// + +其他标准文件: + +StdAfx.h,StdAfx.cpp +这些文件用于生成名为 project2.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 + +Resource.h +这是标准头文件,它定义新的资源 ID。 +Microsoft Visual C++ 读取并更新此文件。 + +project2.manifest + 应用程序清单文件供 Windows XP 用来描述应用程序 + 对特定版本并行程序集的依赖性。加载程序使用此 + 信息从程序集缓存加载适当的程序集或 + 从应用程序加载私有信息。应用程序清单可能为了重新分发而作为 + 与应用程序可执行文件安装在相同文件夹中的外部 .manifest 文件包括, + 也可能以资源的形式包括在该可执行文件中。 +///////////////////////////////////////////////////////////////////////////// + +其他注释: + +应用程序向导使用“TODO:”指示应添加或自定义的源代码部分。 + +如果应用程序在共享的 DLL 中使用 MFC,则需要重新发布这些 MFC DLL;如果应用程序所用的语言与操作系统的当前区域设置不同,则还需要重新发布对应的本地化资源 MFC100XXX.DLL。有关这两个主题的更多信息,请参见 MSDN 文档中有关 Redistributing Visual C++ applications (重新发布 Visual C++ 应用程序)的章节。 + +///////////////////////////////////////////////////////////////////////////// diff --git a/project2/first.cpp b/project2/first.cpp new file mode 100644 index 0000000000000000000000000000000000000000..179fb821f60517f4295a598dcaaa03472cbb7c00 --- /dev/null +++ b/project2/first.cpp @@ -0,0 +1,357 @@ +// first.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "first.h" +#include "afxdialogex.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +#define CLRSCR system("cls") +#define PRINT_TITLE "\n序号\t考号\t\t姓名\t语文\t数学\t英语\t总分\n" +#define PRINT_FORMAT "%d\t%s\t%s\t%d\t%d\t%d\t%d\n",i,p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define WRITE_FORMAT "%s\t%s\t%d\t%d\t%d\t%d\n",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define READ_FORMAT "%s %s %d %d %d %d",&p->stu.num,&p->stu.name,&p->stu.Chinese,&p->stu.math,&p->stu.English,&p->stu.count_score +// first 对话框 + +IMPLEMENT_DYNAMIC(first, CDialogEx) + +first::first(CWnd* pParent /*=NULL*/) + : CDialogEx(first::IDD, pParent) + , m_value10(_T("")) +{ + +} + +first::~first() +{ +} + +void first::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_value10); +} + + +BEGIN_MESSAGE_MAP(first, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &first::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON2, &first::OnBnClickedButton2) +END_MESSAGE_MAP() + + +// first 消息处理程序 +//定义学生类 +class student_bx +{ +public: + char num[40]; + char name[20];//三个汉字长度为6个字节,应多定义一个字节来存放字符串结束符'\0' + int Chinese; + int math; + int English; + int count_score; +}; + +//定义单链表类 +class node +{ +public: + student_bx stu; + node *next; +}; + +int MySelect(node * head,node *temp) +{ + int i=0; + node *p,*tp=temp; + p=head->next; + FILE *fp; + char file[15]="f:\\English.txt"; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + + + while (NULL!=p) + { + if(p->stu.English>100&&p->stu.count_score>300) + { + node *end; + end = (node *)malloc(sizeof(node)); + tp->next=end; + tp=end; + tp->next=NULL; + tp->stu=p->stu; + + if(i==0) + printf (PRINT_TITLE); + i++; + printf(PRINT_FORMAT); + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + + } + p=p->next; + } + fclose(fp); + if(i==0) + printf("\n\t英语超过100分且总分成绩超过300分的学生人数为零\n"); + return i; +} + + + +void Fprintf(node *head) +{ + char file[40]={"f:\\boxiang_stu.txt"}; + FILE *fp; + if((fp=fopen(file,"w"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); +} +void InsertSort(node *head)//总分从大到小排序 +{ + node *p,*q,*u,*h,*w,*n; + int j=0; + p=head->next; + while(p!=NULL) + { + j++; + p=p->next; + } + for(int i=0;inext; + for(int z=0;z<=j-2-i;z++) + { + int y=0; + if((q->next->stu.count_score)>(p->next->stu.count_score)) + { + n=q->next; + u=n->next; + w=p->next; + p->next=n; + n->next=w; + q->next=u; + p=p->next; + y=1; + } + if(y==0) + { + p=p->next; + q=q->next; + } + } + } +} + + +void FscanfFromFile(node *head)//cdsgfdgfhhhhhhhhhhhhhhhhhhhhhhh +{ + char file[20]="f:\\student1.txt"; + char file2[20]="f:\\student2.txt"; + FILE *fp,*fp2; + if((fp=fopen(file,"r"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + if((fp2=fopen(file2,"r"))==NULL) + { + printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node *p=head; + while(!feof(fp)) + { + node *end; + end = (node *)malloc(sizeof(node)); + p->next=end; + + p=end; + p->next=NULL; + fscanf(fp,READ_FORMAT); + } + + while(!feof(fp2)) + { + node *end; + end = (node *)malloc(sizeof(node)); + p->next=end; + + p=end; + p->next=NULL; + fscanf(fp2,READ_FORMAT); + } + + printf("\n\t信息导入成功\n"); + + + + InsertSort(head); + Fprintf(head); + fclose(fp); +} + +void ShowList(node *head)//带头结点的链表 +{ + node *p=head->next; + int i=0; + printf ("\t\t\t成绩汇总排序表\n"); + printf (PRINT_TITLE); + while(NULL!=p ) + { i++; + printf (PRINT_FORMAT); + p=p->next; + } + +} + +void FprintfToFile(node *head) +{ + char file[50]={"f:\\boxiang_stu.txt"}; + + //printf("\n输入要写入的文件名:"); + //scanf("%s",file); + + FILE *fp; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + node *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); + printf("\n\t数据写入成功\n",file);//printf输出双引号要用转义字\" + +} + + +node *ClearList(node *head) +{ + node *p=head->next; + while(NULL!=p) + { + node *tp=p->next; + free(p); + p=tp; + } + return head->next=NULL; + +} + + +void first::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + node *head; + int i=0; + head = (node *)malloc(sizeof(node)); + strcpy(head->stu.num," "); + strcpy(head->stu.name," "); + head->stu.Chinese=0; + head->stu.math=0; + head->stu.English=0; + head->stu.count_score=0; + node *temp= (node *)malloc(sizeof(node));//保存查找结果的头结点 + + FscanfFromFile(head); + ShowList(head); + + ifstream in; + + string str,str2; + m_value10=""; + in.open("f:\\boxiang_stu.txt",ios::in); + while(!in.eof()) + { + getline(in,str,'\n'); + str2+=str+"\r\n"; + CString cstr(str2.c_str()); + cstr=str2.c_str(); + m_value10=cstr; + } + + UpdateData(FALSE); +} + + +void first::OnBnClickedButton2() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + node *head; + int i=0; + head = (node *)malloc(sizeof(node)); + strcpy(head->stu.num," "); + strcpy(head->stu.name," "); + head->stu.Chinese=0; + head->stu.math=0; + head->stu.English=0; + head->stu.count_score=0; + node *temp= (node *)malloc(sizeof(node));//保存查找结果的头结点 + + FscanfFromFile(head); + + MySelect(head,temp); + + ifstream in; + m_value10=""; + string str="",str2=""; + in.open("f:\\English.txt",ios::in); + while(!in.eof()) + { + getline(in,str,'\n'); + str2+=str+"\r\n"; + CString cstr(str2.c_str()); + cstr=str2.c_str(); + m_value10=cstr; + } + + UpdateData(FALSE); +} diff --git a/project2/first.h b/project2/first.h new file mode 100644 index 0000000000000000000000000000000000000000..558ef7a7b33ce851b0e0f8e76c0a60ba58934d11 --- /dev/null +++ b/project2/first.h @@ -0,0 +1,25 @@ +#pragma once + + +// first 对话框 + +class first : public CDialogEx +{ + DECLARE_DYNAMIC(first) + +public: + first(CWnd* pParent = NULL); // 标准构造函数 + virtual ~first(); + +// 对话框数据 + enum { IDD = IDD_DIALOG1 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + CString m_value10; + afx_msg void OnBnClickedButton2(); +}; diff --git a/project2/five.cpp b/project2/five.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6e05173d6ebed248fa0bf7fb46a7a4e2f291b47d --- /dev/null +++ b/project2/five.cpp @@ -0,0 +1,518 @@ +// five.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "five.h" +#include "afxdialogex.h" + +#include +#include +#include +using namespace std; +// five 对话框 + +IMPLEMENT_DYNAMIC(five, CDialogEx) + +five::five(CWnd* pParent /*=NULL*/) + : CDialogEx(five::IDD, pParent) + , m_count1(0) + , m_count2(0) + , m_count3(0) + , m_count4(0) + , m_count5(0) + , m_x(0) + , m_y(0) + , m_width(0) + , m_height(0) + , m_n1(0) + , m_n2(0) + , m_n3(0) + , m_n4(0) + , m_n5(0) + , m_sum1(0) + , m_sum2(0) + , m_sum3(0) + , m_sum4(0) + , m_sum5(0) + , m_sum(0) + , m_height0(0) + , m_height2(0) + , m_height3(0) + , m_height4(0) + , m_height5(0) + , m_scroe(0) +{ + +} + +five::~five() +{ +} + +void five::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_count1); + DDX_Text(pDX, IDC_EDIT2, m_count2); + DDX_Text(pDX, IDC_EDIT3, m_count3); + DDX_Text(pDX, IDC_EDIT4, m_count4); + DDX_Text(pDX, IDC_EDIT5, m_count5); + DDX_Text(pDX, IDC_EDIT6, m_scroe); +} + + +BEGIN_MESSAGE_MAP(five, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &five::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON2, &five::OnBnClickedButton2) + ON_BN_CLICKED(IDC_BUTTON3, &five::OnBnClickedButton3) + ON_BN_CLICKED(IDC_BUTTON4, &five::OnBnClickedButton4) +END_MESSAGE_MAP() + + +// five 消息处理程序 + + +void five::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + + + UpdateData(TRUE); + ///UpdateData(TRUE); + ifstream in,in2; + + string num; + string name; + string sex; + int age; + string address; + double chinese; + double math; + double english; + double history; + double art; + double geograpy; + double physics; + double sum; + string category; + string subject; + m_n1=m_n2=m_n3=m_n4=m_n5=0.0; + m_sum1=m_sum2=m_sum3=m_sum4=m_sum5=0.0; + in.open("f:\\student_bo.txt",ios::in); + + in2.open("f:\\student_bo.txt",ios::in); + while(!in.eof()) + { + in>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((address=="湛江")&&(category=="理科")) + { + m_sum1++; + } + else if((address=="广州")&&(category=="理科")) + { + m_sum2++; + } + else if((address=="珠海")&&(category=="理科")) + { + m_sum3++; + } + else if((address=="汕头")&&(category=="理科")) + { + m_sum4++; + } + else if((address=="深圳")&&(category=="理科")) + { + m_sum5++; + } + + } + + while(!in2.eof()) + { + + in2>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((sum>=m_scroe)) + { + // cout<ShowWindow(TRUE); + GetDlgItem(IDC_IMG3)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG4)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG5)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG6)->ShowWindow(TRUE); + + GetDlgItem(IDC_EDIT1)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT3)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT4)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT5)->ShowWindow(TRUE); + + m_height0=600.0;//总高度 + m_count1=m_n1; + m_count2=m_n2; + m_count3=m_n3; + m_count4=m_n4; + m_count5=m_n5; + + //m_count1=m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + m_sum=100; + //m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + + m_height=(m_n1/m_sum)*m_height0; + m_height2=(m_n2/m_sum)*m_height0; + m_height3=(m_n3/m_sum)*m_height0; + m_height4=(m_n4/m_sum)*m_height0; + m_height5=(m_n5/m_sum)*m_height0; + //GetDlgItem (IDC_IMG)->GetWindow(width); + //m_width=width; + //GetDlgItem(IDC_BUTTON1)->MoveWindow( x, y, width, height ); + GetDlgItem(IDC_IMG)->MoveWindow( 120,(m_height0-150-m_height), 40, m_height ); +GetDlgItem(IDC_IMG3)->MoveWindow( 170,(m_height0-150-m_height2), 40, m_height2 ); +GetDlgItem(IDC_IMG4)->MoveWindow( 220,(m_height0-150-m_height3), 40, m_height3 ); +GetDlgItem(IDC_IMG5)->MoveWindow( 270,(m_height0-150-m_height4), 40, m_height4 ); +GetDlgItem(IDC_IMG6)->MoveWindow( 320,(m_height0-150-m_height5), 40, m_height5 ); + +GetDlgItem(IDC_EDIT1)->MoveWindow( 120,(m_height0-m_height-175.0), 30, 20 ); +GetDlgItem(IDC_EDIT2)->MoveWindow( 170,(m_height0-m_height2-175.0), 30, 20 ); +GetDlgItem(IDC_EDIT3)->MoveWindow( 220,(m_height0-m_height3-175.0), 30, 20 ); +GetDlgItem(IDC_EDIT4)->MoveWindow( 270,(m_height0-m_height4-175.0), 30, 20 ); +GetDlgItem(IDC_EDIT5)->MoveWindow( 320,(m_height0-m_height5-175.0), 30, 20 ); +// CRect rect; +// GetDlgItem(IDC_IMG)->GetWindowRect(&rect); + /// m_width=rect.Width(); + // m_height=rect.Height(); + UpdateData(FALSE); + +} + + +void five::OnBnClickedButton2() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + ///UpdateData(TRUE); + ifstream in,in2; + + string num; + string name; + string sex; + int age; + string address; + double chinese; + double math; + double english; + double history; + double art; + double geograpy; + double physics; + double sum; + string category; + string subject; + m_n1=m_n2=m_n3=m_n4=m_n5=0; + m_sum1=m_sum2=m_sum3=m_sum4=m_sum5=0; + in.open("f:\\student_bo.txt",ios::in); + + in2.open("f:\\student_bo.txt",ios::in); + while(!in.eof()) + { + in>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((address=="湛江")&&(category=="文科")) + { + m_sum1++; + } + else if((address=="广州")&&(category=="文科")) + { + m_sum2++; + } + else if((address=="珠海")&&(category=="文科")) + { + m_sum3++; + } + else if((address=="汕头")&&(category=="文科")) + { + m_sum4++; + } + else if((address=="深圳")&&(category=="文科")) + { + m_sum5++; + } + + } + + while(!in2.eof()) + { + + in2>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((sum>=m_scroe)) + { + // cout<ShowWindow(TRUE); + GetDlgItem(IDC_IMG3)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG4)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG5)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG6)->ShowWindow(TRUE); + + GetDlgItem(IDC_EDIT1)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT3)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT4)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT5)->ShowWindow(TRUE); + + m_height0=600;//总高度 + m_count1=m_n1; + m_count2=m_n2; + m_count3=m_n3; + m_count4=m_n4; + m_count5=m_n5; + + //m_count1=m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + m_sum=100; + //m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + m_height=(m_n1/m_sum)*m_height0; + + m_height2=(m_n2/m_sum)*m_height0; + m_height3=(m_n3/m_sum)*m_height0; + m_height4=(m_n4/m_sum)*m_height0; + m_height5=(m_n5/m_sum)*m_height0; + + //GetDlgItem (IDC_IMG)->GetWindow(width); + //m_width=width; + //GetDlgItem(IDC_BUTTON1)->MoveWindow( x, y, width, height ); + GetDlgItem(IDC_IMG)->MoveWindow( 120,(m_height0-150-m_height), 40, m_height ); +GetDlgItem(IDC_IMG3)->MoveWindow( 170,(m_height0-150-m_height2), 40, m_height2 ); +GetDlgItem(IDC_IMG4)->MoveWindow( 220,(m_height0-150-m_height3), 40, m_height3 ); +GetDlgItem(IDC_IMG5)->MoveWindow( 270,(m_height0-150-m_height4), 40, m_height4 ); +GetDlgItem(IDC_IMG6)->MoveWindow( 320,(m_height0-150-m_height5), 40, m_height5 ); + +GetDlgItem(IDC_EDIT1)->MoveWindow( 120,(m_height0-m_height-175), 30, 20 ); +GetDlgItem(IDC_EDIT2)->MoveWindow( 170,(m_height0-m_height2-175), 30, 20 ); +GetDlgItem(IDC_EDIT3)->MoveWindow( 220,(m_height0-m_height3-175), 30, 20 ); +GetDlgItem(IDC_EDIT4)->MoveWindow( 270,(m_height0-m_height4-175), 30, 20 ); +GetDlgItem(IDC_EDIT5)->MoveWindow( 320,(m_height0-m_height5-175), 30, 20 ); +// CRect rect; +// GetDlgItem(IDC_IMG)->GetWindowRect(&rect); + /// m_width=rect.Width(); + // m_height=rect.Height(); + UpdateData(FALSE); + +} + + +void five::OnBnClickedButton3() +{ + // TODO: 在此添加控件通知处理程序代码 + + UpdateData(TRUE); + ///UpdateData(TRUE); + ifstream in,in2; + + string num; + string name; + string sex; + int age; + string address; + double chinese; + double math; + double english; + double history; + double art; + double geograpy; + double physics; + double sum; + string category; + string subject; + m_n1=m_n2=m_n3=m_n4=m_n5=0; + m_sum1=m_sum2=m_sum3=m_sum4=m_sum5=0; + in.open("f:\\student_bo.txt",ios::in); + + in2.open("f:\\student_bo.txt",ios::in); + while(!in.eof()) + { + in>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((address=="湛江")&&(category=="艺术")) + { + m_sum1++; + } + else if((address=="广州")&&(category=="艺术")) + { + m_sum2++; + } + else if((address=="珠海")&&(category=="艺术")) + { + m_sum3++; + } + else if((address=="汕头")&&(category=="艺术")) + { + m_sum4++; + } + else if((address=="深圳")&&(category=="艺术")) + { + m_sum5++; + } + + } + + while(!in2.eof()) + { + + in2>>num>>name>>sex>>age>>address>>category>> + chinese>>math + >>english>>history>>geograpy>>sum; + + if((sum>=m_scroe)) + { + // cout<ShowWindow(TRUE); + GetDlgItem(IDC_IMG3)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG4)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG5)->ShowWindow(TRUE); + GetDlgItem(IDC_IMG6)->ShowWindow(TRUE); + + GetDlgItem(IDC_EDIT1)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT2)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT3)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT4)->ShowWindow(TRUE); + GetDlgItem(IDC_EDIT5)->ShowWindow(TRUE); + + m_height0=600;//总高度 + m_count1=m_n1; + m_count2=m_n2; + m_count3=m_n3; + m_count4=m_n4; + m_count5=m_n5; + + //m_count1=m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + m_sum=100; + //m_sum1+m_sum2+m_sum3+m_sum4+m_sum5; + m_height=(m_n1/m_sum)*m_height0; + + m_height2=(m_n2/m_sum)*m_height0; + m_height3=(m_n3/m_sum)*m_height0; + m_height4=(m_n4/m_sum)*m_height0; + m_height5=(m_n5/m_sum)*m_height0; + + //GetDlgItem (IDC_IMG)->GetWindow(width); + //m_width=width; + //GetDlgItem(IDC_BUTTON1)->MoveWindow( x, y, width, height ); + GetDlgItem(IDC_IMG)->MoveWindow( 120,(m_height0-150-m_height), 40, m_height ); +GetDlgItem(IDC_IMG3)->MoveWindow( 170,(m_height0-150-m_height2), 40, m_height2 ); +GetDlgItem(IDC_IMG4)->MoveWindow( 220,(m_height0-150-m_height3), 40, m_height3 ); +GetDlgItem(IDC_IMG5)->MoveWindow( 270,(m_height0-150-m_height4), 40, m_height4 ); +GetDlgItem(IDC_IMG6)->MoveWindow( 320,(m_height0-150-m_height5), 40, m_height5 ); + +GetDlgItem(IDC_EDIT1)->MoveWindow( 120,(m_height0-m_height-175), 30, 20 ); +GetDlgItem(IDC_EDIT2)->MoveWindow( 170,(m_height0-m_height2-175), 30, 20 ); +GetDlgItem(IDC_EDIT3)->MoveWindow( 220,(m_height0-m_height3-175), 30, 20 ); +GetDlgItem(IDC_EDIT4)->MoveWindow( 270,(m_height0-m_height4-175), 30, 20 ); +GetDlgItem(IDC_EDIT5)->MoveWindow( 320,(m_height0-m_height5-175), 30, 20 ); + UpdateData(FALSE); +} + + +void five::OnBnClickedButton4() +{ + // TODO: 在此添加控件通知处理程序代码 + exit(0); +} diff --git a/project2/five.dsp b/project2/five.dsp new file mode 100644 index 0000000000000000000000000000000000000000..212c13797a7882b82c5dc5ad159f8d90f0156adb --- /dev/null +++ b/project2/five.dsp @@ -0,0 +1,88 @@ +# Microsoft Developer Studio Project File - Name="five" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=five - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "five.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "five.mak" CFG="five - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "five - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "five - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "five - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x804 /d "NDEBUG" +# ADD RSC /l 0x804 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 + +!ELSEIF "$(CFG)" == "five - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD BASE RSC /l 0x804 /d "_DEBUG" +# ADD RSC /l 0x804 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "five - Win32 Release" +# Name "five - Win32 Debug" +# Begin Source File + +SOURCE=.\five.cpp +# End Source File +# End Target +# End Project diff --git a/project2/five.dsw b/project2/five.dsw new file mode 100644 index 0000000000000000000000000000000000000000..e118b6a90500db680cfc7b0cd42649fd7f4e98a7 --- /dev/null +++ b/project2/five.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "five"=".\five.dsp" - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/project2/five.h b/project2/five.h new file mode 100644 index 0000000000000000000000000000000000000000..48700b78de624bc084239560775cc6d724765cfa --- /dev/null +++ b/project2/five.h @@ -0,0 +1,52 @@ +#pragma once + + +// five 对话框 + +class five : public CDialogEx +{ + DECLARE_DYNAMIC(five) + +public: + five(CWnd* pParent = NULL); // 标准构造函数 + virtual ~five(); + +// 对话框数据 + enum { IDD = IDD_DIALOG7 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + double m_count1; + double m_count2; + double m_count3; + double m_count4; + double m_count5; + double m_x; + double m_y; + double m_width; + double m_height; + double m_n1; + double m_n2; + double m_n3; + double m_n4; + double m_n5; + double m_sum1; + double m_sum2; + double m_sum3; + double m_sum4; + double m_sum5; + double m_sum; + double m_height0; + double m_height2; + double m_height3; + double m_height4; + double m_height5; + afx_msg void OnBnClickedButton2(); + afx_msg void OnBnClickedButton3(); + afx_msg void OnBnClickedButton4(); + int m_scroe; +}; diff --git a/project2/five.ncb b/project2/five.ncb new file mode 100644 index 0000000000000000000000000000000000000000..79b57971a141a08337fbee7e2a2b044743dd75c0 Binary files /dev/null and b/project2/five.ncb differ diff --git a/project2/five.opt b/project2/five.opt new file mode 100644 index 0000000000000000000000000000000000000000..01f45e310264b09f551690f898dfc390da9a09fc Binary files /dev/null and b/project2/five.opt differ diff --git a/project2/five.plg b/project2/five.plg new file mode 100644 index 0000000000000000000000000000000000000000..95a1c3676da8310899cbd6405061b806e328b052 --- /dev/null +++ b/project2/five.plg @@ -0,0 +1,33 @@ + + +
+

Build Log

+

+--------------------Configuration: five - Win32 Debug-------------------- +

+

Command Lines

+Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1E.tmp" with contents +[ +/nologo /MLd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Fp"Debug/five.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\Documents and Settings\Administrator\桌面\高考预录数据信息管理系统\project2\five.cpp" +] +Creating command line "cl.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1E.tmp" +Creating temporary file "C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1F.tmp" with contents +[ +kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:yes /pdb:"Debug/five.pdb" /debug /machine:I386 /out:"Debug/five.exe" /pdbtype:sept +".\Debug\five.obj" +] +Creating command line "link.exe @C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\RSP1F.tmp" +

Output Window

+Compiling... +five.cpp +c:\documents and settings\administrator\桌面\高考预录数据信息管理系统\project2\targetver.h(8) : fatal error C1083: Cannot open include file: 'SDKDDKVer.h': No such file or directory +Error executing cl.exe. + + + +

Results

+five.exe - 1 error(s), 0 warning(s) +
+ + diff --git a/project2/four.cpp b/project2/four.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ee323f70fac8381abab64350a9e364e47e5444e --- /dev/null +++ b/project2/four.cpp @@ -0,0 +1,751 @@ +// four.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "four.h" +#include "afxdialogex.h" + +#include +#include +#include //文件操作头文件 +#include //容器头文件 +#include //容器排序所用头文件 +#include //容器排序所用头文件 + +using namespace std; +/*using std::cin; +using std::cout; +using std::endl; +using std::string; +using std::fstream; +using std::vector; +using std::sort; +using std::greater; //容器排序的时候会用到 +using std::less; */ //容器排序的时候会用到 +string BOOL_GRADE; +int BOOL_TYPE[3]={0, 0, 0}; //开关 +int BOOL_PLACE[5]={0, 0, 0, 0, 0};//开关 +int BOOL_S[4]={ 0, 0, 0, 0 }; //开关 +int BOOL_T[6]={ 0, 0, 0, 0, 0, 0 }; //开关 +// four 对话框 + +IMPLEMENT_DYNAMIC(four, CDialogEx) + +four::four(CWnd* pParent /*=NULL*/) + : CDialogEx(four::IDD, pParent) + , m_seek1(_T("")) + , m_value2(_T("")) +{ + +} + +four::~four() +{ +} + +void four::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_seek1); + DDX_Text(pDX, IDC_EDIT2, m_value2); +} + + +BEGIN_MESSAGE_MAP(four, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &four::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// four 消息处理程序 +class Student_yong2 //学生类 +{ +public: + Student_yong2 (); + ~Student_yong2 (); + int finput(fstream *fp); //文件输入数据 + void fdisplay(ofstream *fp); //文件输入数据 + void input(); //控制台输入数据 + void display(); //控制台输出数据 + void setMath(); //设定数学成绩 + void setChinese(); //设定语文成绩 + void setEnglish(); //设定英语成绩 + void getMath(); //获取数学成绩 + void getChinese(); //获取语文成绩 + void getEnglish(); //获取英语成绩 + + + string _num; //考号 + string _name; //姓名 + string _sex; //性别 + unsigned int _age; //年龄 + string _place; //地点 + string _type; //考生类型 + string _wchar[5]; //储存前缀 + unsigned int _chinese; //语文 + unsigned int _math; //数学 + unsigned int _English; //英语 + unsigned int _course1; //课程一 + unsigned int _course2; //课程二 + unsigned int _sum; //总成绩 + unsigned int _list_num; //序号 + fstream *_fp; //文件指针 + +}; + +/*----------------------排序规则------------------------------*/ +//总分降序排序 +bool greatersum(const Student_yong2 & s1, const Student_yong2 & s2) +{ + return s1._sum > s2._sum; +} +//英语成绩降序排序 +bool greaterEnglish(const Student_yong2 & s1, const Student_yong2 & s2) +{ + return s1._English > s2._English; +} +//语文成绩降序排序 +bool greaterchinese(const Student_yong2 & s1, const Student_yong2& s2) +{ + return s1._chinese > s2._chinese; +} +//数学成绩降序排序 +bool greatermath(const Student_yong2 & s1, const Student_yong2 & s2) +{ + return s1._math > s2._math; +} +//第一科降序排序 +bool greatercourse1(const Student_yong2 & s1, const Student_yong2 & s2) +{ + return s1._course1 > s2._course1; +} +//第二科降序排序 +bool greatercourse2(const Student_yong2 & s1, const Student_yong2 & s2) +{ + return s1._course2 > s2._course2; +} +/*-------------------------排序规则--------------------------*/ +Student_yong2 ::Student_yong2 () +{ + _fp = 0; //初始化文件指针 +} + +Student_yong2 ::~Student_yong2 () +{ +} +int Student_yong2 ::finput(fstream *fp) //具体化finput() +{ + _fp = fp; + (*_fp) >> _num >> _name //设定学号姓名 + >> _sex >> _age //设定性别和年龄 + >> _place >> _type //地点和考生类型 + >> _wchar[0] >> _chinese >> _wchar[1] >> _math >> _wchar[2] >> _English; //设定3科成绩 + if (_type == "文科") + { + (*_fp) >> _wchar[3] >> _course1 >> _wchar[4] >> _course2; //设定历史和地理 + } + else + { + (*_fp) >> _wchar[3] >> _course1; //设定物理或美术 + } + if (_num == "" || _name == "") //如果没有读到数据返回false + { + return 0; + } + else + { + //计算总成绩 + _sum = _math + _English + _chinese + _course1 + _course2; + return 1; + } +} +void Student_yong2 ::fdisplay(ofstream *fp) //具体化display(调试的时候写的) +{ + + if (BOOL_S[0]) + { + (*fp) << _num << " "; + } + if (BOOL_S[1]) + { + (*fp) << _name << " "; + } + if (BOOL_S[2]) + { + (*fp) << _sex << " "; + } + if (BOOL_S[3]) + { + (*fp) << _age << " "; + } + if (BOOL_T[0]) + { + (*fp) << _wchar[0] << " " << _chinese << " "; + } + if (BOOL_T[1]) + { + (*fp) << _wchar[1] << " " << _math << " "; + } + if (BOOL_T[2]) + { + (*fp) << _wchar[2] << " " << _English << " "; + } + if (BOOL_T[3]) + { + (*fp) << _wchar[3] << " " << _course1 << " "; + } + if (BOOL_T[4] && _type == "文科") + { + (*fp) << _wchar[4] << " " << _course2 << " "; + } + if (BOOL_T[5]) + { + (*fp) << "总分 " << _sum << " "; + } + (*fp) << endl; +// fp->close();//关闭文件 +} +void Student_yong2 ::display() //具体化display(调试的时候写的) +{ + if (BOOL_S[0]) + { + cout << _num << " "; + } + if (BOOL_S[1]) + { + cout << _name << " "; + } + if (BOOL_S[2]) + { + cout << _sex << " "; + } + if (BOOL_S[3]) + { + cout << _age << " "; + } + if (BOOL_T[0]) + { + cout << _wchar[0] << " " << _chinese << " "; + } + if (BOOL_T[1]) + { + cout << _wchar[1] << " " << _math << " "; + } + if (BOOL_T[2]) + { + cout << _wchar[2] << " " << _English << " "; + } + if (BOOL_T[3]) + { + cout << _wchar[3] << " " << _course1 << " "; + } + if (BOOL_T[4] && _type == "文科") + { + cout << _wchar[4] << " " << _course2 << " "; + } + if (BOOL_T[5]) + { + cout << "总分 " << _sum << " "; + } + cout << endl; +} + +/* 字符串处理 ,根据符号分类添加到容器 */ +vector splitEx(const string& src, string separate_character) +{ + vector strs; + + int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 + int lastPosition = 0, index = -1; + while (-1 != (index = src.find(separate_character, lastPosition))) + { + strs.push_back(src.substr(lastPosition, index - lastPosition)); + lastPosition = index + separate_characterLen; + } + string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 + if (!lastString.empty()) + strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队 + return strs; +} + +void four::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + fstream file_one("F://data_student.txt"); //打开第一个文件 + if (!file_one) //如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + //abort();//程序退出 + } + vectorstu_data; //定义一个空的stu_date容器,储存文件的全部信息 + do + { + Student_yong2 stu; + if (stu.finput(&file_one)) //调用finpu(),输入成绩 + { + stu_data.push_back(stu); //添加对象到容器末端 + } + else + { + file_one.close(); //关闭文件 + break; //跳出循环 + } + } while (true); + vectordata_two[5]; //定义一个容器数组 + //遍历stu_data + for (auto it = stu_data.begin(); it != stu_data.end(); ++it) + { + if ((*it)._place == "广州") + { + data_two[0].push_back(*it); //添加到data_two[0] + } + else if ((*it)._place == "汕头") + { + data_two[1].push_back(*it); //添加到data_two[1] + } + else if ((*it)._place == "珠海") + { + data_two[2].push_back(*it); //添加到data_two[2] + } + else if ((*it)._place == "湛江") + { + data_two[3].push_back(*it); //添加到data_two[3] + } + else if ((*it)._place == "深圳") + { + data_two[4].push_back(*it); //添加到data_two[4] + } + } + vectordata_three[5][3]; + for (size_t i = 0; i < 5; ++i) + { + for (auto it = data_two[i].begin(); it != data_two[i].end(); ++it) + { + if (it->_type == "文科") + { + data_three[i][0].push_back(*it); // 添加到data_two[i][0] + } + else if (it->_type == "理科") + { + data_three[i][1].push_back(*it);//添加到data_two[i][1] + } + else if (it->_type == "艺术") + { + data_three[i][2].push_back(*it); //添加到data_two[i][2] + } + } + } + + //string str="P(汕头)+Q(艺术,文科,理科)+S(学号,姓名,性别)+T(总分)-Q()-P()-S(学号)%T(总分)"; + string str=""; + + str=m_seek1;//把控件的值付给c++代码 + //m_seek=""; + if (str.find("%T(")<1000){ + BOOL_GRADE = str.substr(str.find("%T") + 3, 4); + str = str.substr(0, str.find("%T")); + } + else + { + //cout << "请输入正确语法" << endl; + // str="请输入正确语法"; + // CString cstr(str.c_str()); // 或者CString cstr(str.data());初始化时才行 + // cstr = str.c_str(); // 或者cstr=str.data(); + // m_value2=cstr; //把c++代码处理后的数据传给控件变量 + // m_value="fgf"; + // GetDlgItem(IDC_EDIT3)->GetWindowText(cstr); + MessageBox("请输入正确语法"); + } + vector strs1 = splitEx(str, "-"); + vector strs2 = splitEx(strs1[0], "+"); + //删除掉"-"号前的字符串 + strs1.erase(strs1.begin()); + //+的情况 + for (unsigned int i = 0; i < strs2.size(); i++) + { + if (strs2[i].find("P") < 1000) + { + int is_ture = 1; + if (strs2[i].find("广州") < 1000) + { + BOOL_PLACE[0] = 1; + is_ture = 0; + } + if (strs2[i].find("汕头") < 1000) + { + BOOL_PLACE[1] = 1; + is_ture = 0; + } + if (strs2[i].find("珠海") < 1000) + { + BOOL_PLACE[2] = 1; + is_ture = 0; + } + if (strs2[i].find("湛江") < 1000) + { + BOOL_PLACE[3] = 1; + is_ture = 0; + + } + if (strs2[i].find("深圳") < 1000) + { + BOOL_PLACE[4] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_PLACE[0] = 1; + BOOL_PLACE[1] = 1; + BOOL_PLACE[2] = 1; + BOOL_PLACE[3] = 1; + BOOL_PLACE[4] = 1; + } + + } + else if (strs2[i].find("Q") < 1000) + { + int is_ture = 1; + if (strs2[i].find("文科") < 1000) + { + BOOL_TYPE[0] = 1; + is_ture = 0; + } + if (strs2[i].find("理科") < 1000) + { + BOOL_TYPE[1] = 1; + is_ture = 0; + } + if (strs2[i].find("艺术") < 1000) + { + BOOL_TYPE[2] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_TYPE[0] = 1; + BOOL_TYPE[1] = 1; + BOOL_TYPE[2] = 1; + } + } + else if (strs2[i].find("S") < 1000) + { + int is_ture = 1; + if (strs2[i].find("学号") < 1000) + { + BOOL_S[0] = 1; + is_ture = 0; + } + if (strs2[i].find("姓名") < 1000) + { + BOOL_S[1] = 1; + is_ture = 0; + } + if (strs2[i].find("性别") < 1000) + { + BOOL_S[2] = 1; + is_ture = 0; + } + if (strs2[i].find("年龄") < 1000) + { + BOOL_S[3] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_S[0] = 1; + BOOL_S[1] = 1; + BOOL_S[2] = 1; + BOOL_S[3] = 1; + } + } + else if (strs2[i].find("T") < 1000) + { + int is_ture = 1; + if (strs2[i].find("语文") < 1000) + { + BOOL_T[0] = 1; + is_ture = 0; + } + if (strs2[i].find("数学") < 1000) + { + BOOL_T[1] = 1; + is_ture = 0; + } + if (strs2[i].find("英语") < 1000) + { + BOOL_T[2] = 1; + is_ture = 0; + } + if (strs2[i].find("美术") < 1000 || + strs2[i].find("历史") < 1000 || + strs2[i].find("物理") < 1000) + { + BOOL_T[3] = 1; + is_ture = 0; + } + if (strs2[i].find("地理") < 1000) + { + BOOL_T[4] = 1; + is_ture = 0; + } + if (strs2[i].find("总分") < 1000) + { + BOOL_T[5] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_T[0] = 1; + BOOL_T[1] = 1; + BOOL_T[2] = 1; + BOOL_T[3] = 1; + BOOL_T[4] = 1; + BOOL_T[5] = 1; + } + } + } + + //-的情况 + for (unsigned int i = 0; i < strs1.size(); i++) + { + if (strs1[i].find("P") < 1000) + { + if (strs1[i].find("广州") < 1000) + { + BOOL_PLACE[0] = 0; + } + if (strs1[i].find("汕头") < 1000) + { + BOOL_PLACE[1] = 0; + } + if (strs1[i].find("珠海") < 1000) + { + BOOL_PLACE[2] = 0; + } + if (strs1[i].find("湛江") < 1000) + { + BOOL_PLACE[3] = 0; + } + if (strs1[i].find("深圳") < 1000) + { + BOOL_PLACE[4] = 0; + } + //如果里面没有任何信息 + if (!(BOOL_PLACE[0] || BOOL_PLACE[1] || BOOL_PLACE[2] || BOOL_PLACE[3] || BOOL_PLACE[4])) + { + BOOL_PLACE[0] = 0; + BOOL_PLACE[1] = 0; + BOOL_PLACE[2] = 0; + BOOL_PLACE[3] = 0; + BOOL_PLACE[4] = 0; + } + + } + else if (strs1[i].find("Q") < 1000) + { + if (strs1[i].find("文科") < 1000) + { + BOOL_TYPE[0] = 0; + } + if (strs1[i].find("理科") < 1000) + { + BOOL_TYPE[1] = 0; + } + if (strs1[i].find("艺术") < 1000) + { + BOOL_TYPE[2] = 0; + } + //如果里面没有任何信息 + if (!(BOOL_TYPE[0] || BOOL_TYPE[1] || BOOL_TYPE[2])) + { + BOOL_TYPE[0] = 0; + BOOL_TYPE[1] = 0; + BOOL_TYPE[2] = 0; + } + } + else if (strs1[i].find("S") < 1000) + { + int is_ture = 1; + if (strs1[i].find("学号") < 1000) + { + BOOL_S[0] = 0; + is_ture = 0; + } + if (strs1[i].find("姓名") < 1000) + { + BOOL_S[1] = 0; + is_ture = 0; + } + if (strs1[i].find("性别") < 1000) + { + BOOL_S[2] = 0; + is_ture = 0; + } + if (strs1[i].find("年龄") < 1000) + { + BOOL_S[3] = 0; + is_ture = 0; + } + if (is_ture) + { + BOOL_S[0] = 0; + BOOL_S[1] = 0; + BOOL_S[2] = 0; + BOOL_S[3] = 0; + } + + } + else if (strs1[i].find("T") < 1000) + { + int is_ture = 1; + if (strs1[i].find("语文") < 1000) + { + BOOL_T[0] = 0; + is_ture = 0; + } + if (strs1[i].find("数学") < 1000) + { + BOOL_T[1] = 0; + is_ture = 0; + } + if (strs1[i].find("英语") < 1000) + { + BOOL_T[2] = 0; + is_ture = 0; + } + if (strs1[i].find("美术") < 1000 || + strs1[i].find("历史") < 1000 || + strs1[i].find("物理") < 1000) + { + BOOL_T[3] = 0; + is_ture = 0; + } + if (strs1[i].find("地理") < 1000) + { + BOOL_T[4] = 0; + is_ture = 0; + } + if (strs1[i].find("总分") < 1000) + { + BOOL_T[5] = 0; + is_ture = 0; + } + if (is_ture) + { + BOOL_T[0] = 0; + BOOL_T[1] = 0; + BOOL_T[2] = 0; + BOOL_T[3] = 0; + BOOL_T[4] = 0; + BOOL_T[5] = 0; + } + + } + } + + //fstream file_four("F://excessive.txt", std::ios::out); //只写打开一个储存排序好的txt文件 + ofstream file_four("F://excessive.txt",ios::out); + for (size_t i = 0; i < 5; ++i) + { + //如果开关是开的 + if (BOOL_PLACE[i]) + { + file_four <<(*data_two[i].begin())._place <fdisplay(&file_four); + } + } + } + + } + + // + //P(汕头)+Q(理科)+S+T%T(数学) + fstream file_five("F://excessive.txt", std::ios::in); //以只读打开一个储存排序好的txt文件 + string ch=""; + string __str; + __str=""; + while (!file_five.eof()) + { + //file_five.get(ch); // 从文件流中读入下一个字符 + getline(file_five,ch,'\n'); + __str += ch; + __str+="\r\n"; + CString cstr(__str.c_str()); // 或者CString cstr(str.data());初始化时才行 + cstr = __str.c_str(); // 或者cstr=str.data(); + // cstr+="\r\n"; + m_value2=cstr; //把c++代码处理后的数据传给控件变量 + } + //cout << __str << endl; // 屏幕输出从文件中读入的字符 + + file_four.close(); + file_five.close(); + + /*for(auto it=data_three[3][5].begin();it!=data_three[3][5].end();++it) + { + it->_age=0; + it->_chinese=0; + it->_course1=0; + it->_course2=0; + it->_English=0; + it->_place=""; + it->_num=""; + it->_sex=""; + it->_sum=0; + it->_math=0; + + }*/ + //CFileFind finder; + UpdateData(FALSE); +} diff --git a/project2/four.h b/project2/four.h new file mode 100644 index 0000000000000000000000000000000000000000..5e8ee902172792be13d09251884ba98c792a701d --- /dev/null +++ b/project2/four.h @@ -0,0 +1,25 @@ +#pragma once + + +// four 对话框 + +class four : public CDialogEx +{ + DECLARE_DYNAMIC(four) + +public: + four(CWnd* pParent = NULL); // 标准构造函数 + virtual ~four(); + +// 对话框数据 + enum { IDD = IDD_DIALOG6 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + CString m_seek1; + CString m_value2; +}; diff --git a/project2/project2.cpp b/project2/project2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06cb21b19f1e6bf728c380b4e4fc1c3570d6d65a --- /dev/null +++ b/project2/project2.cpp @@ -0,0 +1,140 @@ + +// project2.cpp : 定义应用程序的类行为。 +// + +#include "stdafx.h" +#include "project2.h" +#include "project2Dlg.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// Cproject2App + +BEGIN_MESSAGE_MAP(Cproject2App, CWinApp) + ON_COMMAND(ID_HELP, &CWinApp::OnHelp) +END_MESSAGE_MAP() + + +// Cproject2App 构造 + +Cproject2App::Cproject2App() +{ + // 支持重新启动管理器 + m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_RESTART; + + // TODO: 在此处添加构造代码, + // 将所有重要的初始化放置在 InitInstance 中 +} + + +// 唯一的一个 Cproject2App 对象 + +Cproject2App theApp; + +const GUID CDECL BASED_CODE _tlid = + { 0x30D2B85E, 0x9B1C, 0x4CB3, { 0xBA, 0x40, 0x12, 0x2C, 0x6B, 0xAA, 0xE6, 0xB } }; +const WORD _wVerMajor = 1; +const WORD _wVerMinor = 0; + + +// Cproject2App 初始化 + +BOOL Cproject2App::InitInstance() +{ + // 如果一个运行在 Windows XP 上的应用程序清单指定要 + // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式, + //则需要 InitCommonControlsEx()。否则,将无法创建窗口。 + INITCOMMONCONTROLSEX InitCtrls; + InitCtrls.dwSize = sizeof(InitCtrls); + // 将它设置为包括所有要在应用程序中使用的 + // 公共控件类。 + InitCtrls.dwICC = ICC_WIN95_CLASSES; + InitCommonControlsEx(&InitCtrls); + + CWinApp::InitInstance(); + + + // 初始化 OLE 库 + if (!AfxOleInit()) + { + AfxMessageBox(IDP_OLE_INIT_FAILED); + return FALSE; + } + + AfxEnableControlContainer(); + + // 创建 shell 管理器,以防对话框包含 + // 任何 shell 树视图控件或 shell 列表视图控件。 + CShellManager *pShellManager = new CShellManager; + + // 标准初始化 + // 如果未使用这些功能并希望减小 + // 最终可执行文件的大小,则应移除下列 + // 不需要的特定初始化例程 + // 更改用于存储设置的注册表项 + // TODO: 应适当修改该字符串, + // 例如修改为公司或组织名 + SetRegistryKey(_T("应用程序向导生成的本地应用程序")); + // 分析自动化开关或注册/注销开关的命令行。 + CCommandLineInfo cmdInfo; + ParseCommandLine(cmdInfo); + + // 应用程序是用 /Embedding 或 /Automation 开关启动的。 + //使应用程序作为自动化服务器运行。 + if (cmdInfo.m_bRunEmbedded || cmdInfo.m_bRunAutomated) + { + // 通过 CoRegisterClassObject() 注册类工厂。 + COleTemplateServer::RegisterAll(); + } + // 应用程序是用 /Unregserver 或 /Unregister 开关启动的。移除 + // 注册表中的项。 + else if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppUnregister) + { + COleObjectFactory::UpdateRegistryAll(FALSE); + AfxOleUnregisterTypeLib(_tlid, _wVerMajor, _wVerMinor); + return FALSE; + } + // 应用程序是以独立方式或用其他开关(如 /Register + // 或 /Regserver)启动的。更新注册表项,包括类型库。 + else + { + COleObjectFactory::UpdateRegistryAll(); + AfxOleRegisterTypeLib(AfxGetInstanceHandle(), _tlid); + if (cmdInfo.m_nShellCommand == CCommandLineInfo::AppRegister) + return FALSE; + } + + Cproject2Dlg dlg; + m_pMainWnd = &dlg; + INT_PTR nResponse = dlg.DoModal(); + if (nResponse == IDOK) + { + // TODO: 在此放置处理何时用 + // “确定”来关闭对话框的代码 + } + else if (nResponse == IDCANCEL) + { + // TODO: 在此放置处理何时用 + // “取消”来关闭对话框的代码 + } + + // 删除上面创建的 shell 管理器。 + if (pShellManager != NULL) + { + delete pShellManager; + } + + // 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序, + // 而不是启动应用程序的消息泵。 + return FALSE; +} + +int Cproject2App::ExitInstance() +{ + AfxOleTerm(FALSE); + + return CWinApp::ExitInstance(); +} diff --git a/project2/project2.h b/project2/project2.h new file mode 100644 index 0000000000000000000000000000000000000000..61944da8495fd47433a06a15fd3f768c670ea8d6 --- /dev/null +++ b/project2/project2.h @@ -0,0 +1,33 @@ + +// project2.h : PROJECT_NAME 应用程序的主头文件 +// + +#pragma once + +#ifndef __AFXWIN_H__ + #error "在包含此文件之前包含“stdafx.h”以生成 PCH 文件" +#endif + +#include "resource.h" // 主符号 + + +// Cproject2App: +// 有关此类的实现,请参阅 project2.cpp +// + +class Cproject2App : public CWinApp +{ +public: + Cproject2App(); + +// 重写 +public: + virtual BOOL InitInstance(); + virtual int ExitInstance(); + +// 实现 + + DECLARE_MESSAGE_MAP() +}; + +extern Cproject2App theApp; \ No newline at end of file diff --git a/project2/project2.idl b/project2/project2.idl new file mode 100644 index 0000000000000000000000000000000000000000..f995bc5181881b62699e02082906bb8d444f27e8 --- /dev/null +++ b/project2/project2.idl @@ -0,0 +1,29 @@ +// project2.idl : project2.exe 的类型库源 + +// 此文件将由 MIDL 编译器处理以产生 +// 类型库(project2.tlb)。 + +[ uuid(30D2B85E-9B1C-4CB3-BA40-122C6BAAE60B), version(1.0) ] +library project2 +{ + importlib("stdole32.tlb"); + importlib("stdole2.tlb"); + + // Cproject2Doc 的主调度接口 + + [ uuid(138BD86D-7208-4D55-92AF-7D388F8DB8CC) ] + dispinterface Iproject2 + { + properties: + + methods: + }; + + // Cproject2Doc 的类信息 + + [ uuid(4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4) ] + coclass project2 + { + [default] dispinterface Iproject2; + }; +}; diff --git a/project2/project2.rc b/project2/project2.rc new file mode 100644 index 0000000000000000000000000000000000000000..cba71b57cb8ac73c90cd71f4f08c987111c53793 Binary files /dev/null and b/project2/project2.rc differ diff --git a/project2/project2.reg b/project2/project2.reg new file mode 100644 index 0000000000000000000000000000000000000000..3e8050249e6885ef1f8e371fb9dd2f6997281bd5 --- /dev/null +++ b/project2/project2.reg @@ -0,0 +1,17 @@ +REGEDIT +; 此 .REG 文件可能由 SETUP 程序使用。 +; 如果 SETUP 程序不可用,则调用 +; CWinApp::RegisterShellFileTypes 和 COleObjectFactory::UpdateRegistryAll +; 在 InitInstance 中对下列项自动进行注册。 + + +HKEY_CLASSES_ROOT\project2.Application = project2 Application + + +HKEY_CLASSES_ROOT\project2.Application\CLSID = {4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4} + +HKEY_CLASSES_ROOT\CLSID\{4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4} = project2 Application +HKEY_CLASSES_ROOT\CLSID\{4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4}\ProgId = project2.Application + + +HKEY_CLASSES_ROOT\CLSID\{4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4}\LocalServer32 = project2.EXE diff --git a/project2/project2.sln b/project2/project2.sln new file mode 100644 index 0000000000000000000000000000000000000000..d9f688e7585420588898e1689d0a337961c276f2 --- /dev/null +++ b/project2/project2.sln @@ -0,0 +1,20 @@ +锘 +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "project2", "project2.vcxproj", "{59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C}.Debug|Win32.ActiveCfg = Debug|Win32 + {59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C}.Debug|Win32.Build.0 = Debug|Win32 + {59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C}.Release|Win32.ActiveCfg = Release|Win32 + {59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/project2/project2.suo b/project2/project2.suo new file mode 100644 index 0000000000000000000000000000000000000000..5f3c42288f64f945a91e49e51a6aa7aa3a7de26b Binary files /dev/null and b/project2/project2.suo differ diff --git a/project2/project2.vcxproj b/project2/project2.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..64128ce300460c53ea800d28d7839437b8618962 --- /dev/null +++ b/project2/project2.vcxproj @@ -0,0 +1,159 @@ +锘 + + + + Debug + Win32 + + + Release + Win32 + + + + {59CF7FEE-32BA-4E25-9A1A-D3C73B0EBC8C} + project2 + MFCProj + + + + Application + true + MultiByte + Dynamic + + + Application + false + true + MultiByte + Dynamic + + + + + + + + + + + + + true + + + false + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + + + false + true + _DEBUG;%(PreprocessorDefinitions) + $(IntDir)project2.tlb + + + 0x0804 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;%(PreprocessorDefinitions) + + + Windows + true + true + true + true + + + false + true + NDEBUG;%(PreprocessorDefinitions) + $(IntDir)project2.tlb + + + 0x0804 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/project2/project2.vcxproj.filters b/project2/project2.vcxproj.filters new file mode 100644 index 0000000000000000000000000000000000000000..1f673c4e57b82dd2e68cb72d547a26409a734f1b --- /dev/null +++ b/project2/project2.vcxproj.filters @@ -0,0 +1,137 @@ +锘 + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + 璧勬簮鏂囦欢 + + + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + 澶存枃浠 + + + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + 婧愭枃浠 + + + + + 婧愭枃浠 + + + + + 璧勬簮鏂囦欢 + + + \ No newline at end of file diff --git a/project2/project2.vcxproj.user b/project2/project2.vcxproj.user new file mode 100644 index 0000000000000000000000000000000000000000..ace9a86acb77340247c6d79e985eca55840261de --- /dev/null +++ b/project2/project2.vcxproj.user @@ -0,0 +1,3 @@ +锘 + + \ No newline at end of file diff --git a/project2/project2Dlg.cpp b/project2/project2Dlg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99e3e05cbe17dea05c32e448ae8b71c03b00ca09 --- /dev/null +++ b/project2/project2Dlg.cpp @@ -0,0 +1,255 @@ + +// project2Dlg.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "project2Dlg.h" +#include "DlgProxy.h" +#include "afxdialogex.h" +#include "first.h" +#include "second.h" +#include "third.h" +#include "four.h" +#include "five.h" + +#ifdef _DEBUG +#define new DEBUG_NEW +#endif + + +// 用于应用程序“关于”菜单项的 CAboutDlg 对话框 + +class CAboutDlg : public CDialogEx +{ +public: + CAboutDlg(); + +// 对话框数据 + enum { IDD = IDD_ABOUTBOX }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + +// 实现 +protected: + DECLARE_MESSAGE_MAP() +}; + +CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD) +{ +} + +void CAboutDlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) +END_MESSAGE_MAP() + + +// Cproject2Dlg 对话框 + + + + +IMPLEMENT_DYNAMIC(Cproject2Dlg, CDialogEx); + +Cproject2Dlg::Cproject2Dlg(CWnd* pParent /*=NULL*/) + : CDialogEx(Cproject2Dlg::IDD, pParent) +{ + m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); + m_pAutoProxy = NULL; +} + +Cproject2Dlg::~Cproject2Dlg() +{ + // 如果该对话框有自动化代理,则 + // 将此代理指向该对话框的后向指针设置为 NULL,以便 + // 此代理知道该对话框已被删除。 + if (m_pAutoProxy != NULL) + m_pAutoProxy->m_pDialog = NULL; +} + +void Cproject2Dlg::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + +BEGIN_MESSAGE_MAP(Cproject2Dlg, CDialogEx) + ON_WM_SYSCOMMAND() + ON_WM_CLOSE() + ON_WM_PAINT() + ON_WM_QUERYDRAGICON() + ON_BN_CLICKED(IDC_BUTTON1, &Cproject2Dlg::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON2, &Cproject2Dlg::OnBnClickedButton2) + ON_BN_CLICKED(IDC_BUTTON3, &Cproject2Dlg::OnBnClickedButton3) + ON_BN_CLICKED(IDC_BUTTON4, &Cproject2Dlg::OnBnClickedButton4) + ON_BN_CLICKED(IDC_BUTTON5, &Cproject2Dlg::OnBnClickedButton5) +END_MESSAGE_MAP() + + +// Cproject2Dlg 消息处理程序 + +BOOL Cproject2Dlg::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // 将“关于...”菜单项添加到系统菜单中。 + + // IDM_ABOUTBOX 必须在系统命令范围内。 + ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); + ASSERT(IDM_ABOUTBOX < 0xF000); + + CMenu* pSysMenu = GetSystemMenu(FALSE); + if (pSysMenu != NULL) + { + BOOL bNameValid; + CString strAboutMenu; + bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); + ASSERT(bNameValid); + if (!strAboutMenu.IsEmpty()) + { + pSysMenu->AppendMenu(MF_SEPARATOR); + pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); + } + } + + // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动 + // 执行此操作 + SetIcon(m_hIcon, TRUE); // 设置大图标 + SetIcon(m_hIcon, FALSE); // 设置小图标 + + // TODO: 在此添加额外的初始化代码 + + return TRUE; // 除非将焦点设置到控件,否则返回 TRUE +} + +void Cproject2Dlg::OnSysCommand(UINT nID, LPARAM lParam) +{ + if ((nID & 0xFFF0) == IDM_ABOUTBOX) + { + CAboutDlg dlgAbout; + dlgAbout.DoModal(); + } + else + { + CDialogEx::OnSysCommand(nID, lParam); + } +} + +// 如果向对话框添加最小化按钮,则需要下面的代码 +// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序, +// 这将由框架自动完成。 + +void Cproject2Dlg::OnPaint() +{ + if (IsIconic()) + { + CPaintDC dc(this); // 用于绘制的设备上下文 + + SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); + + // 使图标在工作区矩形中居中 + int cxIcon = GetSystemMetrics(SM_CXICON); + int cyIcon = GetSystemMetrics(SM_CYICON); + CRect rect; + GetClientRect(&rect); + int x = (rect.Width() - cxIcon + 1) / 2; + int y = (rect.Height() - cyIcon + 1) / 2; + + // 绘制图标 + dc.DrawIcon(x, y, m_hIcon); + } + else + { + CDialogEx::OnPaint(); + } +} + +//当用户拖动最小化窗口时系统调用此函数取得光标 +//显示。 +HCURSOR Cproject2Dlg::OnQueryDragIcon() +{ + return static_cast(m_hIcon); +} + +// 当用户关闭 UI 时,如果控制器仍保持着它的某个 +// 对象,则自动化服务器不应退出。这些 +// 消息处理程序确保如下情形: 如果代理仍在使用, +// 则将隐藏 UI;但是在关闭对话框时, +// 对话框仍然会保留在那里。 + +void Cproject2Dlg::OnClose() +{ + if (CanExit()) + CDialogEx::OnClose(); +} + +void Cproject2Dlg::OnOK() +{ + //if (CanExit()) + // CDialogEx::OnOK(); +} + +void Cproject2Dlg::OnCancel() +{ + if (CanExit()) + CDialogEx::OnCancel(); +} + +BOOL Cproject2Dlg::CanExit() +{ + // 如果代理对象仍保留在那里,则自动化 + // 控制器仍会保持此应用程序。 + // 使对话框保留在那里,但将其 UI 隐藏起来。 + if (m_pAutoProxy != NULL) + { + ShowWindow(SW_HIDE); + return FALSE; + } + + return TRUE; +} + + + +void Cproject2Dlg::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + first p; + p.DoModal(); +} + + +void Cproject2Dlg::OnBnClickedButton2() +{ + // TODO: 在此添加控件通知处理程序代码 + second p; + p.DoModal(); +} + + +void Cproject2Dlg::OnBnClickedButton3() +{ + // TODO: 在此添加控件通知处理程序代码 + third p; + p.DoModal(); +} + + +void Cproject2Dlg::OnBnClickedButton4() +{ + // TODO: 在此添加控件通知处理程序代码 + four p; + p.DoModal(); +} + + +void Cproject2Dlg::OnBnClickedButton5() +{ + // TODO: 在此添加控件通知处理程序代码 + five p; + p.DoModal(); +} diff --git a/project2/project2Dlg.h b/project2/project2Dlg.h new file mode 100644 index 0000000000000000000000000000000000000000..8ca027d7dcab7f1eaa768f4a7082a86df7c9eb7c --- /dev/null +++ b/project2/project2Dlg.h @@ -0,0 +1,50 @@ + +// project2Dlg.h : 头文件 +// + +#pragma once + +class Cproject2DlgAutoProxy; + + +// Cproject2Dlg 对话框 +class Cproject2Dlg : public CDialogEx +{ + DECLARE_DYNAMIC(Cproject2Dlg); + friend class Cproject2DlgAutoProxy; + +// 构造 +public: + Cproject2Dlg(CWnd* pParent = NULL); // 标准构造函数 + virtual ~Cproject2Dlg(); + +// 对话框数据 + enum { IDD = IDD_PROJECT2_DIALOG }; + + protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + +// 实现 +protected: + Cproject2DlgAutoProxy* m_pAutoProxy; + HICON m_hIcon; + + BOOL CanExit(); + + // 生成的消息映射函数 + virtual BOOL OnInitDialog(); + afx_msg void OnSysCommand(UINT nID, LPARAM lParam); + afx_msg void OnPaint(); + afx_msg HCURSOR OnQueryDragIcon(); + afx_msg void OnClose(); + virtual void OnOK(); + virtual void OnCancel(); + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + afx_msg void OnBnClickedButton2(); + afx_msg void OnBnClickedButton3(); + afx_msg void OnBnClickedButton4(); + afx_msg void OnBnClickedButton5(); +}; diff --git a/project2/project2_h.h b/project2/project2_h.h new file mode 100644 index 0000000000000000000000000000000000000000..0b29f645d0599a238e7f3eba6243fedc6ce7b286 --- /dev/null +++ b/project2/project2_h.h @@ -0,0 +1,203 @@ + + +/* this ALWAYS GENERATED file contains the definitions for the interfaces */ + + + /* File created by MIDL compiler version 7.00.0555 */ +/* at Sat Jul 05 11:04:21 2014 + */ +/* Compiler settings for project2.idl: + Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +/* verify that the version is high enough to compile this file*/ +#ifndef __REQUIRED_RPCNDR_H_VERSION__ +#define __REQUIRED_RPCNDR_H_VERSION__ 475 +#endif + +#include "rpc.h" +#include "rpcndr.h" + +#ifndef __RPCNDR_H_VERSION__ +#error this stub requires an updated version of +#endif // __RPCNDR_H_VERSION__ + + +#ifndef __project2_h_h__ +#define __project2_h_h__ + +#if defined(_MSC_VER) && (_MSC_VER >= 1020) +#pragma once +#endif + +/* Forward Declarations */ + +#ifndef __Iproject2_FWD_DEFINED__ +#define __Iproject2_FWD_DEFINED__ +typedef interface Iproject2 Iproject2; +#endif /* __Iproject2_FWD_DEFINED__ */ + + +#ifndef __project2_FWD_DEFINED__ +#define __project2_FWD_DEFINED__ + +#ifdef __cplusplus +typedef class project2 project2; +#else +typedef struct project2 project2; +#endif /* __cplusplus */ + +#endif /* __project2_FWD_DEFINED__ */ + + +#ifdef __cplusplus +extern "C"{ +#endif + + + +#ifndef __project2_LIBRARY_DEFINED__ +#define __project2_LIBRARY_DEFINED__ + +/* library project2 */ +/* [version][uuid] */ + + +EXTERN_C const IID LIBID_project2; + +#ifndef __Iproject2_DISPINTERFACE_DEFINED__ +#define __Iproject2_DISPINTERFACE_DEFINED__ + +/* dispinterface Iproject2 */ +/* [uuid] */ + + +EXTERN_C const IID DIID_Iproject2; + +#if defined(__cplusplus) && !defined(CINTERFACE) + + MIDL_INTERFACE("138BD86D-7208-4D55-92AF-7D388F8DB8CC") + Iproject2 : public IDispatch + { + }; + +#else /* C style interface */ + + typedef struct Iproject2Vtbl + { + BEGIN_INTERFACE + + HRESULT ( STDMETHODCALLTYPE *QueryInterface )( + Iproject2 * This, + /* [in] */ REFIID riid, + /* [annotation][iid_is][out] */ + __RPC__deref_out void **ppvObject); + + ULONG ( STDMETHODCALLTYPE *AddRef )( + Iproject2 * This); + + ULONG ( STDMETHODCALLTYPE *Release )( + Iproject2 * This); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )( + Iproject2 * This, + /* [out] */ UINT *pctinfo); + + HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )( + Iproject2 * This, + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ ITypeInfo **ppTInfo); + + HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )( + Iproject2 * This, + /* [in] */ REFIID riid, + /* [size_is][in] */ LPOLESTR *rgszNames, + /* [range][in] */ UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ DISPID *rgDispId); + + /* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )( + Iproject2 * This, + /* [in] */ DISPID dispIdMember, + /* [in] */ REFIID riid, + /* [in] */ LCID lcid, + /* [in] */ WORD wFlags, + /* [out][in] */ DISPPARAMS *pDispParams, + /* [out] */ VARIANT *pVarResult, + /* [out] */ EXCEPINFO *pExcepInfo, + /* [out] */ UINT *puArgErr); + + END_INTERFACE + } Iproject2Vtbl; + + interface Iproject2 + { + CONST_VTBL struct Iproject2Vtbl *lpVtbl; + }; + + + +#ifdef COBJMACROS + + +#define Iproject2_QueryInterface(This,riid,ppvObject) \ + ( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) ) + +#define Iproject2_AddRef(This) \ + ( (This)->lpVtbl -> AddRef(This) ) + +#define Iproject2_Release(This) \ + ( (This)->lpVtbl -> Release(This) ) + + +#define Iproject2_GetTypeInfoCount(This,pctinfo) \ + ( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) ) + +#define Iproject2_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \ + ( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) ) + +#define Iproject2_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \ + ( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) ) + +#define Iproject2_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \ + ( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) ) + +#endif /* COBJMACROS */ + + +#endif /* C style interface */ + + +#endif /* __Iproject2_DISPINTERFACE_DEFINED__ */ + + +EXTERN_C const CLSID CLSID_project2; + +#ifdef __cplusplus + +class DECLSPEC_UUID("4E19AEBB-D321-4A0B-B5B7-B9BE7E723ED4") +project2; +#endif +#endif /* __project2_LIBRARY_DEFINED__ */ + +/* Additional Prototypes for ALL interfaces */ + +/* end of Additional Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif + + diff --git a/project2/project2_i.c b/project2/project2_i.c new file mode 100644 index 0000000000000000000000000000000000000000..9963c27886f3c57923ec716e402756f4cc8a9a81 --- /dev/null +++ b/project2/project2_i.c @@ -0,0 +1,85 @@ + + +/* this ALWAYS GENERATED file contains the IIDs and CLSIDs */ + +/* link this file in with the server and any clients */ + + + /* File created by MIDL compiler version 7.00.0555 */ +/* at Sat Jul 05 11:04:21 2014 + */ +/* Compiler settings for project2.idl: + Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555 + protocol : dce , ms_ext, c_ext, robust + error checks: allocation ref bounds_check enum stub_data + VC __declspec() decoration level: + __declspec(uuid()), __declspec(selectany), __declspec(novtable) + DECLSPEC_UUID(), MIDL_INTERFACE() +*/ +/* @@MIDL_FILE_HEADING( ) */ + +#pragma warning( disable: 4049 ) /* more than 64k source lines */ + + +#ifdef __cplusplus +extern "C"{ +#endif + + +#include +#include + +#ifdef _MIDL_USE_GUIDDEF_ + +#ifndef INITGUID +#define INITGUID +#include +#undef INITGUID +#else +#include +#endif + +#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ + DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) + +#else // !_MIDL_USE_GUIDDEF_ + +#ifndef __IID_DEFINED__ +#define __IID_DEFINED__ + +typedef struct _IID +{ + unsigned long x; + unsigned short s1; + unsigned short s2; + unsigned char c[8]; +} IID; + +#endif // __IID_DEFINED__ + +#ifndef CLSID_DEFINED +#define CLSID_DEFINED +typedef IID CLSID; +#endif // CLSID_DEFINED + +#define MIDL_DEFINE_GUID(type,name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) \ + const type name = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} + +#endif !_MIDL_USE_GUIDDEF_ + +MIDL_DEFINE_GUID(IID, LIBID_project2,0x30D2B85E,0x9B1C,0x4CB3,0xBA,0x40,0x12,0x2C,0x6B,0xAA,0xE6,0x0B); + + +MIDL_DEFINE_GUID(IID, DIID_Iproject2,0x138BD86D,0x7208,0x4D55,0x92,0xAF,0x7D,0x38,0x8F,0x8D,0xB8,0xCC); + + +MIDL_DEFINE_GUID(CLSID, CLSID_project2,0x4E19AEBB,0xD321,0x4A0B,0xB5,0xB7,0xB9,0xBE,0x7E,0x72,0x3E,0xD4); + +#undef MIDL_DEFINE_GUID + +#ifdef __cplusplus +} +#endif + + + diff --git a/project2/res/project2.ico b/project2/res/project2.ico new file mode 100644 index 0000000000000000000000000000000000000000..d56fbcdfdf6eac0f4727c34770c26689271d96af Binary files /dev/null and b/project2/res/project2.ico differ diff --git a/project2/res/project2.rc2 b/project2/res/project2.rc2 new file mode 100644 index 0000000000000000000000000000000000000000..bc36d4f23626b0996dcd3e77cff8cc1812e1272f Binary files /dev/null and b/project2/res/project2.rc2 differ diff --git a/project2/resource.h b/project2/resource.h new file mode 100644 index 0000000000000000000000000000000000000000..239150863c7d6a87bb4f001410c8ef24aa206b8b Binary files /dev/null and b/project2/resource.h differ diff --git a/project2/second.cpp b/project2/second.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7974e039ecd58f356a4f0504017c750de8042b54 --- /dev/null +++ b/project2/second.cpp @@ -0,0 +1,53 @@ +// second.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "second.h" +#include "afxdialogex.h" +#include "second_one.h" +#include "second_two.h" + +// second 对话框 + +IMPLEMENT_DYNAMIC(second, CDialogEx) + +second::second(CWnd* pParent /*=NULL*/) + : CDialogEx(second::IDD, pParent) +{ + +} + +second::~second() +{ +} + +void second::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); +} + + +BEGIN_MESSAGE_MAP(second, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &second::OnBnClickedButton1) + ON_BN_CLICKED(IDC_BUTTON2, &second::OnBnClickedButton2) +END_MESSAGE_MAP() + + +// second 消息处理程序 + + +void second::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + second_one p; + p.DoModal(); +} + + +void second::OnBnClickedButton2() +{ + // TODO: 在此添加控件通知处理程序代码 + second_two p; + p.DoModal(); +} diff --git a/project2/second.h b/project2/second.h new file mode 100644 index 0000000000000000000000000000000000000000..9e302bca800f908c8c352b013b7c16285138e4a6 --- /dev/null +++ b/project2/second.h @@ -0,0 +1,24 @@ +#pragma once + + +// second 对话框 + +class second : public CDialogEx +{ + DECLARE_DYNAMIC(second) + +public: + second(CWnd* pParent = NULL); // 标准构造函数 + virtual ~second(); + +// 对话框数据 + enum { IDD = IDD_DIALOG2 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + afx_msg void OnBnClickedButton2(); +}; diff --git a/project2/second_one.cpp b/project2/second_one.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd65f46583bd6d6ffd6841e0fc531922860871e0 --- /dev/null +++ b/project2/second_one.cpp @@ -0,0 +1,327 @@ +// second_one.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "second_one.h" +#include "afxdialogex.h" + +#include +#include +#include +#include +#include +#include +//#include +#include +#include +using namespace std; + +#define CLRSCR system("cls") +#define PRINT_TITLE "\n序号\t考号\t\t姓名\t语文\t数学\t英语\t总分\n" +#define PRINT_FORMAT "%d\t%s\t%s\t%d\t%d\t%d\t%d\n",i,p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define WRITE_FORMAT "%s\t%s\t%d\t%d\t%d\t%d\n",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score +#define READ_FORMAT "%s %s %d %d %d %d",&p->stu.num,&p->stu.name,&p->stu.Chinese,&p->stu.math,&p->stu.English,&p->stu.count_score +// second_one 对话框 + +IMPLEMENT_DYNAMIC(second_one, CDialogEx) + +second_one::second_one(CWnd* pParent /*=NULL*/) + : CDialogEx(second_one::IDD, pParent) + , m_stu(_T("")) +{ + +} + +second_one::~second_one() +{ +} + +void second_one::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_stu); +} + + +BEGIN_MESSAGE_MAP(second_one, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &second_one::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// second_one 消息处理程序 +class student_bx2 +{ +public: + char num[40]; + char name[20];//三个汉字长度为6个字节,应多定义一个字节来存放字符串结束符'\0' + int Chinese; + int math; + int English; + int count_score; +}; + +//定义单链表类 +class node2 +{ +public: + student_bx2 stu; + node2 *next; +}; + +int MySelect(node2 * head,node2 *temp) +{ + int i=0; + node2 *p,*tp=temp; + p=head->next; + FILE *fp; + char file[15]={"f:\\English.txt"}; + if((fp=fopen(file,"w+"))==NULL) + { + // printf("\n\t文件创建失败\n"); + + exit(0); + } + + + while (NULL!=p) + { + if(p->stu.English>100&&p->stu.count_score>300) + { + node2 *end; + end = (node2 *)malloc(sizeof(node2)); + tp->next=end; + tp=end; + tp->next=NULL; + tp->stu=p->stu; + + if(i==0) + // printf(PRINT_TITLE); + i++; + // printf(PRINT_FORMAT); + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + + } + p=p->next; + } +// fclose(fp); + if(i==0) + //printf("\n\t英语超过100分且总分成绩超过300分的学生人数为零\n"); + return i; +} + + + +void Fprintf(node2 *head) +{ + char file[40]={"f:\\boxiang_stu2.txt"}; + FILE *fp; + if((fp=fopen(file,"w+"))==NULL) + { + //printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node2 *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); +} +void InsertSort(node2 *head)//总分从大到小排序 +{ + node2 *p,*q,*u,*h,*w,*n; + int j=0; + p=head->next; + while(p!=NULL) + { + j++; + p=p->next; + } + for(int i=0;inext; + for(int z=0;z<=j-2-i;z++) + { + int y=0; + if((q->next->stu.count_score)>(p->next->stu.count_score)) + { + n=q->next; + u=n->next; + w=p->next; + p->next=n; + n->next=w; + q->next=u; + p=p->next; + y=1; + } + if(y==0) + { + p=p->next; + q=q->next; + } + } + } +} + + +void FscanfFromFile(node2 *head)//cdsgfdgfhhhhhhhhhhhhhhhhhhhhhhh +{ + char file[25]="f:\\boxiang_stu.txt"; + + FILE *fp; + if((fp=fopen(file,"r"))==NULL) + { + //printf("\n\t文件打开失败,按任意键退出\n"); + getch(); + exit(0); + } + + node2 *p=head; + while(!feof(fp)) + { + node2 *end; + end = (node2 *)malloc(sizeof(node2)); + p->next=end; + + p=end; + p->next=NULL; + fscanf(fp,READ_FORMAT); + } + + //printf("\n\t信息导入成功\n"); + + + + InsertSort(head); + Fprintf(head); + fclose(fp); +} + +void ShowList(node2 *head)//带头结点的链表 +{ + node2 *p=head->next; + int i=0; + //printf ("\t\t\t成绩汇总排序表\n"); +// printf (PRINT_TITLE); + while(NULL!=p ) + { i++; + printf (PRINT_FORMAT); + p=p->next; + } + +} + +void FprintfToFile(node2 *head) +{ + char file[50]={"f:\\boxiang_stu2.txt"}; + + //printf("\n输入要写入的文件名:"); + //scanf("%s",file); + + FILE *fp; + if((fp=fopen(file,"w+"))==NULL) + { + printf("\n\t文件创建失败\n"); + + exit(0); + } + node2 *p=head->next; + while(NULL!=p) + { + if(p->next==NULL)//不要最后一行的回车,这样的话导入该文件时就不会有末尾的乱码 + fprintf(fp,"%s\t%s\t%d\t%d\t%d\t%d",p->stu.num,p->stu.name,p->stu.Chinese,p->stu.math,p->stu.English,p->stu.count_score); + else + fprintf(fp,WRITE_FORMAT); + p=p->next; + } + fclose(fp); + printf("\n\t数据写入成功\n",file);//printf输出双引号要用转义字\" + +} + + +node2 *ClearList(node2 *head) +{ + node2 *p=head->next; + while(NULL!=p) + { + node2 *tp=p->next; + free(p); + p=tp; + } + return head->next=NULL; + +} + +void second_one::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + ofstream out; + string num,name; + int chinese,math,english,sum; + out.open("f:\\stu.txt",ios::out); + out<>num>>name>>chinese>>math>>english; + sum=chinese+math+english; + out2<stu.num," "); + strcpy(head->stu.name," "); + head->stu.Chinese=0; + head->stu.math=0; + head->stu.English=0; + head->stu.count_score=0; + node2 *temp= (node2 *)malloc(sizeof(node2));//保存查找结果的头结点 + + FscanfFromFile(head); + ShowList(head); + + //重新写入数据 + ifstream in3; + ofstream out3; + in3.open("f:\\boxiang_stu2.txt",ios::in); + out3.open("f:\\boxiang_stu.txt",ios::out); + while(!in3.eof()) + { + in3>>num>>name>>chinese>>math>>english>>sum; + + out3< +#include +#include +using namespace std; +// second_two 对话框 + +IMPLEMENT_DYNAMIC(second_two, CDialogEx) + +second_two::second_two(CWnd* pParent /*=NULL*/) + : CDialogEx(second_two::IDD, pParent) + , m_seek(_T("")) + , m_seek2(_T("")) +{ + +} + +second_two::~second_two() +{ +} + +void second_two::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_seek); + DDX_Text(pDX, IDC_EDIT2, m_seek2); +} + + +BEGIN_MESSAGE_MAP(second_two, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &second_two::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// second_two 消息处理程序 + + +void second_two::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + + string num; + string name; + string chinese; + string math; + string english; + string sum; + string num1; + + ifstream in; + string str,str2; + + num1=m_seek; + in.open("f:\\boxiang_stu.txt",ios::in); + while(!in.eof()) + { + + // getline(in,str,'\n'); + /// str2+=str+"\r\n"; + in>>num>>name>>chinese>>math>>english>>sum; + if(num==num1) + { + str2+=num+" "+name+" "+chinese+" "+math+" "+english+" "+sum+"\r\n"; + + CString cstr(str2.c_str()); + cstr=str2.c_str(); + m_seek2=cstr; + } + } + UpdateData(FALSE); +} diff --git a/project2/second_two.h b/project2/second_two.h new file mode 100644 index 0000000000000000000000000000000000000000..5331c9bc9a2f0073fcf49179d8c2e5efe2a1ea09 --- /dev/null +++ b/project2/second_two.h @@ -0,0 +1,25 @@ +#pragma once + + +// second_two 对话框 + +class second_two : public CDialogEx +{ + DECLARE_DYNAMIC(second_two) + +public: + second_two(CWnd* pParent = NULL); // 标准构造函数 + virtual ~second_two(); + +// 对话框数据 + enum { IDD = IDD_DIALOG4 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + CString m_seek; + CString m_seek2; +}; diff --git a/project2/six.cpp b/project2/six.cpp new file mode 100644 index 0000000000000000000000000000000000000000..599977894551aea68211e62ae06bb7f0c1fd7b49 --- /dev/null +++ b/project2/six.cpp @@ -0,0 +1,374 @@ +// six.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "six.h" +#include "afxdialogex.h" + +#include +#include +#include //文件操作头文件 +#include //容器头文件 +#include //容器排序所用头文件 +#include //容器排序所用头文件 +using namespace std; +/* +using std::cin; +using std::cout; +using std::endl; +using std::string; +using std::fstream; +using std::vector; +using std::sort; +using std::greater; //容器排序的时候会用到 +using std::less; //容器排序的时候会用到*/ +//string BOOL_GRADE; +int BOOL__[5][3]={0, 0, 0,0,0,0,0,0,0,0,0,0,0,0,0}; //开关 +// six 对话框 + +IMPLEMENT_DYNAMIC(six, CDialogEx) + +six::six(CWnd* pParent /*=NULL*/) + : CDialogEx(six::IDD, pParent) + , m_seek_six(_T("")) + , m_value_six(_T("")) +{ + +} + +six::~six() +{ +} + +void six::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_seek_six); + DDX_Text(pDX, IDC_EDIT2, m_value_six); +} + + +BEGIN_MESSAGE_MAP(six, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &six::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// six 消息处理程序 +/*void System() +{ + cout << "输入查询语句格式如下:" << endl + << "(地区1,类型)+(地区1,类型)" << endl; +} + +class Student_yong3 //学生类 +{ +public: + Student_yong3(); + ~Student_yong3(); + int finput(fstream *fp); //文件输入数据 + void fdisplay(fstream *fp); //文件输入数据 + void input(); //控制台输入数据 + void display(); //控制台输出数据 + void setMath(); //设定数学成绩 + void setChinese(); //设定语文成绩 + void setEnglish(); //设定英语成绩 + void getMath(); //获取数学成绩 + void getChinese(); //获取语文成绩 + void getEnglish(); //获取英语成绩 + + + string _num; //考号 + string _name; //姓名 + string _sex; //性别 + unsigned int _age; //年龄 + string _place; //地点 + string _type; //考生类型 + string _wchar[5]; //储存前缀 + unsigned int _chinese; //语文 + unsigned int _math; //数学 + unsigned int _English; //英语 + unsigned int _course1; //课程一 + unsigned int _course2; //课程二 + unsigned int _sum; //总成绩 + unsigned int _list_num; //序号 + fstream *_fp; //文件指针 + +};*/ + +/*----------------------排序规则------------------------------*/ +//总分降序排序 +/* +bool greatersum(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._sum > s2._sum; +} +//英语成绩降序排序 +bool greaterEnglish(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._English > s2._English; +} +//语文成绩降序排序 +bool greaterchinese(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._chinese > s2._chinese; +} +//数学成绩降序排序 +bool greatermath(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._math > s2._math; +} +//第一科降序排序 +bool greatercourse1(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._course1 > s2._course1; +} +//第二科降序排序 +bool greatercourse2(const Student_yong3& s1, const Student_yong3& s2) +{ + return s1._course2 > s2._course2; +}*/ +/*-------------------------排序规则--------------------------*/ +/* +Student_yong3::Student_yong3() +{ + _fp = 0; //初始化文件指针 +} + +Student_yong3 ::~Student_yong3() +{ +} +int Student_yong3::finput(fstream *fp) //具体化finput() +{ + _fp = fp; + (*_fp) >> _num >> _name //设定学号姓名 + >> _sex >> _age //设定性别和年龄 + >> _place >> _type //地点和考生类型 + >> _wchar[0] >> _chinese >> _wchar[1] >> _math >> _wchar[2] >> _English; //设定3科成绩 + if (_type == "文科") + { + (*_fp) >> _wchar[3] >> _course1 >> _wchar[4] >> _course2; //设定历史和地理 + } + else + { + (*_fp) >> _wchar[3] >> _course1; //设定物理或美术 + } + if (_num == "" || _name == "") //如果没有读到数据返回false + { + return 0; + } + else + { + //计算总成绩 + _sum = _math + _English + _chinese + _course1 + _course2; + return 1; + } +} +void Student_yong3::fdisplay(fstream *fp) //具体化fdisplay +{ + (*fp) << _num << " " << _name << " " //文件输出学号姓名 + << _sex << " " << _age << " " //文件输出性别和年龄 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //文件输出3科成绩 + if (_type == "文科") + { + (*fp) << _wchar[3] << _course1 << _wchar[4] << _course2; //文件输出历史和地理 + } + else + { + (*fp) << _wchar[3] << _course1; //文件输出物理或美术 + } + (*fp) << "总分 " << _sum << endl; //文件输出总分 +} + +/* 字符串处理 ,根据符号分类添加到容器 */ +/* +vector splitEx(const string& src, string separate_character) +{ + vector strs; + + int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 + int lastPosition = 0, index = -1; + while (-1 != (index = src.find(separate_character, lastPosition))) + { + strs.push_back(src.substr(lastPosition, index - lastPosition)); + lastPosition = index + separate_characterLen; + } + string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 + if (!lastString.empty()) + strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队 + return strs; +} +*/ +void six::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + /* UpdateData(TRUE); + + fstream file_one("F://data_student6.txt"); //打开第一个文件 + if (!file_one) //如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + vectorstu_data; //定义一个空的stu_date容器,储存文件的全部信息 + do + { + Student_yong3 stu; + if (stu.finput(&file_one)) //调用finpu(),输入成绩 + { + stu_data.push_back(stu); //添加对象到容器末端 + } + else + { + file_one.close(); //关闭文件 + break; //跳出循环 + } + } while (true); + vectordata_two[5]; //定义一个容器数组 + //遍历stu_data + for (auto it = stu_data.begin(); it != stu_data.end(); ++it) + { + if ((*it)._place == "广州") + { + data_two[0].push_back(*it); //添加到data_two[0] + } + else if ((*it)._place == "汕头") + { + data_two[1].push_back(*it); //添加到data_two[1] + } + else if ((*it)._place == "珠海") + { + data_two[2].push_back(*it); //添加到data_two[2] + } + else if ((*it)._place == "湛江") + { + data_two[3].push_back(*it); //添加到data_two[3] + } + else if ((*it)._place == "深圳") + { + data_two[4].push_back(*it); //添加到data_two[4] + } + } + vectordata_three1[5][3]; + for (size_t i = 0; i < 5; ++i) + { + for (auto it = data_two[i].begin(); it != data_two[i].end(); ++it) + { + if (it->_type == "文科") + { + data_three1[i][0].push_back(*it); // 添加到data_two[i][0] + } + else if (it->_type == "理科") + { + data_three1[i][1].push_back(*it);//添加到data_two[i][1] + } + else if (it->_type == "艺术") + { + data_three1[i][2].push_back(*it); //添加到data_two[i][2] + } + } + } + System(); + //string str="P(汕头)+Q(艺术,文科,理科)+S(学号,姓名,性别)+T(总分)-Q()-P()-S(学号)%T(总分)"; + string str_1=""; + //cin >> str; + str_1=m_seek_six; + vector strs2 = splitEx(str_1, "+"); + + //+的情况 + for (unsigned int i = 0; i < strs2.size(); i++) + { + + + if (strs2[i].find("(广州") < 1000) + { + string str1__= strs2[i].substr(strs2[i].find("广州")+5, 4); + if (str1__ == "文科") + BOOL__[0][0] = 1; + if (str1__ == "理科") + BOOL__[0][1] = 1; + if (str1__== "艺术") + BOOL__[0][2] = 1; + } + if (strs2[i].find("(汕头") < 1000) + { + string str2__ = strs2[i].substr(strs2[i].find("汕头") + 5, 4); + if (str2__ == "文科") + BOOL__[1][0] = 1; + if (str2__ == "理科") + BOOL__[1][1] = 1; + if (str2__ == "艺术") + BOOL__[1][2] = 1; + } + if (strs2[i].find("(珠海") < 1000) + { + string str3__ = strs2[i].substr(strs2[i].find("珠海") + 5, 4); + if (str3__ == "文科") + BOOL__[2][0] = 1; + if (str3__ == "理科") + BOOL__[2][1] = 1; + if (str3__ == "艺术") + BOOL__[2][2] = 1;; + } + if (strs2[i].find("(湛江") < 1000) + { + string str3__ = strs2[i].substr(strs2[i].find("湛江") + 5, 4); + if (str3__ == "文科") + BOOL__[3][0] = 1; + if (str3__ == "理科") + BOOL__[3][1] = 1; + if (str3__ == "艺术") + BOOL__[3][2] = 1;; + } + if (strs2[i].find("(深圳") < 1000) + { + { + string str3__ = strs2[i].substr(strs2[i].find("深圳") + 5, 4); + if (str3__ == "文科") + BOOL__[4][0] = 1; + if (str3__ == "理科") + BOOL__[4][1] = 1; + if (str3__ == "艺术") + BOOL__[4][2] = 1;; + } + } + } + fstream file_six("F://scholar.txt",std::ios::out); //打开第一个文件 + for (size_t i = 0; i < 5; ++i) + { + + for (size_t j = 0; j < 3; ++j) + { + //如果开关是开的 + if (BOOL__[i][j]) + { + file_six << (*data_three1[i][j].begin())._place + << (*data_three1[i][j].begin())._type << " 状元: " << endl; + //按总分降序排序 + sort(data_three1[i][j].begin(), data_three1[i][j].end(), greatersum); + auto it = data_three1[i][j].begin(); + //把数据读进student.txt + it->fdisplay(&file_six); + //(汕头,文科)+(广州,理科) + } + } + + } + string _str_one_1; + string _str_two_1; + fstream file_six_2("F://scholar.txt"); + while (!file_six_2.eof()) + { + getline(file_six_2, _str_one_1, '\n'); // 从文件流中读入下一个字符 + + _str_two_1 += _str_one_1 + "\r\n"; + CString cstr(_str_two_1.c_str()); + cstr=_str_two_1.c_str(); + m_value_six=cstr; + } + //关闭文件 + //cout << _str_two_1 << endl; + + file_six_2.close(); + UpdateData(FALSE); */ +} diff --git a/project2/six.h b/project2/six.h new file mode 100644 index 0000000000000000000000000000000000000000..7b8ba539cd07cae6ed489fc1991db8c501839840 --- /dev/null +++ b/project2/six.h @@ -0,0 +1,25 @@ +#pragma once + + +// six 对话框 + +class six : public CDialogEx +{ + DECLARE_DYNAMIC(six) + +public: + six(CWnd* pParent = NULL); // 标准构造函数 + virtual ~six(); + +// 对话框数据 + enum { IDD = IDD_DIALOG8 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + CString m_seek_six; + CString m_value_six; + afx_msg void OnBnClickedButton1(); +}; diff --git a/project2/stdafx.cpp b/project2/stdafx.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8b8295ed39704337eda89b133092137c4bf03862 --- /dev/null +++ b/project2/stdafx.cpp @@ -0,0 +1,8 @@ + +// stdafx.cpp : 只包括标准包含文件的源文件 +// project2.pch 将作为预编译头 +// stdafx.obj 将包含预编译类型信息 + +#include "stdafx.h" + + diff --git a/project2/stdafx.h b/project2/stdafx.h new file mode 100644 index 0000000000000000000000000000000000000000..3cf985d9c3167b6f63e41322b28e6419e377c66a --- /dev/null +++ b/project2/stdafx.h @@ -0,0 +1,69 @@ + +// stdafx.h : 标准系统包含文件的包含文件, +// 或是经常使用但不常更改的 +// 特定于项目的包含文件 + +#pragma once + +#ifndef _SECURE_ATL +#define _SECURE_ATL 1 +#endif + +#ifndef VC_EXTRALEAN +#define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 +#endif + +#include "targetver.h" + +#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // 某些 CString 构造函数将是显式的 + +// 关闭 MFC 对某些常见但经常可放心忽略的警告消息的隐藏 +#define _AFX_ALL_WARNINGS + +#include // MFC 核心组件和标准组件 +#include // MFC 扩展 + + +#include // MFC 自动化类 + + + +#ifndef _AFX_NO_OLE_SUPPORT +#include // MFC 对 Internet Explorer 4 公共控件的支持 +#endif +#ifndef _AFX_NO_AFXCMN_SUPPORT +#include // MFC 对 Windows 公共控件的支持 +#endif // _AFX_NO_AFXCMN_SUPPORT + +#include // 功能区和控件条的 MFC 支持 + + + + + + + + +// 除要将 bMultiInstance 参数的 TRUE +// 传递给 COleObjectFactory 构造函数之外,此宏与 IMPLEMENT_OLECREATE 相同。 +// 对于自动化控制器所请求的每一个自动化代理对象, +// 需要分别启动一个该应用程序的实例。 +#ifndef IMPLEMENT_OLECREATE2 +#define IMPLEMENT_OLECREATE2(class_name, external_name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ + AFX_DATADEF COleObjectFactory class_name::factory(class_name::guid, \ + RUNTIME_CLASS(class_name), TRUE, _T(external_name)); \ + const AFX_DATADEF GUID class_name::guid = \ + { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; +#endif // IMPLEMENT_OLECREATE2 + +#ifdef _UNICODE +#if defined _M_IX86 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"") +#elif defined _M_X64 +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"") +#else +#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") +#endif +#endif + + diff --git a/project2/targetver.h b/project2/targetver.h new file mode 100644 index 0000000000000000000000000000000000000000..0afac5bb16e359e4c7c48215174acb95603caf91 --- /dev/null +++ b/project2/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// 包括 SDKDDKVer.h 将定义最高版本的可用 Windows 平台。 + +// 如果要为以前的 Windows 平台生成应用程序,请包括 WinSDKVer.h,并将 +// WIN32_WINNT 宏设置为要支持的平台,然后再包括 SDKDDKVer.h。 + +#include diff --git a/project2/third.cpp b/project2/third.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7b75a419e1b98ca183c3ea0246f050212ba78c6d --- /dev/null +++ b/project2/third.cpp @@ -0,0 +1,289 @@ +// third.cpp : 实现文件 +// + +#include "stdafx.h" +#include "project2.h" +#include "third.h" +#include "afxdialogex.h" + +#include +#include +#include //文件操作头文件 +#include //容器头文件 +#include //容器排序所用头文件 +#include //容器排序所用头文件 + +using std::cin; +using std::cout; +using std::endl; +using std::string; +using std::fstream; +using std::vector; +using std::sort; +using std::greater; //容器排序的时候会用到 +using std::less; //容器排序的时候会用到 +// third 对话框 + +IMPLEMENT_DYNAMIC(third, CDialogEx) + +third::third(CWnd* pParent /*=NULL*/) + : CDialogEx(third::IDD, pParent) + , m_value(_T("")) +{ + +} + +third::~third() +{ +} + +void third::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Text(pDX, IDC_EDIT1, m_value); +} + + +BEGIN_MESSAGE_MAP(third, CDialogEx) + ON_BN_CLICKED(IDC_BUTTON1, &third::OnBnClickedButton1) +END_MESSAGE_MAP() + + +// third 消息处理程序 +class Student_yong //学生类 +{ +public: + Student_yong (); + ~Student_yong (); + int finput(fstream *fp); //文件输入数据 + void fdisplay(fstream *fp); //文件输入数据 + void input(); //控制台输入数据 + void display(); //控制台输出数据 + void setMath(); //设定数学成绩 + void setChinese(); //设定语文成绩 + void setEnglish(); //设定英语成绩 + void getMath(); //获取数学成绩 + void getChinese(); //获取语文成绩 + void getEnglish(); //获取英语成绩 + + string _num; //考号 + string _name; //姓名 + string _sex; //性别 + unsigned int _age; //年龄 + string _place; //地点 + string _type; //考生类型 + string _wchar[5]; //储存前缀 + unsigned int _chinese; //语文 + unsigned int _math; //数学 + unsigned int _English; //英语 + unsigned int _course1; //课程一 + unsigned int _course2; //课程二 + unsigned int _sum; //总成绩 + unsigned int _list_num; //序号 + fstream *_fp; //文件指针 + +}; +/*----------------------排序规则------------------------------*/ +//英语成绩升序排序 +static bool lessEnglish(const Student_yong& s1, const Student_yong& s2) +{ + return s1._English < s2._English; +} +//英语成绩降序排序 +static bool greaterEnglish(const Student_yong& s1, const Student_yong& s2) +{ + return s1._English > s2._English; +} +//总分升序排序 +static bool lesssum(const Student_yong& s1, const Student_yong& s2) +{ + return s1._sum < s2._sum; +} +//总分降序排序 +static bool greatersum(const Student_yong& s1, const Student_yong& s2) +{ + return s1._sum > s2._sum; +} +/*-------------------------排序规则--------------------------*/ + +Student_yong ::Student_yong () +{ + _fp = 0; //初始化文件指针 +} + +Student_yong ::~Student_yong () +{ +} +int Student_yong::finput(fstream *fp) //具体化finput() +{ + _fp = fp; + (*_fp) >> _num >> _name //设定学号姓名 + >>_sex>>_age //设定性别和年龄 + >>_place>>_type //地点和考生类型 + >> _wchar[0] >> _chinese >> _wchar[1] >> _math >> _wchar[2] >> _English; //设定3科成绩 + if (_type == "文科") + { + (*_fp) >> _wchar[3] >> _course1 >> _wchar[4] >> _course2; //设定历史和地理 + } + else + { + (*_fp) >> _wchar[3] >> _course1; //设定物理或美术 + } + if (_num==""||_name=="") //如果没有读到数据返回false + { + return 0; + } + else + { + //计算总成绩 + _sum = _math + _English + _chinese + _course1 + _course2; + return 1; + } +} +void Student_yong::fdisplay(fstream *fp) //具体化fdisplay +{ + (*fp) << _num << " " << _name << " " //文件输出学号姓名 + << _sex << " " << _age << " " //文件输出性别和年龄 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //文件输出3科成绩 + if (_type == "文科") + { + (*fp) << _wchar[3] << _course1 << _wchar[4] << _course2 ; //文件输出历史和地理 + } + else + { + (*fp) << _wchar[3] << _course1; //文件输出物理或美术 + } + (*fp) << "总分 " << _sum << endl; //文件输出总分 +} +void Student_yong::display() //具体化display(调试的时候写的) +{ + cout << _num <<" "<< _name<<" " //控制台输出学号姓名 + << _sex <<" "<< _age<<" " //控制台输出性别和年龄 + << _place <<" "<< _type<<" " //控制台输出地点和考生类型 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //控制台输3科成绩 + if (_type == "文科") + { + cout << _wchar[3] << _course1 << _wchar[4] << _course2; //控制台输历史和地理 + } + else + { + cout << _wchar[3] << _course1 ; //控制台输历史和地理 + } + cout << "总分 " << _sum << endl; +} + +void third::OnBnClickedButton1() +{ + // TODO: 在此添加控件通知处理程序代码 + UpdateData(TRUE); + + fstream file_one("F://data_student.txt"); //打开第一个文件 + if (!file_one) //如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + vectorstu_data; //定义一个空的stu_date容器,储存文件的全部信息 + do + { + Student_yong stu; + if (stu.finput(&file_one)) //调用finpu(),输入成绩 + { + stu_data.push_back(stu); //添加对象到容器末端 + } + else + { + file_one.close(); //关闭文件 + break; //跳出循环 + } + } while (true); + vectordata_two[5]; //定义个个容器数组 + //遍历stu_data + for (auto it = stu_data.begin(); it != stu_data.end(); ++it) + { + if ((*it)._place == "广州") + { + data_two[0].push_back(*it); //添加到data_two[0] + } + else if ((*it)._place == "汕头") + { + data_two[1].push_back(*it); //添加到data_two[1] + } + else if ((*it)._place == "珠海") + { + data_two[2].push_back(*it); //添加到data_two[2] + } + else if ((*it)._place == "湛江") + { + data_two[3].push_back(*it); //添加到data_two[3] + } + else if ((*it)._place == "深圳") + { + data_two[4].push_back(*it); //添加到data_two[4] + } + } + vectordata_three[5][3]; + for (size_t i = 0; i < 5; ++i) + { + for (auto it = data_two[i].begin(); it != data_two[i].end(); ++it) + { + if (it->_type=="文科") + { + data_three[i][0].push_back(*it); // 添加到data_two[i][0] + } + else if (it->_type == "理科") + { + data_three[i][1].push_back(*it);//添加到data_two[i][1] + } + else if (it->_type == "艺术") + { + data_three[i][2].push_back(*it); //添加到data_two[i][2] + } + } + } + //打开要储存分类好的文件 + fstream file_two("F://student.txt"); + if (!file_two)//如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + for (size_t i = 0; i < 5; ++i) + { + file_two<<(*data_two[i].begin())._place<fdisplay(&file_two); + } + } + + } + //关闭文件 + string str; + string str2; + fstream in; + in.open("f:\\student.txt",std::ios::in); + while(!in.eof()) + { + getline(in,str,'\n'); + str2+=str+"\r\n"; + CString cstr(str2.c_str()); + cstr=str2.c_str(); + m_value=cstr; + + } + + + + + + file_two.close(); + in.close(); + UpdateData(FALSE); +} diff --git a/project2/third.h b/project2/third.h new file mode 100644 index 0000000000000000000000000000000000000000..87e71d7c59464419eada02daf0195eea8ef21910 --- /dev/null +++ b/project2/third.h @@ -0,0 +1,24 @@ +#pragma once + + +// third 对话框 + +class third : public CDialogEx +{ + DECLARE_DYNAMIC(third) + +public: + third(CWnd* pParent = NULL); // 标准构造函数 + virtual ~third(); + +// 对话框数据 + enum { IDD = IDD_DIALOG5 }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnBnClickedButton1(); + CString m_value; +}; diff --git a/student.txt b/student.txt new file mode 100644 index 0000000000000000000000000000000000000000..f0425a7181d0f0db55e15ad234dfc3abfca94649 --- /dev/null +++ b/student.txt @@ -0,0 +1,128 @@ +#include +#include +#include +using namespace std; +class person//定义person类 +{ +friend void contrast(person (&a)[10]);//友元声明,该函数对person类数组按成绩进行排序 +friend void degree(const person &);//友元声明,该函数对学生成绩进行评定 +public: +person(char*s="0",char g='0',int a=0,float n=0):name(new char[strlen(s)+1]),sex(g),age(a),score(n),num() +{//带默认实参的构造函数,初始化列表中为name成员动态分配堆中空间 +strcpy(name,s); +set_no();//见该函数注释 +} +person(const person &p):name(new char[strlen(p.name)+1]),sex(p.sex),age(p.age),score(p.score),num() +{//复制构造函数,初始化列表中为name成员动态分配堆中空间 +strcpy(name,p.name); +copy_no(p);//见该函数注释 +} +/*具有删除堆中空间功能的析构寒素,因为每个对象的name成员都创建了堆 +中空间,析构掉该对象时必须先删除对应的堆中空间,否则会产生内存泄露*/ +~person(){delete [] name;name=NULL;} +void dispaly();//打印对象数据成员的函数 +void set_item(char *s="0",char g='0',int a=0,float n=0);//设置除学号外其它数据成员的函数 +void copy_item(const person &);//复制对象的成员函数 +protected: +void set_no();//以static成员start对代表学号的num成员进行"赋值" +void copy_no(const person &);//"复制"num成员 +char *name;//用string多好,题目真恶心 +char sex;//单个字符能表达性别么? +int num[10];// +float score; +int age; +static int start;//用来对学号"赋值"的静态整型成员 +}; +int person::start(1300000001);//对该静态整型成员定义,13表示2013年尾数1表示学号从1起始 +void person::dispaly() +{ +cout<=90){cout<=80){cout<=70){cout<=60){cout< +#include +#include //文件操作头文件 +#include //容器头文件 +#include //容器排序所用头文件 +#include //容器排序所用头文件 + +using std::cin; +using std::cout; +using std::endl; +using std::string; +using std::fstream; +using std::vector; +using std::sort; +using std::greater; //容器排序的时候会用到 +using std::less; //容器排序的时候会用到 + +class Student //学生类 +{ +public: + Student (); + ~Student (); + int finput(fstream *fp); //文件输入数据 + void fdisplay(fstream *fp); //文件输入数据 + void input(); //控制台输入数据 + void display(); //控制台输出数据 + void setMath(); //设定数学成绩 + void setChinese(); //设定语文成绩 + void setEnglish(); //设定英语成绩 + void getMath(); //获取数学成绩 + void getChinese(); //获取语文成绩 + void getEnglish(); //获取英语成绩 + + string _num; //考号 + string _name; //姓名 + string _sex; //性别 + unsigned int _age; //年龄 + string _place; //地点 + string _type; //考生类型 + string _wchar[5]; //储存前缀 + unsigned int _chinese; //语文 + unsigned int _math; //数学 + unsigned int _English; //英语 + unsigned int _course1; //课程一 + unsigned int _course2; //课程二 + unsigned int _sum; //总成绩 + unsigned int _list_num; //序号 + fstream *_fp; //文件指针 + +}; +/*----------------------排序规则------------------------------*/ +//英语成绩升序排序 +static bool lessEnglish(const Student& s1, const Student& s2) +{ + return s1._English < s2._English; +} +//英语成绩降序排序 +static bool greaterEnglish(const Student& s1, const Student& s2) +{ + return s1._English > s2._English; +} +//总分升序排序 +static bool lesssum(const Student& s1, const Student& s2) +{ + return s1._sum < s2._sum; +} +//总分降序排序 +static bool greatersum(const Student& s1, const Student& s2) +{ + return s1._sum > s2._sum; +} +/*-------------------------排序规则--------------------------*/ + +Student ::Student () +{ + _fp = 0; //初始化文件指针 +} + +Student ::~Student () +{ +} +int Student::finput(fstream *fp) //具体化finput() +{ + _fp = fp; + (*_fp) >> _num >> _name //设定学号姓名 + >>_sex>>_age //设定性别和年龄 + >>_place>>_type //地点和考生类型 + >> _wchar[0] >> _chinese >> _wchar[1] >> _math >> _wchar[2] >> _English; //设定3科成绩 + if (_type == "文科") + { + (*_fp) >> _wchar[3] >> _course1 >> _wchar[4] >> _course2; //设定历史和地理 + } + else + { + (*_fp) >> _wchar[3] >> _course1; //设定物理或美术 + } + if (_num==""||_name=="") //如果没有读到数据返回false + { + return 0; + } + else + { + //计算总成绩 + _sum = _math + _English + _chinese + _course1 + _course2; + return 1; + } +} +void Student::fdisplay(fstream *fp) //具体化fdisplay +{ + (*fp) << _num << " " << _name << " " //文件输出学号姓名 + << _sex << " " << _age << " " //文件输出性别和年龄 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //文件输出3科成绩 + if (_type == "文科") + { + (*fp) << _wchar[3] << _course1 << _wchar[4] << _course2 ; //文件输出历史和地理 + } + else + { + (*fp) << _wchar[3] << _course1; //文件输出物理或美术 + } + (*fp) << "总分 " << _sum << endl; //文件输出总分 +} +void Student::display() //具体化display(调试的时候写的) +{ + cout << _num <<" "<< _name<<" " //控制台输出学号姓名 + << _sex <<" "<< _age<<" " //控制台输出性别和年龄 + << _place <<" "<< _type<<" " //控制台输出地点和考生类型 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //控制台输3科成绩 + if (_type == "文科") + { + cout << _wchar[3] << _course1 << _wchar[4] << _course2; //控制台输历史和地理 + } + else + { + cout << _wchar[3] << _course1 ; //控制台输历史和地理 + } + cout << "总分 " << _sum << endl; +} +int main() +{ + fstream file_one("F://data_student.txt"); //打开第一个文件 + if (!file_one) //如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + vectorstu_data; //定义一个空的stu_date容器,储存文件的全部信息 + do + { + Student stu; + if (stu.finput(&file_one)) //调用finpu(),输入成绩 + { + stu_data.push_back(stu); //添加对象到容器末端 + } + else + { + file_one.close(); //关闭文件 + break; //跳出循环 + } + } while (true); + vectordata_two[5]; //定义个个容器数组 + //遍历stu_data + for (auto it = stu_data.begin(); it != stu_data.end(); ++it) + { + if ((*it)._place == "广州") + { + data_two[0].push_back(*it); //添加到data_two[0] + } + else if ((*it)._place == "汕头") + { + data_two[1].push_back(*it); //添加到data_two[1] + } + else if ((*it)._place == "珠海") + { + data_two[2].push_back(*it); //添加到data_two[2] + } + else if ((*it)._place == "湛江") + { + data_two[3].push_back(*it); //添加到data_two[3] + } + else if ((*it)._place == "深圳") + { + data_two[4].push_back(*it); //添加到data_two[4] + } + } + vectordata_three[5][3]; + for (size_t i = 0; i < 5; ++i) + { + for (auto it = data_two[i].begin(); it != data_two[i].end(); ++it) + { + if (it->_type=="文科") + { + data_three[i][0].push_back(*it); // 添加到data_two[i][0] + } + else if (it->_type == "理科") + { + data_three[i][1].push_back(*it);//添加到data_two[i][1] + } + else if (it->_type == "艺术") + { + data_three[i][2].push_back(*it); //添加到data_two[i][2] + } + } + } + //打开要储存分类好的文件 + fstream file_two("F://student.txt"); + if (!file_two)//如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + for (size_t i = 0; i < 5; ++i) + { + file_two<<(*data_two[i].begin())._place<fdisplay(&file_two); + } + } + + } + //关闭文件 + file_two.close(); +} \ No newline at end of file diff --git "a/\347\254\254\345\233\233\351\242\230.cpp" "b/\347\254\254\345\233\233\351\242\230.cpp" new file mode 100644 index 0000000000000000000000000000000000000000..e7997c5f1aa539eb271465962e89b5dbbacd366a --- /dev/null +++ "b/\347\254\254\345\233\233\351\242\230.cpp" @@ -0,0 +1,655 @@ +/* + 项目实训第四部分使用说明: + + 直接运行,两个txt文件(student.txt && data_student.txt )要放到F盘的根目录下 + 为了分类用了2维类容器 + + 优点: + 通过判断学生_type属性来判断是多一科课程还是两科课程 + 用容器的sort排序显得非常简练 + 写得非常乱啊,叫我拿什么优点出来啊 + + 不足: + 乱到只有编辑器才看得懂 + 提取字符串有效数据的方法很累赘 + 控制台输出数据的方法很操蛋 + 并没用实现类的封装,规则写进类里面要记住用静态类型 + 没有实现模块化 + Student里面的_fp属性有点多余 + 用容器数组存储分类的算法是不是可以优化? + 无任何页面操作 + by2014/6/30 +*/ + +#include +#include +#include //文件操作头文件 +#include //容器头文件 +#include //容器排序所用头文件 +#include //容器排序所用头文件 + +using std::cin; +using std::cout; +using std::endl; +using std::string; +using std::fstream; +using std::vector; +using std::sort; +using std::greater; //容器排序的时候会用到 +using std::less; //容器排序的时候会用到 +string BOOL_GRADE; +int BOOL_TYPE[3]{0, 0, 0}; //开关 +int BOOL_PLACE[5]{0, 0, 0, 0, 0};//开关 +int BOOL_S[4]{ 0, 0, 0, 0 }; //开关 +int BOOL_T[6]{ 0, 0, 0, 0, 0,0 }; //开关 + +void System() +{ + cout << "输入查询语句格式如下:"< s2._sum; +} +//英语成绩降序排序 +bool greaterEnglish(const Student& s1, const Student& s2) +{ + return s1._English > s2._English; +} +//语文成绩降序排序 +bool greaterchinese(const Student& s1, const Student& s2) +{ + return s1._chinese > s2._chinese; +} +//数学成绩降序排序 +bool greatermath(const Student& s1, const Student& s2) +{ + return s1._math > s2._math; +} +//第一科降序排序 +bool greatercourse1(const Student& s1, const Student& s2) +{ + return s1._course1 > s2._course1; +} +//第二科降序排序 +bool greatercourse2(const Student& s1, const Student& s2) +{ + return s1._course2 > s2._course2; +} +/*-------------------------排序规则--------------------------*/ +Student ::Student () +{ + _fp = 0; //初始化文件指针 +} + +Student ::~Student () +{ +} +int Student::finput(fstream *fp) //具体化finput() +{ + _fp = fp; + (*_fp) >> _num >> _name //设定学号姓名 + >>_sex>>_age //设定性别和年龄 + >>_place>>_type //地点和考生类型 + >> _wchar[0] >> _chinese >> _wchar[1] >> _math >> _wchar[2] >> _English; //设定3科成绩 + if (_type == "文科") + { + (*_fp) >> _wchar[3] >> _course1 >> _wchar[4] >> _course2; //设定历史和地理 + } + else + { + (*_fp) >> _wchar[3] >> _course1; //设定物理或美术 + } + if (_num==""||_name=="") //如果没有读到数据返回false + { + return 0; + } + else + { + //计算总成绩 + _sum = _math + _English + _chinese + _course1 + _course2; + return 1; + } +} +void Student::fdisplay(fstream *fp) //具体化fdisplay +{ + (*fp) << _num << " " << _name << " " //文件输出学号姓名 + << _sex << " " << _age << " " //文件输出性别和年龄 + << _wchar[0] << _chinese << _wchar[1] << _math << _wchar[2] << _English; //文件输出3科成绩 + if (_type == "文科") + { + (*fp) << _wchar[3] << _course1 << _wchar[4] << _course2 ; //文件输出历史和地理 + } + else + { + (*fp) << _wchar[3] << _course1; //文件输出物理或美术 + } + (*fp) << "总分 " << _sum << endl; //文件输出总分 +} +void Student::display() //具体化display(调试的时候写的) +{ + if (BOOL_S[0]) + { + cout << _num << " "; + } + if (BOOL_S[1]) + { + cout << _name << " "; + } + if (BOOL_S[2]) + { + cout << _sex << " "; + } + if (BOOL_S[3]) + { + cout << _age << " "; + } + if (BOOL_T[0]) + { + cout << _wchar[0] << " " << _chinese << " "; + } + if (BOOL_T[1]) + { + cout << _wchar[1] << " " << _math << " "; + } + if (BOOL_T[2]) + { + cout << _wchar[2] << " " << _English << " "; + } + if (BOOL_T[3]) + { + cout << _wchar[3] << " " << _course1 << " "; + } + if (BOOL_T[4]&&_type=="文科") + { + cout << _wchar[4] << " " << _course2 << " "; + } + if (BOOL_T[5]) + { + cout << "总分 " << _sum << " "; + } + cout<< endl; +} +/* 字符串处理 ,根据符号分类添加到容器 */ +vector splitEx(const string& src, string separate_character) +{ + vector strs; + + int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 + int lastPosition = 0, index = -1; + while (-1 != (index = src.find(separate_character, lastPosition))) + { + strs.push_back(src.substr(lastPosition, index - lastPosition)); + lastPosition = index + separate_characterLen; + } + string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 + if (!lastString.empty()) + strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队 + return strs; +} +int main() +{ + fstream file_one("F://data_student.txt"); //打开第一个文件 + if (!file_one) //如果打开失败 + { + cout << "open error!" << endl;//显示出错信息 + abort();//程序退出 + } + vectorstu_data; //定义一个空的stu_date容器,储存文件的全部信息 + do + { + Student stu; + if (stu.finput(&file_one)) //调用finpu(),输入成绩 + { + stu_data.push_back(stu); //添加对象到容器末端 + } + else + { + file_one.close(); //关闭文件 + break; //跳出循环 + } + } while (true); + vectordata_two[5]; //定义一个容器数组 + //遍历stu_data + for (auto it = stu_data.begin(); it != stu_data.end(); ++it) + { + if ((*it)._place == "广州") + { + data_two[0].push_back(*it); //添加到data_two[0] + } + else if ((*it)._place == "汕头") + { + data_two[1].push_back(*it); //添加到data_two[1] + } + else if ((*it)._place == "珠海") + { + data_two[2].push_back(*it); //添加到data_two[2] + } + else if ((*it)._place == "湛江") + { + data_two[3].push_back(*it); //添加到data_two[3] + } + else if ((*it)._place == "深圳") + { + data_two[4].push_back(*it); //添加到data_two[4] + } + } + vectordata_three[5][3]; + for (size_t i = 0; i < 5; ++i) + { + for (auto it = data_two[i].begin(); it != data_two[i].end(); ++it) + { + if (it->_type == "文科") + { + data_three[i][0].push_back(*it); // 添加到data_two[i][0] + } + else if (it->_type == "理科") + { + data_three[i][1].push_back(*it);//添加到data_two[i][1] + } + else if (it->_type == "艺术") + { + data_three[i][2].push_back(*it); //添加到data_two[i][2] + } + } + } + System(); + //string str="P(汕头)+Q(艺术,文科,理科)+S(学号,姓名,性别)+T(总分)-Q()-P()-S(学号)%T(总分)"; + string str; + cin >> str; + if (str.find("%T(")<1000){ + BOOL_GRADE = str.substr(str.find("%T") + 3, 4); + str = str.substr(0, str.find("%T")); + } + else + { + cout << "请输入正确语法" << endl; + } + vector strs1 = splitEx(str, "-"); + vector strs2 = splitEx(strs1[0], "+"); + //删除掉"-"号前的字符串 + strs1.erase(strs1.begin()); + //+的情况 + for (unsigned int i = 0; i < strs2.size(); i++) + { + if ( strs2[i].find("P") < 1000) + { + int is_ture = 1; + if ( strs2[i].find("广州") < 1000) + { + BOOL_PLACE[0] = 1; + is_ture = 0; + } + if ( strs2[i].find("汕头") < 1000) + { + BOOL_PLACE[1] = 1; + is_ture = 0; + } + if ( strs2[i].find("珠海") < 1000) + { + BOOL_PLACE[2] = 1; + is_ture = 0; + } + if ( strs2[i].find("湛江") < 1000) + { + BOOL_PLACE[3] = 1; + is_ture = 0; + + } + if ( strs2[i].find("深圳") < 1000) + { + BOOL_PLACE[4] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_PLACE[0] = 1; + BOOL_PLACE[1] = 1; + BOOL_PLACE[2] = 1; + BOOL_PLACE[3] = 1; + BOOL_PLACE[4] = 1; + } + + } + else if ( strs2[i].find("Q") < 1000) + { + int is_ture = 1; + if ( strs2[i].find("文科") < 1000) + { + BOOL_TYPE[0] = 1; + is_ture = 0; + } + if ( strs2[i].find("理科") < 1000) + { + BOOL_TYPE[1] = 1; + is_ture = 0; + } + if ( strs2[i].find("艺术") < 1000) + { + BOOL_TYPE[2] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_TYPE[0] = 1; + BOOL_TYPE[1] = 1; + BOOL_TYPE[2] = 1; + } + } + else if ( strs2[i].find("S") < 1000) + { + int is_ture = 1; + if ( strs2[i].find("学号") < 1000) + { + BOOL_S[0] = 1; + is_ture = 0; + } + if ( strs2[i].find("姓名") < 1000) + { + BOOL_S[1] = 1; + is_ture = 0; + } + if ( strs2[i].find("性别") < 1000) + { + BOOL_S[2] = 1; + is_ture = 0; + } + if (strs2[i].find("年龄") < 1000) + { + BOOL_S[3] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_S[0] = 1; + BOOL_S[1] = 1; + BOOL_S[2] = 1; + BOOL_S[3] = 1; + } + } + else if ( strs2[i].find("T") < 1000) + { + int is_ture = 1; + if ( strs2[i].find("语文") < 1000) + { + BOOL_T[0] = 1; + is_ture = 0; + } + if ( strs2[i].find("数学") < 1000) + { + BOOL_T[1] = 1; + is_ture = 0; + } + if ( strs2[i].find("英语") < 1000) + { + BOOL_T[2] = 1; + is_ture = 0; + } + if (strs2[i].find("美术") < 1000 || + strs2[i].find("历史") < 1000 || + strs2[i].find("物理") < 1000 ) + { + BOOL_T[3] = 1; + is_ture = 0; + } + if ( strs2[i].find("地理") < 1000) + { + BOOL_T[4] = 1; + is_ture = 0; + } + if (strs2[i].find("总分") < 1000) + { + BOOL_T[5] = 1; + is_ture = 0; + } + //如果里面没有任何信息 + if (is_ture) + { + BOOL_T[0] = 1; + BOOL_T[1] = 1; + BOOL_T[2] = 1; + BOOL_T[3] = 1; + BOOL_T[4] = 1; + BOOL_T[5] = 1; + } + } + } + + //-的情况 + for (unsigned int i = 0; i < strs1.size(); i++) + { + if (strs1[i].find("P") < 1000) + { + if (strs1[i].find("广州") < 1000) + { + BOOL_PLACE[0] = 0; + } + if (strs1[i].find("汕头") < 1000) + { + BOOL_PLACE[1] = 0; + } + if (strs1[i].find("珠海") < 1000) + { + BOOL_PLACE[2] = 0; + } + if (strs1[i].find("湛江") < 1000) + { + BOOL_PLACE[3] = 0; + } + if (strs1[i].find("深圳") < 1000) + { + BOOL_PLACE[4] = 0; + } + //如果里面没有任何信息 + if (!(BOOL_PLACE[0] || BOOL_PLACE[1] || BOOL_PLACE[2] || BOOL_PLACE[3] || BOOL_PLACE[4])) + { + BOOL_PLACE[0] = 0; + BOOL_PLACE[1] = 0; + BOOL_PLACE[2] = 0; + BOOL_PLACE[3] = 0; + BOOL_PLACE[4] = 0; + } + + } + else if (strs1[i].find("Q") < 1000) + { + if (strs1[i].find("文科") < 1000) + { + BOOL_TYPE[0] = 0; + } + if (strs1[i].find("理科") < 1000) + { + BOOL_TYPE[1] = 0; + } + if (strs1[i].find("艺术") < 1000) + { + BOOL_TYPE[2] = 0; + } + //如果里面没有任何信息 + if (!(BOOL_TYPE[0] || BOOL_TYPE[1] || BOOL_TYPE[2])) + { + BOOL_TYPE[0] = 0; + BOOL_TYPE[1] = 0; + BOOL_TYPE[2] = 0; + } + } + else if (strs1[i].find("S") < 1000) + { + int is_ture = 1; + if (strs1[i].find("学号") < 1000) + { + BOOL_S[0] = 0; + is_ture = 0; + } + if (strs1[i].find("姓名") < 1000) + { + BOOL_S[1] = 0; + is_ture = 0; + } + if (strs1[i].find("性别") < 1000) + { + BOOL_S[2] = 0; + is_ture = 0; + } + if (strs1[i].find("年龄") < 1000) + { + BOOL_S[3] = 0; + is_ture = 0; + } + if (is_ture) + { + BOOL_S[0] = 0; + BOOL_S[1] = 0; + BOOL_S[2] = 0; + BOOL_S[3] = 0; + } + + } + else if (strs1[i].find("T") < 1000) + { + int is_ture = 1; + if (strs1[i].find("语文") < 1000) + { + BOOL_T[0] = 0; + is_ture = 0; + } + if (strs1[i].find("数学") < 1000) + { + BOOL_T[1] = 0; + is_ture = 0; + } + if (strs1[i].find("英语") < 1000) + { + BOOL_T[2] = 0; + is_ture = 0; + } + if (strs1[i].find("美术") < 1000 || + strs1[i].find("历史") < 1000 || + strs1[i].find("物理") < 1000) + { + BOOL_T[3] = 0; + is_ture = 0; + } + if (strs1[i].find("地理") < 1000) + { + BOOL_T[4] = 0; + is_ture = 0; + } + if (strs1[i].find("总分") < 1000) + { + BOOL_T[5] = 0; + is_ture = 0; + } + if (is_ture) + { + BOOL_T[0] = 0; + BOOL_T[1] = 0; + BOOL_T[2] = 0; + BOOL_T[3] = 0; + BOOL_T[4] = 0; + BOOL_T[5] = 0; + } + + } + } + for (size_t i = 0; i < 5; ++i) + { + //如果开关是开的 + if (BOOL_PLACE[i]) + { + cout << (*data_two[i].begin())._place << endl << endl; + } + else + { + continue; + } + for (size_t j = 0; j < 3; ++j) + { + //如果开关是开的 + if (BOOL_TYPE[j]) + { + cout << (*data_three[i][j].begin())._type << " : " << endl; + //按总分降序排序 + if (BOOL_GRADE == "总分") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greatersum); + } + else if (BOOL_GRADE == "英语") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greaterEnglish); + } + else if (BOOL_GRADE == "数学") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greatermath); + } + else if (BOOL_GRADE == "语文") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greaterchinese); + } + else if (BOOL_GRADE == "物理" || BOOL_GRADE == "历史" || BOOL_GRADE == "美术") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greatercourse1); + } + else if (BOOL_GRADE == "地理") + { + sort(data_three[i][j].begin(), data_three[i][j].end(), greatercourse2); + } + else + { + cout << "请输入正确语法" << endl; + break; + } + for (auto it = data_three[i][j].begin(); it != data_three[i][j].end(); ++it) + { + + //把数据读进student.txt + it->display(); + } + } + } + + } + +} \ No newline at end of file diff --git "a/\351\253\230\350\200\203\351\242\204\345\275\225\347\263\273\347\273\237.doc" "b/\351\253\230\350\200\203\351\242\204\345\275\225\347\263\273\347\273\237.doc" new file mode 100644 index 0000000000000000000000000000000000000000..8464f79f09e40d97326f1b6d0f0e2782483b78d4 Binary files /dev/null and "b/\351\253\230\350\200\203\351\242\204\345\275\225\347\263\273\347\273\237.doc" differ