📄 32.cpp
字号:
// 32.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream.h>
#include<stdlib.h>
struct student //学生信息结构体
{
int num;
char name[20];
float elec;
float c_prog;
float media;
float eng;
float mach;
float sport;
float polity;
float ave;
int order;
struct student *next;
};
struct student *creat(struct student *head)
{
struct student *p1,*p2;
p1=p2=(struct student*) malloc(sizeof(struct student)); // 申请新节点
cin>>p1->num>>p1->name>>p1-> elec>>p1-> c_prog>>p1-> media>>p1-> eng>>p1-> mach>>p1-> sport>>p1->polity>>p1-> ave;// 输入节点的值
p1-> next = NULL;
for(int i=1;i<=9;i++)
{
if (head==NULL) head=p1; //空表,接入表头
else p2->next=p1; // 非空表,接到表尾
p2 = p1;
p1=(struct student *)malloc(sizeof(struct student));
if(i<=9)
{
cin>>p1->num>>p1->name>>p1-> elec>>p1-> c_prog>>p1-> media>>p1-> eng>>p1-> mach>>p1-> sport>>p1-> polity>>p1-> ave;
}
//
};
return head;
}
void count(struct student *head)
{
struct student *temp;
temp=head; //取得链表的头指针
for(int i=1;i<=n;i++)
{
int m;
m=temp->foxscore+temp->cscore+temp->englishscore;
cout<<m<<endl;//输出链表节点的值
temp=temp->next; //跟踪链表增长
}
}
void sort(struct student *head) //排序函数
{
struct student *tp;
tp=head;
int a[9];//定义平均分数组
int i,j,k;
a[1]=(tp->elec+tp1->c_prog+tp1->media+tp1->eng+tp1->mach+tp1->sport+tp1->polity+tp1-> ave)/8;
tp=tp->next;
a[2]=(tp->elec+tp1->c_prog+tp1->media+tp1->eng+tp1->mach+tp1->sport+tp1->polity+tp1-> ave)/8;
tp=tp->next;
a[3]=(tp->elec+tp1->c_prog+tp1->media+tp1->eng+tp1->mach+tp1->sport+tp1->polity+tp1-> ave)/8;
tp=tp->next;
a[4]=(tp->elec+tp1->c_prog+tp1->media+tp1->eng+tp1->mach+tp1->sport+tp1->polity+tp1-> ave)/8;
for(j=1;j<=3;j++)//冒泡法排序 按平均分排序
for(k=1;k<=4-j;k++)
if(a[k]<a[k+1])
{
int t=a[k];a[k]=a[k+1];a[k+1]=t;
}
for(i=1;i<5;i++)
cout<<a[i]<<endl;
}
void lookup(struct student *head) //查询函数
{
struct student *temper;
temper=head;
int number;
cout<<"请输入要查询的学生学号:";
cin>>number;
for(int i=1;i<=n;i++)
{
if(number==temper->num) //找到后输出学生信息
{
cout<<" name is:"<<temper->name<<endl;
cout<<" elec is:"<<temper->elec <<endl;
cout<<" c_prog is:"<<temper->c_prog<<endl;
cout<<" media is:"<<temper->media<<endl;
cout<<" eng is:"<<temper->eng<<endl;
cout<<" mach is:"<<temper->mach<<endl;
cout<<" sport is:"<<temper->sport<<endl;
cout<<" polity is:"<<temper->polity<<endl;
}
temper=temper->next;
}
}
void Modify(struct student *head) //修改函数
{
int i=0;
char c;
cout<<"你要修改的学生姓名是:"<<endl;
cin>>name;
do{
stu *s[20];
s[i]=new stu(name,elec,cprog,media,eng,math,sport,polity,ave,sum);
i++;
bool flag1=0;
for(int h=0;h<i,h++)
{
if(strcmp(name,*s[hend]->name)==0)
{
bool flag1=1;
cout<<"请修改:";
cin>>student;
s[hend]->elec=elec;s[hend]->cprog=cprog; s[hend]->media=media;
s[hend]->eng=eng;s[hend]->math=math;s[hend]->sport=sport;s[hend]->polity=polity;
}
if(flag1=0)
{
cout<<"输入错误!"<<endl;
cout<<"是否重新修改?(y/n)"<<endl;
cin>>c;
}
}
}while(c='y');
break;
}
void Delete(struct student *head) //删除函数
{
stu *s[20];
char c;
int i=0;
cout<<"输出你要删除的姓名:"<<endl;
cin>>name;
do{
s[i]=new stu(name,num,elec,cprog,eng,math,sport,media,polity,ave,order);
i++;
for(int p=0,p<i,p++);
{
bool flag2=0;
if(strcmp(name,*s[p]->name)==0)
{
bool flag2=1;
s[p]->name=s[p+1]->name;
s[p]->num=s[p+1]->num;
s[p]->elec=s[p+1]->elec;
s[p]->cprog=s[p+1]->cprog;
s[p]->eng=s[p+1]->eng;
s[p]->math=s[p+1]->math;
s[p]->sport=s[p+1]->sport;
s[p]->media=s[p+1]->media;
s[p]->polity=s[p+1]->polity;
s[p]->ave=s[p+1]->ave;
s[p]->order=s[p+1]->order;
}
}
}while(c='y');
break;
}
void Output(struct student *head) //输出函数
{
stu *s[20];
int i=0;
s[i]=new stu(num,name,elec,cprog,media,eng,math,sport,polity,ave,order);
i++;
bool flag3=0;
cout<<"输出班级学生成绩记录如下:"
for(int u=0;u<i;u++)
{
bool flag3=1
cout<<*s[u]->num<<" "<<*s[u]->name<<"电工电子"<<*s[u]->elec<<"c++"<<*s[u]->cprog<<"多媒体"<<*s[u]->media<<"英语"<<*s[u]->eng<<"高数"<<*s[u]->math<<"体育"<<*s[u]->sport<<"政治"<<*s[u]->polity<<endl;
cout<<"平均成绩"<<*s[u]->ave<<"总成绩"<<*s[u]->order<<endl;
}
if(flag3==0)
{
cout<<"无法查询 "<<endl;
}
}
void Insert() //插入函数
{
float x,y;
char c;
stu *s[20];int i=0;
do{
s[i]=new stu(name,ave);
i++;
bool flag5=0;
for(int p=0;p<i;p++)
{
flag=1
cin>>y;
cin>>name;
if(*s[p]->ave<y)
{
x=*s[p]->ave;
*s[p]->ave=y;
y=x;
*s[p]->name=name;
}
if(flag5=0)
{
cout<<"输入错误!"<<endl;
cout<<"是否重新输入?(y/n)"<<endl;
cin>>c;
}
}
}while(c='y');
break;
}
void main() //主函数
{
menu(){cout<<"请输入学生的信息"<<endl;
}
struct student *head;
head=NULL; /* 建一个空表*/
head=creat(head); /* 创建单链表*/
count(head);
sort(head);
lookup(head);
Modify(head);
Output(head);
Delete(head);
Insert(head);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -