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

📄 cpp1.cpp

📁 我的期末课程设计
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iomanip>
#include <iostream>
#include <conio.h>
#include <string>
#include<fstream>

using namespace std;

struct student
{
char name[10];         ///   姓名
char id[10];           ///   学号
float Ynum;            ///   语文分数
float Snum;            ///   数学分数
float Enum;            ///   英语分数
float number;          ///   总分
student *next;
};
///////////-------------定义类-----------------------////////////

class stud
{
    student *p1,*p2,*head;
public:

  ~stud() /////----析构函数------------------------
{

while(head)
{
  p1=head->next;
  delete head;
  head=p1;
}
}
///------------成员函数------------
void output(student *head);              //  输出学生成绩
student *lookup(student *head);          //统计学生单科成绩
student *input(student *head);           //  增加学生记录
student *del(student *head, char*p);     //  删除记录
student *find1(student *head,char *p,int &n);  // 查找学生记录(可查找多个同名数据)
student *find2(student *head,char *p,int &n);
student *stat(student *head);           //排序统计学生总分
friend void total(student *head);       //统计学生总分
student *insert(student *head);         //按学生总分插入记录
student *clear(student *head);          // 删除当前表
 void Inputs(student *p);               //用于添加数据的子函数 
};//----------------------------------------------------



////---------用于添加数据的子函数-------///////
void stud::Inputs(student *p)
{
	int n;
   cout<<setw(6)<<"姓名"<<setw(8)<<" 学号"
<<setw(8)<<"语文"<<setw(8)<<"数学"
<<setw(8)<<"英语"<<endl;

   cin>>p->name >>p->id;
   cin >>p->Ynum;

  cin>>p->Snum;

  cin>>p->Enum;

  cout<<"您需要修改的是:0.不需要 1.名字 2.学号 3.语文 4.数学 5.英语"<<endl;
  cin>>n;
  if(n==0)
  {}
  if(n==1)
  {cout<<"修改为:"<<endl;
  cin>>p->name;}
  if(n==2)
	 { cout<<"修改为:"<<endl;
  cin>>p->id;}
  if(n==3)
	 { cout<<"修改为:"<<endl;
  cin>>p->Ynum;}
  if(n==4)
	 { cout<<"修改为:"<<endl;
  cin>>p->Snum;}
  if(n==5)
	 { cout<<"修改为:"<<endl;
  cin>>p->Enum;}

  total(p);                         ///计算出总分
}

////////-----对于成绩的统计-------///////////
student* stud::lookup(student *head)
{p2=head;
int n;
float a,b;
 cout<<"请输入您想要统计的课程名:1.语文 2.数学 3.外语"<<endl;
 cin>>n;
 cout<<"请输入你想要统计的分数段:"<<endl;
 cin>>a>>b;
 while(p2!=NULL)
 {
 if(n==1)
 {
   if(p2->Ynum>a&&p2->Ynum<b)
    cout<<setw(6)<<p2->name<<setw(8)
   <<p2->id<<setw(8)<<p2->Ynum
   <<setw(8)<<p2->Snum <<setw(8)
   <<p2->Enum <<setw(8)<<p2->number <<endl;
 }
  if(n==2)
 {
   if(p2->Snum>a&&p2->Snum<b)
    cout<<setw(6)<<p2->name<<setw(8)
   <<p2->id<<setw(8)<<p2->Ynum
   <<setw(8)<<p2->Snum <<setw(8)
   <<p2->Enum <<setw(8)<<p2->number <<endl;

  }
    if(n==3)
 {
   if(p2->Enum>a&&p2->Enum<b)
    cout<<setw(6)<<p2->name<<setw(8)
   <<p2->id<<setw(8)<<p2->Ynum
   <<setw(8)<<p2->Snum <<setw(8)
   <<p2->Enum <<setw(8)<<p2->number <<endl;

	}
	p2=p2->next;
}//---------------------------------while
   return head;
 
}
 
////////-----输出学生成绩---------///////////
void stud::output (student *head)
{ p1=head;
	ofstream outfile;
	outfile.open("out.tax");
while(p1!=NULL)
{
   cout<<setw(6)<<p1->name<<setw(8)
   <<p1->id<<setw(8)<<p1->Ynum
   <<setw(8)<<p1->Snum <<setw(8)
   <<p1->Enum <<setw(8)<<p1->number <<endl;
       outfile<<setw(6)<<"姓名"<<setw(8)<<" 学号"
<<setw(8)<<"语文"<<setw(8)<<"数学"
<<setw(8)<<"英语"<<setw(8)<<"总分!"<<endl;
    outfile<<setw(6)<<p1->name<<setw(8)
   <<p1->id<<setw(8)<<p1->Ynum
   <<setw(8)<<p1->Snum <<setw(8)
   <<p1->Enum <<setw(8)<<p1->number <<endl;
p1=p1->next ;
}
outfile.close();
}
/////////------------插入学生成绩记录--------////////////////
student* stud::insert(student *head)
{   
p1=new student;
 Inputs(p1); //调用子函数 增加数据
 
      p2=head;
 p1=p2->next;
      
 return head;
}
//////----------清空数据------------/////////////
student* stud::clear(student *head)
{   
    while(head)
{   p1=head->next ;
      delete head;
   head=p1;
   }
    return head;
}
//////////-----------排序统计函数-----------/////////////////
student *stud::stat(student *head)
{
int m,n;
p2=head;
p1=p2->next;
cout<<"您想按何种方式排序:1.总分 2.语文 3.数学 4.英语"<<endl;
cin>>m;
if(m==1)
{
cout<<"您想以何种方式排序:1.升序 2.降序"<<endl;
cin>>n;
if(n==1)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->number > p1->number)
   {         // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }
   else
   {           // 指向下一个节点
    p2=p2->next ;
    p1=p2->next ;
   }//-------------------------------------------

}
cout<<"!!当前表以按学生总分升序排序成功!!"<<endl;
return head;
}

if(n==2)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->number < p1->number)
   {             // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }
   else
   {            // 指向下一个节点
    p2=p2->next ;
    p1=p2->next ;
   }//-------------------------------------------

}
cout<<"!!当前表以按学生总分降序排序成功!!"<<endl;
return head;
}
}

if(m==2)
{
cout<<"您想以何种方式排序:1.升序 2.降序"<<endl;
cin>>n;
if(n==1)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->Ynum > p1->Ynum)
   {         // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }
   else
   {           // 指向下一个节点
    p2=p2->next ;
    p1=p2->next ;
   }//-------------------------------------------

}
cout<<"!!当前表以按学生语文成绩升序排序成功!!"<<endl;
return head;
}

if(n==2)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->Ynum < p1->Ynum)
   {             // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }
   else
   {            // 指向下一个节点
    p2=p2->next ;
    p1=p2->next ;
   }//-------------------------------------------

}
cout<<"!!当前表以按学生语文成绩降序排序成功!!"<<endl;
return head;
}
}

if(m==3)
{
cout<<"您想以何种方式排序:1.升序 2.降序"<<endl;
cin>>n;
if(n==1)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->Snum > p1->Snum)
   {         // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }
   else
   {           // 指向下一个节点
    p2=p2->next ;
    p1=p2->next ;
   }//-------------------------------------------

}
cout<<"!!当前表以按学生数学成绩升序排序成功!!"<<endl;
return head;
}

if(n==2)
{
while(p2->next)  //冒泡泡法
{ 
    
   if(p2->Snum < p1->Snum)
   {             // 把头指针指向当前比较小的节点
     p2->next=p1->next;     
     p1->next=head;        
     head=p1;

                // 把用于比较的两个指针复位             
        
     p1=p2->next;
   }

⌨️ 快捷键说明

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