学生管理系统出错,大家帮忙看看,谢谢啦
错误 3 error C2440: “return”: 无法从“std::string”转换为“float” c:\users\think\documents\visual studio 2013\projects\project1\project1\c1.cpp 77 1 Project14 IntelliSense: 不存在从 "std::string" 到 "float" 的适当转换函数 c:\Users\THINK\Documents\Visual Studio 2013\Projects\Project1\Project1\c1.cpp 77 35 Project1
#include<iostream>
#include<string>
using namespace std;
class Student
{
int no;
string name;
string score;
Student *per;
Student *next;
public:
Student();
Student *find(int i_no);
void edit(string i_newname, float i_score);
void erase();
int add(Student *i_newStudent);
int getno();
string getname();
float getscore();
static int maxno;
};
Student::Student()
{
score = 0.0;
per = NULL;
next = NULL;
}
Student * Student::find(int i_no)
{
if (i_no == no)
return this;
if (next != NULL)
return next->find(i_no);
return NULL;
}
void Student::edit(string i_name, float i_score)
{
if (i_name == "")
return;
name = i_name;
score = i_score;
}
void Student::erase()
{
if (no < 0)
return;
if (per!= NULL)
per->next = next;
if (next!= NULL)
next->per = per;
next = NULL;
per = NULL;
}
int Student::add(Student *i_newStudent)
{
int no = maxno + 1;
while (true)
{
if (NULL == find(no))
break;
no = no + 1;
}
Student * tmp = this;
while (true){
if (tmp->next == NULL)
break;
tmp = tmp->next;
}
tmp->next = i_newStudent;
i_newStudent->next = NULL;
i_newStudent->per = tmp;
i_newStudent->no = no;
return no;
}
int Student::getno(){ return no; }
string Student::getname(){ return name; }
float Student::getscore(){ return score; }
int Student::maxno = 1000;
int main()
{
Student *studentroot = new Student();
string input1;
float input2;
Student * tmp = NULL;
while (true){
cout << "输入指令:查找(F),增加(A),编辑(E),删除(D),退出(Q)" << endl;
cin >> input1;
if (("F" == input1) || ("f" == input1))
{
cout << "输入学号:";
int id = -1;
cin >> id;
tmp = studentroot->find(id);
if (tmp == NULL)
{
cout << "没找到" << endl;
continue;
}
cout << "学号:" << tmp->getno();
cout << " 姓名: ";
string name;
if ((name = tmp->getname()) != "")
cout << name << endl;
else
cout << "未输入" << endl;
cout << "成绩:" << tmp->getscore() << endl;
}
else if ((input1 == "A") || (input1 == "a"))
{
cout << "输入姓名,成绩:";
cin >> input1 >> input2;
tmp = new Student();
tmp->edit(input1, input2);
cout << "学号:" << studentroot->add(tmp) << endl;
}
else if ((input1 == "E") || (input1 == "e"))
{
cout << "输入学号:";
int id = 0;
cin >> id;
tmp = studentroot->find(id);
if (tmp == NULL)
{
cout << "空号" << endl;
continue;
}
cout << "新姓名,新成绩:";
cin >> input1 >> input2;
tmp->edit(input1, input2);
cout << "更改成功." << endl;
}
else if ((input1 == "D") || (input1 == "d"))
{
cout << "输入学号:";
int id = 0;
cin >> id;
tmp = studentroot->find(id);
tmp->erase();
cout << "已成功删除" << endl;
delete tmp;
}
else if ((input1 == "Q") || (input1 == "q"))
{
break;
}
else
{
cout << "输出有误!" << endl;
}
}
delete studentroot;
return 0;
}