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

📄 项目.cpp

📁 以上源码都能完成相应功能!是基础编程者学习着的好资料!
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
ifstream in("student.txt");
class XX
{
public:
    string xm;
    string xh;
    string xb;

    void accept()
           {
             
             cout<<"请输入学号:"<<endl;
             cin>>xh;
             cout<<"请输入性别:"<<endl;
             cin>>xb;
           }
    void  display()
           { 
			 cout<<endl<<endl<<endl;
			 cout<<"**********************************个人信息输入完毕******************************";
             cout<<"姓名:"<<xm<<endl;
             cout<<"学号:"<<xh<<endl;
             cout<<"性别:"<<xb<<endl;
			 cout<<"********************************************************************************"<<endl;
			
           }
};
class LX
{
public:
   string  QQ;
   string sj;

   void accept()
           {
           cout<<"请输入QQ号码:"<<endl;
           cin>>QQ;
           cout<<"请输入手机号码:"<<endl;
           cin>>sj;
           
           }
    void  display()
   {    
	    cout<<endl<<endl<<endl;
		cout<<"**********************************联系方式输入完毕******************************";
        cout<<"QQ号码:"<<QQ<<endl;
        cout<<"手机号码:"<<sj<<endl;
		cout<<"********************************************************************************"<<endl;
		
   }

};

class CJ
{
public:
        string GS;
        string YY;
        string NIIT;
        string WL;

	void accept()
	{
	    cout<<"高数成绩:"<<endl;
	    cin>>GS;
	    cout<<"英语成绩:"<<endl;
	    cin>>YY;
	    cout<<"NIIT成绩:"<<endl;
	    cin>>NIIT;
	    cout<<"大学物理成绩:"<<endl;
	    cin>>WL;
        
	}
	void display()
	{   
		cout<<endl<<endl<<endl;
		cout<<"**********************************大学成绩输入完毕******************************";
	    cout<<"高数成绩:"<<GS<<endl;
	    cout<<"英语成绩:"<<YY<<endl;
	    cout<<"NIIT成绩:"<<NIIT<<endl;
	    cout<<"大学物理成绩:"<<WL<<endl;
		cout<<"********************************************************************************"<<endl;
		
	}

};
class student
{
public:
	 XX obj2;
	 CJ obj1;
	 LX obj3;
	void set()
	{
		
	   
	   obj2.accept();
	   obj2.display();
	   cout<<endl<<endl<<endl;
	   cout<<"下面输入学科成绩:"<<endl;
	  
       obj1.accept();
	   obj1.display();
	   cout<<endl<<endl<<endl;
	   cout<<"下面输入联系方式:"<<endl;
      
       obj3.accept();
	   obj3.display();
	}
	
};
student sj;
struct Node
{
  student stu;
  Node *NEXT;
  Node(const string s, Node * n = NULL)
  { 
	  stu.obj2.xm=s;
	  stu.set();
	  NEXT=	n;

  }

  Node(Node * n = NULL)
  { 
	  stu.obj2.xm=sj.obj2.xm;
	  stu.obj2.xb=sj.obj2.xb;
	  stu.obj2.xh=sj.obj2.xh;
	  stu.obj3.sj=sj.obj3.sj;
	  stu.obj3.QQ=sj.obj3.QQ;
	  stu.obj1.GS=sj.obj1.GS;
	  stu.obj1.NIIT=sj.obj1.NIIT;
	  stu.obj1.WL=sj.obj1.WL;
	  stu.obj1.YY=sj.obj1.YY;
	  
	  NEXT=	n;

  }
};
class List
{
public:
  Node *START,   
       *CURRENT, 
       *PRECEDE;

  List();
  ~List()
  {
    destroy ();
  }
  void addNode(string s); //用于添加学生信息
  void addNode1(string s); //用于把文件的信息加入节点
  void server();          //用于保存信息
  bool queryNode(string s); //在删除节点之前做寻找节点工作
  void queryNode1(string s); //用于查找所输入的学生的节点
   void queryNode2(string s);
  bool delNode(string s); 	//删除学生的信息				     
  void traverse();         //显示所有学生的姓名和学号
  void traverse1();         //显示所输入的学生的姓名和学号
  void destroy();           //删除全部学生的信息
};


List::List()
{
   START = CURRENT = PRECEDE = NULL;
}

void List::destroy()
{
  while(START != NULL)
  {
    CURRENT = START;
    START = START->NEXT;
    delete CURRENT;
  }
  START = PRECEDE = CURRENT = NULL;
}

void List::addNode(string s)
{
  if(START == NULL || s<= START->stu.obj2.xm)
  {
    START = new Node(s,START);
    return;
  }
  Node *prev, *curr;
  for( prev = curr = START; curr != NULL && s> curr -> stu.obj2.xm ;
                                      prev = curr, curr = curr->NEXT)
  { 
  }
  Node *n = new Node (s,curr);	
  prev->NEXT = n;
}

void List::addNode1(string s)
{
   if(START == NULL || s<= START->stu.obj2.xm)
  {
    START = new Node(START);
    return;
  }
      else
        {
            Node *prev, *curr;
           for( prev = curr = START; curr != NULL && s> curr -> stu.obj2.xm ;
                                      prev = curr, curr = curr->NEXT)
                           { 
                           }
           Node *n = new Node (curr);	
           prev->NEXT = n;
       }
}
void List::traverse()
{  
	system("cls");
  cout<<endl
<<"******************************现有的学生姓名和学号如下**************************"<<endl
<<endl<<endl;

for(Node *temp = START; temp != NULL; temp = temp->NEXT)
  {
      cout <<"姓名:"<<"   "<< temp->stu.obj2.xm <<"\t\t\t"; 
      cout <<"学号:"<<"   "<< temp->stu.obj2.xh <<endl<<endl;
	 
  }
 cout<<"********************************************************************************"<<endl;
  char ch;
	        cout  <<endl<<endl<<endl<<endl<<endl<<endl
				  <<"按任意键返回主菜单:"<<endl;
			      cin>>ch;
			      system("cls");
}
void List::traverse1()
{
system("cls");
  cout<<endl
<<"******************************现有的学生姓名和学号如下**************************"<<endl
<<endl<<endl;

for(Node *temp = START; temp != NULL; temp = temp->NEXT)
  {
      cout <<"姓名:"<<"   "<< temp->stu.obj2.xm <<"\t\t\t"; 
      cout <<"学号:"<<"   "<< temp->stu.obj2.xh <<endl<<endl;
	 
  }
 cout<<"********************************************************************************"<<endl;
}
void List::queryNode1(string s)
{

for(PRECEDE = CURRENT = START; CURRENT != NULL && s != CURRENT->stu.obj2.xm;
                           PRECEDE = CURRENT, CURRENT = CURRENT->NEXT)
  { }
   if(s == CURRENT->stu.obj2.xm)
	  {
      system("cls");
	  cout<<"********************************"<<CURRENT->stu.obj2.xm<<"学生的信息如下:*****************************"<<endl<<endl;
      cout <<"姓名:"<<"         "<< CURRENT->stu.obj2.xm <<endl<<endl;
      cout <<"学号:"<<"         "<< CURRENT->stu.obj2.xh <<endl<<endl;
	  cout <<"性别:"<<"         "<< CURRENT->stu.obj2.xb <<endl<<endl;
	  cout <<"手机号码:"<<"         "<< CURRENT->stu.obj3.sj <<endl<<endl;
	  cout <<"QQ号码:"<<"         "<< CURRENT->stu.obj3.QQ <<endl<<endl;
	  cout <<"高数成绩:"<<"         "<< CURRENT->stu.obj1.GS <<endl<<endl;
	  cout <<"英语成绩:"<<"         "<< CURRENT->stu.obj1.YY <<endl<<endl;
      cout <<"NIIT成绩:"<<"         "<< CURRENT->stu.obj1.NIIT <<endl<<endl;
	  cout <<"大学物理成绩:"<<"         "<< CURRENT->stu.obj1.WL <<endl<<endl;
	  }
 cout<<"********************************************************************************"<<endl;
  char ch;
	        cout  <<endl<<endl<<endl<<endl<<endl<<endl
				  <<"按任意键返回主菜单:"<<endl;
			      cin>>ch;
			      system("cls");
}

void List::queryNode2(string s)
{

for(PRECEDE = CURRENT = START; CURRENT != NULL && s != CURRENT->stu.obj2.xm;
                           PRECEDE = CURRENT, CURRENT = CURRENT->NEXT)
  { }
   if(s == CURRENT->stu.obj2.xm)
	  {
      system("cls");
	  cout<<"********************************"<<CURRENT->stu.obj2.xm<<"编辑的学生信息如下:*****************************"<<endl<<endl;
          cout <<"姓名:"<<"         "<< CURRENT->stu.obj2.xm <<endl<<endl;
      cout <<"学号:"<<"         "<< CURRENT->stu.obj2.xh <<endl<<endl;
	  cout <<"性别:"<<"         "<< CURRENT->stu.obj2.xb <<endl<<endl;
	  cout <<"手机号码:"<<"         "<< CURRENT->stu.obj3.sj <<endl<<endl;
	  cout <<"QQ号码:"<<"         "<< CURRENT->stu.obj3.QQ <<endl<<endl;
	  cout <<"高数成绩:"<<"         "<< CURRENT->stu.obj1.GS <<endl<<endl;
	  cout <<"英语成绩:"<<"         "<< CURRENT->stu.obj1.YY <<endl<<endl;
      cout <<"NIIT成绩:"<<"         "<< CURRENT->stu.obj1.NIIT <<endl<<endl;
	  cout <<"大学物理成绩:"<<"         "<< CURRENT->stu.obj1.WL <<endl<<endl;
	  }
 cout<<"********************************************************************************"<<endl;
  
}

void List::server()
{
	
	if(START == NULL)
		{
			ofstream outobj("Student.txt",ios::app);
	outobj <<""<<endl;
	system("cls");
	cout<<"保存数据成功!!!!!!!"<<endl<<endl<<endl;
				   
	cout<<"按任意键返回主菜单:"<<endl;
	char ch;
	cin>>ch;
	system("cls");
	}
	

⌨️ 快捷键说明

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