⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpp9.cpp

📁 是学语言的课程设计,好象是查找或是迷宫
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
class List;    
class Time   
{
 public:
	 int year,month,day;
};

class ListNode
{
public:
	friend class List;
	ListNode()
	{	No=age=0;
		strcpy(name,"无");
		strcpy(sex,"无");
		link=NULL;
	}
private :
	int No,age; //学号,年龄
	
	char name[80],sex[10];//姓名,性别

	
	char learn[20];//学习状况

	char major[100];//专业
	char school[100];//所在院校
	char department[100];//所在班级	
	
	
	
	Time start;
	char English[20];
	char shuxue[20];
	char C[20];
	double sum;


	ListNode *link;
};
//////////////////
class List
{
public:
	List()
	{	first=new ListNode;
		first->link=NULL;
		Nodesum=0;
	}
	int Insert(ListNode*);//插入一个节点
	int Remove();//按学号删除
	void Show_List();//显示学生信息
	void DisplayOneStu();//显示一个学生的信息
	int Set_No(ListNode *p);//数据输入
	ListNode* Find_Link(int);//按学号查找同学的前一个同学的指针
	ListNode * Find_Name(char *a );//
	void Modify();
private:
	int Nodesum;
	ListNode *first;//指向头结点
};
int List::Set_No(ListNode *p)//数据输入
	{
	cout<<"学号:";cin>>p->No;
	cout<<"姓名:";cin>>p->name;
	cout<<"性别:Male or Female?";  cin>>p->sex;
	cout<<"年龄:"; cin>>p->age;

	
//	char st[10]; gets(st);
	cout<<"学习状况:"; cin>>p->learn;
	
	cout<<"入学时间:"; cin>>p->start.year>>
		p->start.month>>p->start.day;
	cout<<"班级:"; cin>>p->department;	
	
	cout<<"专业:"; cin>>p->major;
	cout<<"所在院校:"; cin>>p->school;
	
	


	cout<<"英语:"; cin>>p->English;
	cout<<"数学:"; cin>>p->shuxue;
	cout<<"C ++:"; cin>>p->C;

		return 1;
	}
int List::Insert(ListNode* ln)//插入
{      
	Nodesum++;
	ListNode *p=first,*q; 
//	Set_No(ListNode *ln);
	if(p->link==NULL)
	{
		ln->link=NULL;
		first->link=ln;  
		return 1;
	}
	while(p&&p->No<=ln->No) {  	q=p; p=p->link;	}
	if(q->No==ln->No) 		return 0;//不能有相同的学号
	if(p==NULL)//当p达到末尾
	{
		ln->link=NULL;		
		q->link=ln;
	}
	else 
	{	ln->link=p;
		q->link =ln;		
	}
	return 1;
}
ListNode* List::Find_Link(int Dum)//按学号查询
{
	ListNode* p=first,*q;
	while(p&&p->No!=Dum)     //Be Careful Here while(p->No!=Dum&&p) is wrong 
	{ 
		q=p;
		p=p->link;
	}
	if(p==NULL)//没找到 
	{
		cout<<"Find failure! No this Number!"<<endl;
		return q;
	}
	else return q;
}
ListNode *List::Find_Name(char *st)//按名字查询
{
	ListNode* p=first,*q;

	while(p&&strcmp(p->name,st)!=0)//不能写while(strcmp(p->name,st)!=0&&p)
	{
		q=p;
		p=p->link;
	}
	if(p==NULL) 
	{
		cout<<"Find failure! No this Name"<<endl;
		return q;
	}
	else return q;
}
void List::Modify()//修改信息
{
	int n;
	ListNode *p= new ListNode;
	cout<<"请输入要修改的学生的学号:";
	cin>>n; 
	p=Find_Link(n)->link;
	if(p==NULL)
	{
		cout<<"Find failure!"<<endl;
		return ;
	}
	cout<<"该学生当前的信息为:"<<endl;
	  printf("\t     * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");
     // printf("\t     *                                                   * \n");
      printf("\t     *                 学生基本资料修改                  * \n");
     // printf("\t     *                                                   * \n");
      printf("\t     * * * * * * * * * * * * * * * * * * * * * * * * * * * \n");

	printf("    |----------------------------------------------------------------------|\n");
	printf("    |*****************************学生基本信息*****************************|\n");
	//printf("    |----------------------------------------------------------------------|\n");
    printf("    |----------------------------------------------------------------------|\n");
    printf("    |  学生号    |  姓  名     |  性 别   |   年 龄   |    \n");//
    printf("    |----------------------------------------------------------------------|\n");
    printf("    |  %-10d|  %-11s|",p->No,p->name); 
	   
	if(p->sex[0]=='F'||p->sex[0]=='f') printf("    男    |"); 
	else if(p->sex[0]=='M'||p->sex[0]=='m') printf("    女    |") ;
	else printf("    无    | ");

	printf("   %-7d|    %6d/%-2d/%-6d|\n");

	printf("    |----------------------------------------------------------------------|\n");
	printf("    |学习状况|       \n");
	printf("    |----------------------------------------------------------------------|\n");
	printf("    | %-7s|%-17s|%-22s|%-20s|\n",p->learn);
	printf("    |----------------------------------------------------------------------|\n");
	printf("    |****************************学生成绩管理信息******************************|\n");
    printf("    |----------------------------------------------------------------------|\n");
	printf("    |      班级       | \n");//
	printf("    |----------------------------------------------------------------------|\n");
    printf("    | %-16s| %-17s| %-17s| %-13s|\n");
	printf("    |----------------------------------------------------------------------|\n");
    printf("    |           所在院校           |         专 业        |    入学时间    |\n");
	printf("    |----------------------------------------------------------------------|\n");
    printf("    |  %-28s|  %-20s|  /%-4d/%-2d/%-2d   |\n",p->school,p->major,p->start.year,p->start.month,p->start.day);
	printf("    |----------------------------------------------------------------------|\n");
	printf("    |****************************学生成绩统计情况**************************|\n");
	printf("    |----------------------------------------------------------------------|\n");
	printf("    |          英语           |         数学          |        C++         |总分| 平均分|不及格科目|\n");
	printf("    |----------------------------------------------------------------------|\n");
	printf("    |          %-7s        |         %-7s       |       %-7s    |\n",p->English,p->shuxue,p->C++,p-总分,p-平均分,
	printf("    |----------------------------------------------------------------------|\n");    
	Set_No(p);
}
int List::Remove()//信息删除
{
	Nodesum--;
	int n; cout<<"请输入要删除的学号:"; 
	cin>>n;
	ListNode *p=Find_Link(n),*q;	
	if(p->link==NULL) 
	{
		cout<<"Delete Failure!"<<endl;
		return 0;
	}
	else
	{	q=p->link;
		p->link=p->link->link;
	}
printf("操作成功\n");
	delete q;
	return 0;
}
void List::DisplayOneStu()//查询一个学生的基本信息
{
	ListNode *p=new ListNode;
pp:; cout<<"请选择要查询的方式"<<endl;
	cout<<"1:学号"<<endl;
	cout<<"2:姓名"<<endl;
	int n; scanf("%d",&n);
	if(n==1)
	{ 	printf("请输入要查询的学号:");
		scanf("%d",&n);
		p=Find_Link(n)->link;
		if(p==NULL)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -