C语言课程设计 简单的单词学习系统 (2)

#include
#include
#include
#include
#include
//定义单词结构体 
typedef struct word{
	char e[100];
	char c[100];
}word;
typedef struct phy{
	char e[100];   //英 
	char c[100];   //汉 
}phy;
//定义单词库 
typedef struct word_list{
	word list[20];
	int length;
}word_list;
typedef struct phy_list{
	phy list[20];
	int length;
}phy_list;
word_list Word;
phy_list Phy;
void create();
int max(int,int);
void add();
void del();
void pr();
void update();
int exc(int);
int wordlearn(int);
void startLearn();
//创建单词库 
void create(){
	int n;
	printf("创建单词库(1)还是词组库(2)?\n");
	scanf("%d",&n);
	system("cls");
	switch(n){
		case 1:
			Word.length = 0;
			printf("单词库创建成功!\n");
			break;
		case 2:
			Phy.length = 0;
			printf("词组库创建成功!\n");
			break;
		default:
			printf("选择错误!\n");
	}
	 
}
//最大值函数 
int max(int a , int b){
	return a > b ? a:b;
}
//增加单词 
void add(){
	printf("请输入单词英文和中文(换行输入):\n");
	scanf("%s%s",Word.list[Word.length].e,Word.list[Word.length].c);
	Word.length++;
}
void add2(){
	printf("请输入词组英文和中文(换行输入):\n");
	scanf("%s%s",Phy.list[Phy.length].e,Phy.list[Phy.length].c);
	Phy.length++;
}
//删除单词 
void del(){
	printf("请输入要删除的单词序号:\n");
	int n,j;
	scanf("%d",&n);
	if(n > Word.length){
		printf("未找到该单词!\n");
		return;
	}
	for(j = n-1 ; j < Word.length-1 ; j++){
		Word.list[j] = Word.list[j+1];
	}
	Word.length--;
	printf("删除成功!\n");
}
void del2(){
	printf("请输入要删除的词组序号:\n");
	int n,j;
	scanf("%d",&n);
	if(n > Phy.length){
		printf("未找到该词组!\n");
		return;
	}
	for(j = n-1 ; j < Phy.length-1 ; j++){
		Phy.list[j] = Phy.list[j+1];
	}
	Phy.length--;
	printf("删除成功!\n");
}
//打印单词库 
void pr(){
	if(Word.length == 0){
		printf("词库中没有单词!\n");
	}
	printf("******单词词库内容******\n");
	
	int i;
	for(i = 0 ; i < Word.length ; i++){
		printf("%s  %s\n",Word.list[i].e,Word.list[i].c);
	}
}
void pr2(){
	if(Phy.length == 0){
		printf("词库中没有词组!\n");
	}
	printf("******词组库内容******\n");
	
	int i;
	for(i = 0 ; i < Phy.length ; i++){
		printf("%s  %s\n",Phy.list[i].e,Phy.list[i].c);
	}
}
//更新系统 
void update(){
	int flag = 1;
	int n;
	while(flag){
		printf("*******更新系统*******\n");
		printf("****1.添加单词 2.删除单词*****\n");
		printf("****3.查看单词词库 4.退出 ********\n");
		printf("****5.添加词组 6.删除词组*****\n");
		printf("****7.查看词组库   ") ; 
		scanf("%d",&n);
		system("cls");
		switch(n){
			case 1:
				add();
				break;
			case 2:
			    del(); 
			    break;
			case 3:
				pr();
				break;
			case 4:
				flag = 0;
				break;
			case 5:
				 add2();
				 break;
			case 6:
				del2();
				break;
			case 7:
				pr2();
				break;
			default:
				printf("输入错误!\n");
				 
		}
	}
}
//回答题目 
int exc(int grade){
	if(Word.length == 0){
		printf("单词库中空空如也,请先去完善单词库!\n");
		return 0;
	}
	srand(time(0));
	int number = 0;
	int score = 0;
	int r;
	char temp[100];
	//等级1 
	if(grade == 1){
		while(number < 10){
			r = rand()%10 + 1;
			printf("英:%s\n",Word.list[r].e);
			printf("中:");
			scanf("%s",temp);
			if(strcmp(temp,Word.list[r].c) == 0){
				score += 10;
				printf("回答正确!\n");
			}else{
				while(1){
					printf("回答错误!请重新回答:\n");
					scanf("%s",temp);
					if(strcmp(temp,Word.list[r].c) == 0){
						printf("回答正确,但不是一次答对,所以不加分!\n");
						break;
					}
				} 
			}
			number++;
		}
	}
	//等级2 
	if(grade == 2){
		while(number < 10){
			r = rand()%10 + 11;
			printf("英:%s\n",Word.list[r].e);
			printf("中:");
			scanf("%s",temp);
			if(strcmp(temp,Word.list[r].c) == 0){
				score += 10;
				printf("回答正确!\n");
			}else{
				while(1){
					printf("回答错误!请重新回答:\n");
					scanf("%s",temp);
					if(strcmp(temp,Word.list[r].c) == 0){
						printf("回答正确,但不是一次答对,所以不加分!\n");
						break;
					}
			}
			number++;
		}
	}
	return score; //返回分数 
}
}
int exc2(int grade){
	if(Word.length == 0){
		printf("词组库中空空如也,请先去完善单词库!\n");
		return 0;
	}
	srand(time(0));
	int number = 0;
	int score = 0;
	int r;
	char temp[100];
	//等级1 
	if(grade == 1){
		while(number < 10){
			r = rand()%10 + 1;
			printf("英:%s\n",Phy.list[r].e);
			printf("中:");
			scanf("%s",temp);
			if(strcmp(temp,Phy.list[r].c) == 0){
				score += 10;
				printf("回答正确!\n");
			}else{
				while(1){
					printf("回答错误!请重新回答:\n");
					scanf("%s",temp);
					if(strcmp(temp,Phy.list[r].c) == 0){
						printf("回答正确,但不是一次答对,所以不加分!\n");
						break;
					}
				} 
			}
			number++;
		}
	}
	//等级2 
	if(grade == 2){
		while(number < 10){
			r = rand()%10 + 11;
			printf("英:%s\n",Phy.list[r].e);
			printf("中:");
			scanf("%s",temp);
			if(strcmp(temp,Phy.list[r].c) == 0){
				score += 10;
				printf("回答正确!\n");
			}else{
				while(1){
					printf("回答错误!请重新回答:\n");
					scanf("%s",temp);
					if(strcmp(temp,Phy.list[r].c) == 0){
						printf("回答正确,但不是一次答对,所以不加分!\n");
						break;
					}
			}
			number++;
		}
	}
	return score; //返回分数 
}
}
//单词学习 
int wordlearn(int grade){
	int score = 0;
	int flag = 1;
	while(flag){
	printf("请选择:\n");
	printf("1.学习 2.退出\n");
	int n ;
	scanf("%d",&n);
	system("cls");
	switch(n){
		case 1:
			score = max(score,exc(grade));
			break;
		case 2:
			flag = 0;
			break;
		default:
			printf("输入错误!\n");
	}
    }
    return score;
}
int phylearn(int grade){
	int score = 0;
	int flag = 1;
	while(flag){
	printf("请选择:\n");
	printf("1.学习 2.退出\n");
	int n ;
	scanf("%d",&n);
	system("cls");
	switch(n){
		case 1:
			score = max(score,exc2(grade));
			break;
		case 2:
			flag = 0;
			break;
		default:
			printf("输入错误!\n");
	}
    }
    return score;
}
//学习系统 
void startLearn(){
	int flag = 1;
	int n;
	int score = 0;
	int score2 = 0;
	int grade = 1;
	int grade2 = 1;
	while(flag){
		printf("*******学习系统********\n");
		printf("***1.单词学习  2.词组学习******\n");
		printf("***3.等级查看  4.称号查看******\n");
		printf("***0.退出系统  *****\n");
		scanf("%d",&n);
		system("cls");
		switch(n){
			case 1:
				score = max(score ,wordlearn(grade));
				if(score >= 80 && grade < 2){
					grade++;
				}
				break;
			case 2:
				score2 = max(score2, phylearn(grade2));
				if(score2 >= 80 && grade2 < 2){
					grade++;
				}
				break;
			case 3:
				printf("您现在的单词等级是%d\n",grade);
				printf("您现在的词组等级是%d\n",grade2); 
				break;
			case 4:
			    if(grade == 1 && grade2 == 1){
			    	printf("无称号\n");
			    	break;
				} 
				printf("您现在的称号是:\n");
				if(grade == 2){
					printf("单词小霸王\n");
				}
				if(grade2 == 2){
					printf("词组小天才\n");
				}
				if(grade == 1 && grade2 == 1){
					printf("初出茅庐\n");
				}
				if(score == 100 && score2 == 100){
					printf("人生巅峰\n");
				}
				break;
			case 0:
				flag = 0;
				break;
			default:
				printf("输入错误!\n");
		}
		
	}
}
//主菜单 
int menu(){
	int n;
	int flag = 1;
	while(flag){
	printf("*********欢迎来到小学生英语学习系统*********\n");
	printf("*********1.新建词库 2.更新词库********\n");
	printf("*********3.开始学习 4.退出    ********\n");
	printf("**********************************************\n");
	scanf("%d",&n);
	system("cls");
	switch(n){
		case 1: 
		create();
		break;
		case 2:
		update(); 
		break;
		case 3:
		startLearn();
		break;
		case 4:
		flag = 0;
		printf("退出成功!\n");
		break;
		default:
		printf("输入错误!\n");
		}
   }
}
//主函数 
int main(){
	menu();
	return 0;
}



 

你可能感兴趣的:(c语言,开发语言)