2 liuqaz8274 liuqaz8274 于 2013.06.30 11:29 提问

新手 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
liuqaz8274   2013.06.30 11: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

John_ToString
John_ToString   2015.12.05 16:19

哎 问题很大啊, 要好好看看书,调试你的代码

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!