| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 591 人关注过本帖
标题:各位高手,帮我看看为什么这个删除和修改的部分老不行?
只看楼主 加入收藏
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
结帖率:75%
收藏
已结贴  问题点数:18 回复次数:2 
各位高手,帮我看看为什么这个删除和修改的部分老不行?
各位高手,帮我看看为什么这个删除和修改的部分老不行?每次我录入两组数据时可以运行,但是录入三组数据时便不行?帮我看看到底是哪里出错啦?不好意思哦,我是初学者。。谢谢啦。。。
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class Student
{
  int N,addr[50],i,k;
  char number[50],name[50];
  double Chinese,Math,English,sum,ave;
public:
  Student();
  ~Student();
  Student(char number[50],char name[50],double Chinese,double Math,double English);
  void AddStudent(char number[50],char name[50],double Chinese,double Math,double English);
  void DeleteStudent();
  void ChangeStudent();
  void DispAll();
  Student *stu;      
};
Student::Student()
{
  number[0]='0';
  name[0]='0';
  Chinese=0;
  Math=0;
  English=0;
  for(int i=0;i<50;i++)
  {
      addr[i]=0;
  }
  N=0;
}
Student::Student(char number1[50],char name1[50],double Chinese1,double Math1,double English1)
{
  strcpy(number,number1);
  strcpy(name,name1);
  Chinese=Chinese1;
  Math=Math1;
  English=English1;
}
Student::~Student()
{
}
void Student::AddStudent(char number[50],char name[50],double Chinese,double Math,double English)
{
   ofstream fileout("学生成绩管理.txt",ios::app);
   if (!fileout)
   {
       cerr<<"文件学生成绩管理.txt打开失败!"<<endl;
       exit(1);
   }
   fileout<<"学号:"<<number<<endl;
   fileout<<"姓名:"<<name<<endl;
   fileout<<"语文:"<<Chinese<<endl;
   fileout<<"数学:"<<Math<<endl;
   fileout<<"英语:"<<English<<endl;
   stu=new Student(number,name,Chinese,Math,English);
   addr[N]=(int)stu;
   N++;
   fileout.close();
}
void Student::DeleteStudent()
{   int i;
    char m[50],c;
    bool d=0;
    do
    {
      cout<<"请输入您要删除的学生的学号:"<<endl;
      cin>>m;
     for(i=0;i<N;i++)
     {
       if(strcmp(m,stu[i].number)==0)
        {
          d=1;
          N--;
          do
          {
            stu[i]=stu[i+1];
             i++;
          }while(i<=N);
        }
     }

       if(d==0)
       cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
       cout<<"要继续删除吗?(y/n)"<<endl;
       cin>>c;
       if(c!='y'&&c!='n')
       {
         cout<<"指令错误!请重新输入!"<<endl;
         cin>>c;
        }
    }while(c=='y');
   
   
}
void Student::ChangeStudent()
{   int i,k,p;
    char m[50],c;
    bool d=0;
    do
    {
      cout<<"请输入您要修改的学生的学号:"<<endl;
      cin>>m;
     for(i=0;i<N;i++)
     {
       if(strcmp(m,stu[i].number)==0)
       {   d=1;
           do
           { cout<<"==========================="<<endl;
             cout<<"||请选择您需要的操作:    ||"<<endl;
             cout<<"==========================="<<endl;
             cout<<"||1.修改该学生的语文成绩:||"<<endl;
             cout<<"||2.修改该学生的数学成绩:||"<<endl;
             cout<<"||3.修改该学生的英语成绩:||"<<endl;
             cout<<"==========================="<<endl;
             cout<<"||请输入您要修改的选项   ||:"<<endl;
             cin>>k;
             switch(k)
             {
             case 1:
                 {
                   cout<<"请输入该学生的语文成绩:"<<endl;
                   cin>>p;
                   stu[i].Chinese=p;
                   break;
                 }
              case 2:
                 {
                   cout<<"请输入该学生的数学成绩:"<<endl;
                   cin>>p;
                   stu[i].Math=p;
                   break;
                 }
                 case 3:
                 {
                   cout<<"请输入该学生的英语成绩:"<<endl;
                   cin>>p;
                   stu[i].English=p;
                   break;
                 }

            
             }
           }while(i!=0);
       }
     }
       if(d==0)
       cout<<"您要求修改的对象本来就不存在!请检查输入的正确性!";
       cout<<"要继续修改吗?(y/n)"<<endl;
       cin>>c;
       if(c!='y'&&c!='n')
       {
         cout<<"指令错误!请重新输入!"<<endl;
         cin>>c;
        }
    }while(c=='y');
   
   
}

void Student::DispAll()
{   
    cout<<"本系统所有学生数据如下:"<<endl;
    if(N==0)
    cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
    cout<<"学号"<<"\t姓名"<<"\t语文"<<"\t数学"<<"\t英语"<<endl;
    for (int i=0;i<N;i++)
    {
        stu=(Student*)addr[i];
        cout<<stu->number<<'\t'<<stu->name<<'\t'<<stu->Chinese<<'\t'<<stu->Math<<'\t'<<stu->English<<endl;
    }
}

void main()
{
    Student stu;
    int select=0,k,i;
    int N=0,addr[50];
    char number[50],name[50],c,m;
    double Chinese,Math,English,sum,ave;
    bool d=0;
do
  {cout<<"               ***--------------------------------------------------***"<<endl;
   cout<<"               ***                                                  ***"<<endl;
   cout<<"               ***            欢迎进入学生成绩管理系统              ***"<<endl;
   cout<<"               ***                                                  ***"<<endl;
   cout<<"               ***--------------------------------------------------***"<<endl;
   cout<<"                || 请选择您需要的操作:                             ||"<<endl;
   cout<<"                ||                    信息维护:                    ||"<<endl;
   cout<<"                ||                             (0)数据录入          ||"<<endl;
   cout<<"                ||                             (1)增加人员          ||"<<endl;
   cout<<"                ||                             (2)删除人员          ||"<<endl;
   cout<<"                ||                             (3)修改数据          ||"<<endl;
   cout<<"                ||                    信息查询:                    ||"<<endl;
   cout<<"                ||                             (4)按总成绩查询      ||"<<endl;
   cout<<"                ||                             (5)按姓名查询        ||"<<endl;
   cout<<"                ||                             (6)输出所有学生的数据||"<<endl;
   cout<<"                ||                    成绩排名:                     ||"<<endl;
   cout<<"                ||                             (7)按总分查询排名    ||"<<endl;
   cout<<"                ||                             (8)按语文查询排名    ||"<<endl;
   cout<<"                ||                             (9)按数学查询排名    ||"<<endl;
   cout<<"                ||                             (10)按英语查询排名   ||"<<endl;
   cout<<"                ||                             (11)退出             ||"<<endl;
   cout<<"                || 选择相关操作请输入相对的括号里的阿拉伯数字!     ||"<<endl;
   do
   {
    cin>>select;
    if(select>=0&&select<=11)
      d=1;
    else
      cout<<"指令错误!请重新输入:"<<endl;
    }while(d==0);
    switch (select)
    {case 0:{
              do
              {
               cout<<"请输入学号:";
               cin>>number;
               cout<<endl;
               cout<<"请输入姓名:";
               cin>>name;
               cout<<endl;
               cout<<"请输入语文成绩:";
               cin>>Chinese;
               cout<<endl;
               cout<<"请输入数学成绩:";
               cin>>Math;
               cout<<endl;
               cout<<"请输入外语成绩:";
               cin>>English;
               cout<<endl;
               stu.AddStudent(number,name,Chinese, Math, English);
               stu.DispAll();
               cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
               cin>>c;
               if(c!='y'&&c!='n')
                   {
                     cout<<"指令错误!请重新输入!"<<endl;
                     cin>>c;
                   }
              }while(c=='y');
              break;
    }
       case 1:{
              do
              {
               cout<<"请输入学号:";
               cin>>number;
               cout<<endl;
               cout<<"请输入姓名:";
               cin>>name;
               cout<<endl;
               cout<<"请输入语文成绩:";
               cin>>Chinese;
               cout<<endl;
               cout<<"请输入数学成绩:";
               cin>>Math;
               cout<<endl;
               cout<<"请输入外语成绩:";
               cin>>English;
               cout<<endl;
               stu.AddStudent(number,name,Chinese, Math, English);
               stu.DispAll();
               cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
               cin>>c;
               if(c!='y'&&c!='n')
                   {
                     cout<<"指令错误!请重新输入!"<<endl;
                     cin>>c;
                   }
              }while(c=='y');
              break;
    }
       case 2:{
               stu.DeleteStudent();
               stu.DispAll();
               break;
              }
       case 3:
           {   
               stu.ChangeStudent();
               stu.DispAll();
               break;
           }
     
       }
            

   
}while(select!=11);
}

搜索更多相关主题的帖子: 录入 class English Chinese include 
2011-12-20 22:08
单行道1129
Rank: 3Rank: 3
来 自:山东潍坊
等 级:论坛游侠
帖 子:38
专家分:118
注 册:2011-10-26
收藏
得分:18 
能具体点吗??
2011-12-21 09:26
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
收藏
得分:0 
为什么我录入两组数据时可以运行删除和修改的部分,但是录入三组数据时就会错乱。帮我看看,谢谢啦。。
2011-12-21 16:51
快速回复:各位高手,帮我看看为什么这个删除和修改的部分老不行?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029923 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved