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

📄 funtion.cpp

📁 自己的VC课程设计,呵呵也许有点简陋单对于初学者应该有点用途,里面用到类的知识对系统文件添加删除等操作还有调用系统命令行程序里面有些程序思路 会给你带来启示的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
int StuDel()
{
  char choose;    
    while (1)
    {
        system("cls");
        cout <<endl <<"\t删除学生信息" <<endl <<endl;
        cout <<endl <<"\t●\t1.  删除除一个学生记录" <<endl
            <<endl <<"\t●\t2.  删除所有学生记录" <<endl 
            <<endl <<"\t●\t3.  返回首页" <<endl <<endl <<"\t\t";        
        choose = getch();
        fflush(stdin);
        
        switch (choose)
        {
        case '1':
            delete_sigle();//删除一个学生记录
            break;
        case '2':
            delete_all();//删除所有学生信息
            break;
        case '3':
            return 0;
        default:
            break;
        }
    }
}
//删除老师页面
int TeaDel()
{
  char choose;    
    while (1)
    {
        system("cls");
        cout <<endl <<"\t删除老师信息" <<endl <<endl;
        cout <<endl <<"\t●\t1.  删除除一个老师记录" <<endl
            <<endl <<"\t●\t2.  删除所有老师记录" <<endl 
            <<endl <<"\t●\t3.  返回首页" <<endl <<endl <<"\t\t";        
        choose = getch();
        fflush(stdin);
        
        switch (choose)
        {
        case '1':
            delete_sigletea();//删除一个学生记录
            break;
        case '2':
            delete_all();//删除所有学生信息
            break;
        case '3':
            return 0;
        default:
            break;
        }
    }
}
//删除单一老师页面
void delete_sigletea()
{
    system("cls");
    cout <<endl <<"\t删除老师信息" <<endl <<endl;
    cout <<"\t请输入姓名 : ";
    string no;
    cin >>no;
    //fflush(stdin);
    string number;
    ifstream stuFile("tea.dat");
    assert(stuFile);
    while (stuFile >>number)
    {
        if (no == number)
        {
            //number = "stu\\0"+number+".txt";          
            number = "Type tea\\"+number+".txt";          
            cout<<endl<<"你想删除的学生信息如下 : "<<endl;
            cout<<"--------------------------------------------------------------------------------"<<endl;
			cout<<"--------------------------------------------------------------------------------"<<endl;
			system(number.c_str());
           cout<<"--------------------------------------------------------------------------------"<<endl;
		    cout<<"--------------------------------------------------------------------------------"<<endl;

            cout <<endl <<"你确定要删除吗?(y/n) : ";
            if (getch() == 'y')
            {  
				number = "del tea\\"+number+".txt";
               system(number.c_str());
                ifstream stuFile2("tea.dat");
                assert(stuFile2);
                ofstream tempFile("teatemp.dat");
                assert(tempFile);

                while (stuFile2 >>number)
                {
                    if (no != number)
                    {
                        tempFile <<number <<endl;
                    }
                }
                stuFile2.close();
                tempFile.close();
                ifstream tempFile1("teatemp.dat");
                assert(tempFile1);
                ofstream stuFile3("tea.dat");
                assert(stuFile3);
                stuFile3 <<tempFile1.rdbuf();
                tempFile1.close();
                number = "tea\\"+no+".txt";
                ofstream stuFile4(number.c_str());
                stuFile4.close();
                cout <<endl <<endl <<"该老师信息已经删除!!" <<endl <<endl <<"\t";
                system("pause");
            }
			else
            cout <<endl <<"不存在该老师信息!!" <<endl<<"\t";
            system("pause");
			break; 
        }
		
    }

}

//删除单一学生页面
void delete_sigle()
{
    system("cls");
    cout <<endl <<"\t删除学生信息" <<endl <<endl;
    cout <<"\t请输入学号 : ";
    string no;
	int i(0); //标志是否存在要删除的信息
    cin >>no;
    //fflush(stdin);
    string number;
    ifstream stuFile("stu.dat");
    assert(stuFile);
    while (stuFile >>number)
    {
        if (no == number)
        {   i++;
            //number = "stu\\0"+number+".txt";          
            number = "Type stu\\"+number+".txt";          
            cout<<endl<<"你想删除的学生信息如下 : "<<endl;
            cout<<"--------------------------------------------------------------------------------"<<endl;
			cout<<"--------------------------------------------------------------------------------"<<endl;
			system(number.c_str());
           cout<<"--------------------------------------------------------------------------------"<<endl;
		    cout<<"--------------------------------------------------------------------------------"<<endl;

            cout <<endl <<"你确定要删除吗?(y/n) : ";
            if (getch() == 'y')
            {  
				number = "del stu\\"+number+".txt";
               system(number.c_str());
                ifstream stuFile2("stu.dat");
                assert(stuFile2);
                ofstream tempFile("temp.dat");
                assert(tempFile);

                while (stuFile2 >>number)
                {
                    if (no != number)
                    {
                        tempFile <<number <<endl;
                    }
                }
                stuFile2.close();
                tempFile.close();
                ifstream tempFile1("temp.dat");
                assert(tempFile1);
                ofstream stuFile3("stu.dat");
                assert(stuFile3);
                stuFile3 <<tempFile1.rdbuf();
                tempFile1.close();
                number = "stu\\"+no+".txt";
                ofstream stuFile4(number.c_str());
                stuFile4.close();
                cout <<endl <<endl <<"该生信息已经删除!!" <<endl <<endl <<"\t";
            }
			if(i==0)
			cout <<endl <<"不存在该学生信息!!" <<endl<<"\t";
            system("pause");
            break; 
        }
		
    }

}

//删除所有学生记录
void delete_all()
{
    cout <<endl <<endl <<"\t你确定在删除所有学生信息吗? 此操作不可恢复.(y/n) : ";
    if (getch() == 'y')
    {
        system("del stu\\*.txt");
		system("del stu.dat");
        ofstream stuFile2("stu.dat");
        assert(stuFile2);
        cout <<endl <<endl <<"\t所用学生信息已经删除!!!" <<endl <<endl;
		stuFile2.close;
		system("del tea\\*.txt");
		system("del tea.dat");
        ofstream stuFile3("tea.dat");
        assert(stuFile3);
        cout <<endl <<endl <<"\t所用老师信息已经删除!!!" <<endl <<endl;
        stuFile3.close;
		system("pause");
    }
}
//学生修改信息
void stu_alter()
{
    system("cls");
    cout <<endl <<"\t信息修改" <<endl <<endl;
    cout <<"\t请输入学号 : ";
    string no;
	string number;
    cin >>no;
   if(!StuSelect(no))
  {
	  cout<<"对不起你输入的学号不存在!"<<endl;
       system("pause");
		 system("cls");
	   Form1_Show();
  }
    ifstream stuFile("stu.dat");
    while (stuFile >>number)
    {
        if (no == number)
        {
            cout <<endl <<number <<"以前的信息如下 : " <<endl <<endl;
            number = "type stu\\"+no+".txt";
			 cout<<"--------------------------------------------------------------------------------"<<endl;
        	system(number.c_str());
           cout<<"--------------------------------------------------------------------------------"<<endl;
  string name1;
  string sex1;
  string Birth1;
  string Address1;
  string Tel1;
  string Home1;
  string QQ1;
  string PID1; 
  string StuID1; //学号
//显示出入信息模块
  string speciality1;//专业 
  string ClassName1; //班级
  string College1; //学院
  string word1;//留言
  cout<<"     请输入姓名: ";
  cin>>name1; 
  cout<<endl<<"     请输入性别: ";
  cin>>sex1;
  cout<<endl<<" 请输入出生年月: ";
  cin>>Birth1;
  cout<<endl<<"     请输入电话: ";
  cin>>Tel1;
  cout<<endl<<"   请输入出生地: ";
  cin>>Home1;
   cout<<endl<<"     请输入宿舍: ";
  cin>>Address1;
  cout<<endl<<"       请输入qq: ";
  cin>>QQ1;
  cout<<endl<<" 请输入身份证号: ";
  cin>>PID1; 
  cout<<endl<<"     请输入专业: ";
  cin>>speciality1;
  cout<<endl<<"     请输入班级: ";
  cin>>ClassName1;
  cout<<endl<<"     请输入学院: ";
  cin>>College1;
  cout<<endl<<"     请输入留言: ";
  cin>>word1;
  Stu p1(name1,sex1,Birth1,Tel1,Home1,QQ1,PID1,speciality1,ClassName1,College1,word1,Address1);  
  //把整个学生信息保存到记事本中文件名为学号
  string txtname="stu\\"+no+".txt";
  p1.StuSave(txtname.c_str());
  cout <<"信息存储完毕!!!!" <<endl <<endl;
   system("pause");
      Form1_Show();
        }
    }
}
//修改老师
void Tea_alter()
{
	 system("cls");
    cout <<endl <<"\t老师信息修改" <<endl <<endl;
    cout <<"\t请输入姓名 : ";
    string no;
	string number;
    cin >>no;
   if(!TeaSelect(no))
  {
	  cout<<"对不起你输入的老师不存在!"<<endl;
       system("pause");
		 system("cls");
	   Form1_Show();
  }
    ifstream stuFile("tea.dat");
    while (stuFile >>number)
    {
        if (no == number)
        {
            cout <<endl <<number <<"以前的信息如下 : " <<endl <<endl;
            number = "type tea\\"+no+".txt";
			 cout<<"--------------------------------------------------------------------------------"<<endl;
        	system(number.c_str());
           cout<<"--------------------------------------------------------------------------------"<<endl;
  string name1;
  string sex1;
  string Birth1;
  string Address1;
  string Tel1;
  string Home1;
  string QQ1;
  string PID1; 
  string WorkID1; //工号
  string Kemu1;//科目 
  string word1;//留言
  cout<<"     请输入姓名: ";
  cin>>name1; 
  cout<<endl<<"     请输入性别: ";
  cin>>sex1;
  cout<<endl<<" 请输入出生年月: ";
  cin>>Birth1;
  cout<<endl<<"     请输入电话: ";
  cin>>Tel1;
  cout<<endl<<"   请输入出生地: ";
  cin>>Home1;
   cout<<endl<<"     请输入住址: ";
  cin>>Address1;
  cout<<endl<<"       请输入qq: ";
  cin>>QQ1;
  cout<<endl<<" 请输入身份证号: ";
  cin>>PID1; 
  cout<<endl<<" 请输入任教科目: ";
  cin>>Kemu1;
  cout<<endl<<"     请输入留言: ";
  cin>>word1;
  Tea p1(name1,sex1,Birth1,Tel1,Home1,QQ1,PID1,WorkID1,Kemu1,word1,Address1);  
  //把整个学生信息保存到记事本中文件名为学号
  string txtname="tea\\"+no+".txt";
  p1.Teasave(txtname.c_str());
  cout <<"信息存储完毕!!!!" <<endl <<endl;
   system("pause");
      Form1_Show();
        }
    }
}		

⌨️ 快捷键说明

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