| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3977 人关注过本帖
标题:学生管理系统出错,大家帮忙看看,谢谢啦
只看楼主 加入收藏
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
结帖率:88.89%
收藏
 问题点数:0 回复次数:1 
学生管理系统出错,大家帮忙看看,谢谢啦
错误    3    error C2440: “return”: 无法从“std::string”转换为“float”    c:\users\think\documents\visual studio 2013\projects\project1\project1\c1.cpp    77    1    Project1

    4    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;
}
搜索更多相关主题的帖子: Documents documents 管理系统 include return 
2016-03-30 22:46
醒山
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:9
帖 子:463
专家分:2071
注 册:2015-5-25
收藏
得分:0 
知道了,哈哈
2016-03-30 23:01
快速回复:学生管理系统出错,大家帮忙看看,谢谢啦
数据加载中...
 
   



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

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