liuqaz8274 2013-06-30 03:29 采纳率: 0%
浏览 3312

新手 c++学生管理系统 不知道怎么改错

#include "iostream"
#include "string"
#include "fstream"
#include "conio.h"
using namespace std;

// *******建立学生信息的类
class Student
{
public:
Student *Head,*p;
Student *Next,*end;
char name[20];
char sex;

char dorm[20];
char num[20];
int age;
double math;
double english;
double cprogram;
double sum;
double average;

void Menu();
void Find();
void Save();
void Modify();
void Delect();
void Display();
void Displaym();
void Input();
void Read(istream &in);
void Add();

private:

ifstream in;
ofstream out;
Student *Findname(char name)
{
    for(Student *p=Head;p->Next!=end;p=p->Next)     
        if(!strcmp(p->Next->name,name))
        {
            return p;
        }
        return NULL;
}
Student *Findnum(int num)
{
    for(Student * p=Head;p->Next!=end;p=p->Next)
        if(!strcmp(p->Next->num,num))
        {
            return p;
        }
        return NULL;
}

}stu;

void Student::Display() // 输出学生信息
{

cout<<"学号:"< }
void Student::Input() // 输入学生信息
{
system("color 9e");
cout cin>>stu.num;
cout< cout cin>>stu.name;
cout< cout cin>>stu.sex;
cout< cout cin>>stu.age;
cout< cout cin>>stu.dorm;
cout< cout cout cin>>stu.math;
cout< cout cin>>stu.english;
cout< cout cin>>stu.cprogram;
cout<<endl;
cout<<"信息输入成功!"<<endl;
stu.sum=stu.math+stu.english+stu.cprogram;
stu.average=stu.sum/3;

}
void Student::Read(istream &in)// 从文件中读取信息
{
in>>"学号:">>stu.num>>"\n"<<"姓名:">>stu.name>>"\n">>"性别:">>stu.sex>>"\n">>"年龄:">>stu.age>>"\n">>"寝室地址:">>stu.dorm>>"\n">>"高数成绩:">>stu.math>>"\n">>"英语成绩:">>stu.english>>"\n">>"C++成绩:">>stu.cprogram>>"\n">>"总分:">>stu.sum>>"\n">>"平均分:">>stu.average;
}

void Student::Add() //写入文件
{

//p->Next=new Student;
//p=p->Next;

ofstream outfile("student.txt");            

p->Input();
outfile<<"学号:"<<p->num<<"\n"<<"姓名:"<<p->name<<"\n"<<"性别:"<<p->sex<<"\n"<<"年龄:"<<p->age<<"\n"<<"寝室地址:"<<p->dorm<<"\n"<<"高数成绩:"<<p->math<<"\n"<<"英语成绩:"<<p->english<<"\n"<<"C++成绩:"<<p->cprogram<<"\n"<<"总分:"<<p->sum<<"\n"<<"平均分:"<<p->average<<"\n"<<endl;
outfile<<"-------------------------------------------------------------------"<<endl;
outfile.close();

p->Next=new Student;
p=p->Next;

cout<<"添加成功!"<<endl;

}
void Student::Displaym()
{
ifstream infile("student.txt");
//Student *p=Head->Next;p!=p;p=p->Next

for(Student *p=Head->Next;p!=p;p=p->Next)
{
    //infile.read((char *)p,sizeof(p));         
    p->Display();

}       
infile.close();

}
// ********查找函数
void Student::Find()
{
char name[20],num[20];
int n;
Student p;
cout<<"\n\t\t
********************************\n";
cout<<"\t\t※ 1.按学生的姓名查找\n\t\t※ 2.按学生学号查找";
cout<<"\n\t\t*********************************\n请选择:";
cin>>n;
switch(n)
{
case 1:
{
cout<<"输入要查询的学生姓名";
cin>>name;
if(p=Findname(name))
{
p->Next->Display();

        }
        else

        {   
            cout<<"\t\t没有找到该姓名的学生!"<<'\n'<<endl;   


        }
        break;
    }

case 2:
    {
        cout<<"请输入要查询学生的学号";
        cin>>num;
        if(p=Findnum(num))
        {
            p->Next->Display();

        }
        else
        {
            cout<<"\t\t没有找到该学号的学生!"<<'\n'<<endl;          

        }

    }break;

}

}
// *********修改函数

void Student::Modify()
{
char name[20],num;
Student * p;
int n;
cout<<"\n\t\t*********************************\n";
cout<<"\t\t※ 1.按学生的姓名查找修改\n\t\t※ 2.按学生学号查找修改";
cout<<"\n\t\t*********************************\n请选择:";
cin>>n;
switch(n)
{
case 1:
{

        cout<<"\t\t请输入要修改的人的姓名:";cin>>name; 
        if(p=Findname(name)) 
        { 
            cout<<"\t\t已找到学生的信息,请输入新的信息!"<<endl;  
            p->Next->Input();  
            cout<<"修改成功!"<<endl;  

        }

        else 
        {  
            cout<<"\t\t没有找到!"<<endl;  

        }
    }
    break;
case 2:
    {
        cout<<"\t\t请输入要修改的人的学号:";cin>>num; 
        if(p=Findnum(num)) 
        { 
            cout<<"\t\t已找到学生的信息,请输入新的信息!"<<endl;  
            p->Next->Input();  
            cout<<"修改成功!"<<endl;       
        }

        else 
        {  
            cout<<"\t\t没有找到!"<<endl;  


        }
        break;
    }

}

}
//删除函数
void Student::Delect()
{
int num[20];
Student *p,*temp;
char n;
cout<<"输入需要删除的学生学号";
cin>>num;
if(p=Findnum(num))
{
p->Next->Display();
cout<<"是否删除该学生信息?(y/n)";
cin>>n;
if(n=='y'||n=='Y')
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t删除成功!"<<endl;

    }
    else
    {
        cout<<"输入任意字符!继续……";
        getch();
    }


}
else
{
    cout<<"\t\t无该生信息!"<<endl;     

}

}
// 保存函数
void Student::Save()
{

out.open("student.txt",ios::app); 
for(Student *p=Head->Next;p!=p;p=p->Next) 
{
    out<<"学号:"<<p->num<<"\n"<<"姓名:"<<p->name<<"\n"<<"性别:"<<p->sex<<"\n"<<"年龄:"<<p->age<<"\n"<<"寝室地址:"<<p->dorm<<"\n"<<"高数成绩:"<<p->math<<"\n"<<"英语成绩:"<<p->english<<"\n"<<"C++成绩:"<<p->cprogram<<"\n"<<"总分:"<<p->sum<<"\n"<<"平均分:"<<p->average<<"\n"<<endl;
}
out.close();

}

//显示函数
void Student::Displaym()
{
ifstream infile("student.txt");
for(Student *p=stu.Head->Next;p!=p;p=p->Next)
{
//infile.read((char *)p,sizeof(p));

p->Display();

}       
infile.close();

// ********查找函数
void Student::Find()
{
char name[20],num[20];
int n;
Student p;
cout<<"\n\t\t
********************************\n";
cout<<"\t\t※ 1.按学生的姓名查找\n\t\t※ 2.按学生学号查找";
cout<<"\n\t\t*********************************\n请选择:";
cin>>n;
switch(n)
{
case 1:
{
cout<<"输入要查询的学生姓名";
cin>>name;
if(p=Findname(name))
{
p->Next->Display();

        }
        else

        {   
            cout<<"\t\t没有找到该姓名的学生!"<<'\n'<<endl;   


        }
        break;
    }

case 2:
    {
        cout<<"请输入要查询学生的学号";
        cin>>num;
        if(p=Findnum(num))
        {
            p->Next->Display();

        }
        else
        {
            cout<<"\t\t没有找到该学号的学生!"<<'\n'<<endl;          


        }

    }break;

}

}
// *********修改函数

void Student::Modify()
{
char name[20],num;
Student * p;
int n;
cout<<"\n\t\t*********************************\n";
cout<<"\t\t※ 1.按学生的姓名查找修改\n\t\t※ 2.按学生学号查找修改";
cout<<"\n\t\t*********************************\n请选择:";
cin>>n;
switch(n)
{
case 1:
{

        cout<<"\t\t请输入要修改的人的姓名:";cin>>name; 
        if(p=Findname(name)) 
        { 
            cout<<"\t\t已找到学生的信息,请输入新的信息!"<<endl;  
            p->Next->Input();  
            cout<<"修改成功!"<<endl;  


        else 
        {  
            cout<<"\t\t没有找到!"<<endl;  


        }
    }
    break;
case 2:
    {
        cout<<"\t\t请输入要修改的人的学号:";cin>>num; 
        if(p=Findname(name)) 
        { 
            cout<<"\t\t已找到学生的信息,请输入新的信息!"<<endl;  
            p->Next->Input();  
            cout<<"修改成功!"<<endl;  

        }

        else 
        {  
            cout<<"\t\t没有找到!"<<endl;  

        }
        break;
    }

}

}
//删除函数
void Student::Delect()
{
char num[20];
Student *p,*temp;
int n;
cout<<"输入需要删除的学生学号";
cin>>num;
if(p=Findnum(num))
{
p->Next->Disendlay();
cout<<"是否删除该学生信息?(1/0)";
cin>>n;
if(n==1)
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t删除成功!"<<endl;

    }
    else
    {
        cout<<"输入任意字符!继续……";
        getch();
    }

}
else
{
    cout<<"\t\t无该生信息!"<<endl;     

}

}
// 保存函数
void Student::Save()
{

out.open("student.txt",ios::app); 
for(Student *p=Head->Next;p!=p;p=p->Next) 
{
    out<<"学号:"<<p->num<<"\n"<<"姓名:"<<p->name<<"\n"<<"性别:"<<p->sex<<"\n"<<"年龄:"<<p->age<<"\n"<<"寝室地址:"<<p->dorm<<"\n"<<"高数成绩:"<<p->math<<"\n"<<"英语成绩:"<<p->english<<"\n"<<"C++成绩:"<<p->cprogram<<"\n"<<"总分:"<<p->sum<<"\n"<<"平均分:"<<p->average<<"\n"<<endl;
}
out.close();

}

int main()
{

int i,j;
system("color 8e");
cout<<"********************************************************************************"<<endl;
cout<<"****************************欢迎使用学生信息管理系统****************************"<<endl;
cout<<"********************************************************************************"<<endl;
cout<<"\t1.输入信息     \t2.保存信息     \t3.查询信息     \t4.修改并保存"<<endl;
cout<<"\t5.显示全部     \t6.删除信息     \t7.退出系统                   "<<endl;
cout<<"********************************************************************************"<<endl;
do 
{ 
    cout<<"请输入您要进行的操作编号(1--7):";
    cin>>j;
    cout<<endl;
    if(j<1||j>7)
        cout<<"对不起,请输入1-7这几个选择数字!"<<endl;
} 
while(j<1||j>7);
switch(j)
{    
case 1:stu.Add();
    break;    
case 2:stu.Save();
    break;    
case 3:stu.Find(); 
    break;
    break;
case 4:stu.Modify();
    case 5:stu.Displaym();
        break;    
    case 6:stu.Delect();
        break;
    case 7:exit(0);
        break;
}

}

  • 写回答

2条回答

  • liuqaz8274 2013-06-30 03:29
    关注

    D:\MyProjects\管理\student.cpp(42) : error C2664: 'strcmp' : cannot convert parameter 2 from 'char' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(51) : error C2664: 'strcmp' : cannot convert parameter 2 from 'int' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(65) : error C2297: '<<' : illegal, right operand has type 'char [2]'
    D:\MyProjects\管理\student.cpp(102) : error C2676: binary '<<' : 'class std::basic_istream >' does not define this operator or a conversion to a type acceptable to the predefined operator
    D:\MyProjects\管理\student.cpp(156) : error C2664: 'Findname' : cannot convert parameter 1 from 'char [20]' to 'char'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(175) : error C2664: 'Findnum' : cannot convert parameter 1 from 'char [20]' to 'int'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(207) : error C2664: 'Findname' : cannot convert parameter 1 from 'char [20]' to 'char'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(251) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int [20]' (or there is no acceptable conversion)
    D:\MyProjects\管理\student.cpp(252) : error C2664: 'Findnum' : cannot convert parameter 1 from 'int [20]' to 'int'
    This conversion requires a reinterpret_cast, a C-style cast or function-style cast
    D:\MyProjects\管理\student.cpp(295) : error C2084: function 'void __thiscall Student::Displaym(void)' already has a body
    D:\MyProjects\管理\student.cpp(307) : error C2601: 'Find' : local function definitions are illegal
    D:\MyProjects\管理\student.cpp(359) : error C2601: 'Modify' : local function definitions are illegal
    D:\MyProjects\管理\student.cpp(495) : fatal error C1075: end of file found before the left brace '{' at 'D:\MyProjects\管理\student.cpp(359)' was matched

    评论

报告相同问题?

悬赏问题

  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)