| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 553 人关注过本帖
标题:求一哥们帮忙解决下问题,看看下面这个代码,有两处错误,一直看不出来,有 ...
只看楼主 加入收藏
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
结帖率:42.86%
收藏
已结贴  问题点数:20 回复次数:5 
求一哥们帮忙解决下问题,看看下面这个代码,有两处错误,一直看不出来,有点小急,谢谢拉。。。
#include <stdio.h>
#include <iomanip>
#include <iostream>
#include <malloc.h>
#include <string>
#include <io.h>
#include <windows.h>
#include <fstream>
using namespace std;
#define NULL 0
//#define "F:\C++作业设计\xuesheng,txt"
class student
{
private:
    int long num;//学生数据
    string name;
    int birthday;
    int age;
    string dizhi;
    int dianhua;
    int youbian;
    string E_mail;
    class student *next;
public:
void welcome();
void mainneun();
void delet();
void student::student_scan();
void student::look_at_by_num();
void student::display(class student *p);
void student_record();
void student_insert(class student *stu);
};
void look_at_by_num();
void look_at_by_name();
void display(class student *p);
void student_changeall();
void student_change();
void student_look();
void student_scan();
void student_dele();
void student_record();
void freeall();
void freeall();
void readdate();
void reserve();
int totall_num=0;
//class student *p[100];
class student *head=NULL;
void welcome()//显示欢迎信息
{
    cout<<"+---------------------------+"<<endl;
    cout<<"|                           |"<<endl;
    cout<<"|  欢迎使用学生信息管理系统 |"<<endl;
    cout<<"|     小白制作,复制必究    |"<<endl;
    cout<<"|                           |"<<endl;
    cout<<"+---------------------------+"<<endl;
}
void student::mainneun()
{
    int temp;
    temp=-1;
    readdate();
    cout<<"为了你操作的数据正常保存,请按顺序退出系统"<<endl;
    do
    {
        cout<<endl;
        cout<<"~---------------------~"<<endl;
        cout<<"    学生管理主菜单    "<<endl;
        cout<<"~---------------------~"<<endl;
        cout<<"|**************************|"<<endl;
        cout<<"|   录入学生信息请按---[1] |"<<endl;
        cout<<"|   删除学生信息请按---[2] |"<<endl;
        cout<<"|   浏览学生信息请按---[3] |"<<endl;
        cout<<"|   查询学生信息请按---[4] |"<<endl;
        cout<<"|   修改学生信息请按---[5] |"<<endl;
        cout<<"|   修改全部信息请按---[6] |"<<endl;
        cout<<"|   退出学生系统请按---[0] |"<<endl;
        cout<<"|**************************|"<<endl;
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
        cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
        cout<<"请输入你选择的操作";
        cin>>temp;
        if(temp>6)
        {
            cout<<"输入错误,请重新输入";
        
        }break;
        switch(temp)
        {
        case 0:reserve();
            freeall();
        case 1:student_record();break;
        case 2:student_dele();break;
        case 3:student_scan();break;
        case 4:student_look();break;
        case 5:student_change();break;
        case 6:student_changeall();break;
        }


    }
    while(temp!=0);
}
void student::student_record()//学生的录入
{
//    int st_num;
    class student *p1;
     p1=new student;
     cout<<"请输入学生资料"<<endl;
     cout<<"请输入学生学号"<<endl;
     cin>>p1->num;
     cout<<"请输入学生姓名"<<endl;
     cin>>p1->name;
     cout<<"请输入学生生日"<<endl;
     cin>>p1->birthday;
     cout<<"请输入学生年龄"<<endl;
     cin>>p1->age;
     cout<<"请输入学生地址"<<endl;
     cin>>p1->dizhi;
     cout<<"请输入学生电话"<<endl;
     cin>>p1->dianhua;
     cout<<"请输入学生邮编"<<endl;
     cin>>p1->youbian;
     cout<<"请输入学生邮箱"<<endl;
     cin>>E_mail;
     
     cout<<"该学生的信息为:"<<endl;
     cout<<"---------------------------------------------------------------------------"<<endl;
     cout<<"学号"<<setw(5)<<"姓名"<<setw(5)<<"生日"<<setw(5)<<"年龄"<<setw(5)
         <<"地址"<<setw(5)<<"电话"<<setw(5)<<"邮编"<<setw(5)<<"邮箱"<<endl;
     student_insert(p1);
     display(p1);
    /* cout<<this->num<<setw(5)<<this->name<<setw(5)<<this->birthday<<setw(5)
         <<this->age<<setw(5)<<this->dizhi<<setw(5)<<this->dianhua<<setw(5)
         <<this->youbian<<setw(5)<<this->E-mail<<endl;*/
}
void student::student_insert(class student *stu)//链表
{
    class student *p0,*p1,*p2;
    p1=head;
    p0=stu;
    if(head==NULL)
    {
        head=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num>p1->num)&&(p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num<=p1->num)
        {
            if(head==p1)
                head=p0;
            else
            {
                p2->next=p0;
                p0->next=p1;
            }
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    totall_num++;
}
void student::display(class student *p)
{
    cout<<"学生总数为:"<<totall_num<<endl;
    cout<<p->num<<setw(5)
    <<p->name<<setw(5)
    <<p->birthday<<setw(5)
         <<p->age<<setw(5)
         <<p->dizhi<<setw(5)
         <<p->dianhua<<setw(5)
         <<p->youbian<<setw(5)
         <<p->E_mail<<endl;
    cout<<"--------------------------------------------------------------------------"<<endl;
   
}
void student::delet()//删除学生信息
{
    long int a;
    class student *p1,*p2;
    if(head==NULL)
    {
        cout<<"没有该学生信息!!";
        return;
    }
    cout<<"请输入您需要删除学生的学号"<<endl;
    cin>>a;
    p2=p1=head;
    while(a!=p1->num&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(a==p1->num)
    {
        if(p1==head)
            head=p1->next;
        else
            p2->next=p1->next;
        free(p1);
        totall_num--;
    }
    else
        cout<<"没有该学生信息,请正确输入!";
}
void student::student_scan()//学生信息浏览
{
    class student *p;
    cout<<"学生总数为:"<<totall_num<<endl;
    p=head;
    if(head==NULL)
    {
        cout<<"没有该学生,请重新输入";
        return;
    }
    if(head!=NULL)
    {
        cout<<"学号"<<setw(5)<<"姓名"<<setw(5)<<"生日"<<setw(5)<<"年龄"<<setw(5)
         <<"地址"<<setw(5)<<"电话"<<setw(5)<<"邮编"<<setw(5)<<"邮箱"<<endl;
        cout<<"------------------------------------------------------------------------";
        do
        {
            display(p);
            p=p->next;
        }
        while(p!=NULL);
    }
    cout<<endl;
}
void student_look()//学生信息查看
{
    int temp;
    temp=-1;
    do
    {
        cout<<endl;
        cout<<"+--------------------------+"<<endl;
        cout<<"|    按学号查询请按---[1]  |"<<endl;
        cout<<"|    按姓名查询请按---[2]  |"<<endl;
        cout<<"|    取消请按---------[0]  |"<<endl;
        cout<<"+--------------------------+"<<endl;
        cout<<"请您选择:"<<setw(3);
        cin>>temp;
        switch(temp)
        {
        case 0:return;
        case 1:look_at_by_num();break;
        case 2:look_at_by_name();break;
        default:cout<<"选项错误";break;
        }
    }
    while(temp!=0);

}
void student::look_at_by_num()//按学号查询
{
    int num;
    class student *p;
    cout<<"请输入需要查询的学生学号:"<<setw(3);
    cin>>num;
    if(head==NULL)
    {
        cout<<"没有该学生";
        return;
    }
    p=head;

    while((num!=p->num)&&(p->next!=NULL))
    {
        p=p->next;
    }
    if(num==p->num)
    {
        cout<<"学号"<<setw(5)<<"姓名"<<setw(5)<<"生日"<<setw(5)<<"年龄"<<setw(5)
         <<"地址"<<setw(5)<<"电话"<<setw(5)<<"邮编"<<setw(5)<<"邮箱"<<endl;
        cout<<"------------------------------------------------------------------------";
        display(p);

    }
    else
        cout<<"没有该学生记录";
}
void look_at_by_name()//按姓名查找
{
    string name1;
    class student *p;
    cout<<"请输入学生的姓名:"<<setw(3);
    cin>>name1;
    if(head==NULL)
    {
        cout<<"没有该学生记录";
        return;

    }
    p=head;
    while(strcmp(name1,p->name)==0&&p->next!=NULL)
    {
        p=p->next;
    }
    if(strcmp(name1,p->name))
    {
        cout<<"学号"<<setw(5)"姓名"<<setw(5)<<"生日"<<setw(5)<<"年龄"<<setw(5)"
         <<"地址"<<setw(5)"电话"<<setw(5)<<"邮编<<"setw(5)"<<"邮箱"<<endl;
        cout<<"------------------------------------------------------------------------";
        display(p);

    }
    else
        cout<<"没有学生记录";
}
void student_change()//学生信息修改
{
    class student *p1,*p2;
    long int num;
    if(head==NULL)
    {
        cout<<"无该学生记录";
        return;
    }
    cout<<"请输入您需要修改的学生学号:"<<setw(3);
    cin>>num;
    p1=head;
    while(num!=p1->num&&p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->num)
    {
        change(p1)
    }
}
void change(class student *p)
{
    int temp;
    temp=-1;
    do
    {
        cout<<"请选择你需要修改的选项内容:"<<endl;
        cout<<"+-------------------------+"<<endl;
        cout<<"|   学号请按---------[1]  |"<<endl;
        cout<<"|   姓名请按---------[2]  |"<<endl;
        cout<<"|   年龄请按---------[3]  |"<<endl;
        cout<<"|   地址请按---------[4]  |"<<endl;
        cout<<"|   出生年月请按-----[5]  |"<<endl;
        cout<<"|   邮编请按---------[6]  |"<<endl;
        cout<<"|   电话请按---------[7]  |"<<endl;
        cout<<"|   E-mail请按-------[8]  |"<<endl;
        cout<<"|   取消请按---------[0]  |"<<endl;
        cout<<"+-------------------------+"<<endl;
        cout<<"请输入你的选择:"<<setw(3);
        cin>>temp;
        switch(temp)
        {
        case 0:return;
        case 1:cout<<"请输入新的学号:"<<setw(3);
            cin>>p->num;break;
        case 2:cout<<"请输入新的姓名:"<<setw(3);
            cin>>p->name;break;
        case 3:cout<<"请输入新的年龄:"<<setw(3);
            cin>>p->age;break;
        case 4:cout<<"请输入新的地址:"<<setw(3);
            cin>>p->dizhi;break;
        case 5:cout<<"请输入新的出生年月:"<<setw(3);
            cin>>p->birthday;break;
        case 6:cout<<"请输入新的邮编:"<<setw(3);
            cin>>p->youbian;break;
        case 7:cout<<"请输入新的电话:"<<setw(3);
            cin>>p->dianhua;break;
        case 8:cout<<"请输入新的E-mail:"<<setw(3);
            cin>>p->E_mail;break;
        default:cout<<"输入错误"

        }
    }
    while(temp!=0);

}
void student_changeall(class student *p)
{
    cout<<"请输入新的学号:"<<setw(3);
    cin>>p->num;
    cout<<"请输入新的姓名:"<<setw(3);
    cin>>p->name;
    cout<<"请输入新的年龄:"<<setw(3);
    cin>>p->age;
    cout<<"请输入新的地址:"<<setw(3);
    cin>>p->dizhi;
    cout<<"请输入新的出生年月:"<<setw(3);
    cin>>p->birthday;
    cout<<"请输入新的邮编:"<<setw(3);
    cin>>p->youbian;
    cout<<"请输入新的电话:"<<setw(3);
    cin>>p->dianhua;
    cout<<"请输入新的E-mail:"<<setw(3);
    cin>>p->E_mail;

}
void reserve()//写入文件
{
    class student *p1;
    p1=head;
    outfile.open("F:\C++作业设计\f1.dat",ios::out);
     if(! outfile)
     {
         cerr<<"open error"<<endl;
         exit(1);
         return;
     }
     for(p=head;p!=NULL;P=P->next)
     {
         outfile<<p->num
             <<p->name
             <<p->age
             <<p->dizhi
             <<p->birthday
             <<p->youbian
             <<p->dianhua
             <<p->E_mail;
     }
     outfile.close;
}
void freeall()//释放空间
{
    class student *p1,*p2;
    p1=p2=head;
    while(p1)
    {
        p2=p1->next;
        free(p1);
        p1=p2;
    }

}
void readdate()
{
    FILE*  fp;//文件指针
    class student *p1, *p2;

    fp = fopen(FILE_DATA_PATH, "r");
    if (!fp)
    {
  printf("文件打开错误!");
        return ;
    }
 
 fscanf(fp,"%d\n", &TOTAL_NUM);
 head = p1 = p2 = (struct student *)malloc(LEN);
 fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n",
        &p1->num, p1->name,&p1->birthday,&p1->age, p1->dizhi, &p1->dianhua,&p1->youbian,p1->E_mail);
 while(!feof(fp))
 {
  p1 = (struct student *)malloc(LEN);
  fscanf(fp,"%ld\t%s\t%d\t%s\t%s\t%s\t%ld\t%s\n",
           &p1->num, p1->name,&p1->birthday, &p1->age, p1->dizhi, &p1->dianhua, &p1->youbian, p1->E_mail);
  p2->next = p1;
  p2 = p1;
 }
 p2->next = NULL;
 fclose(fp);
}

}
int main()
{
    string setname;
    string setcode;
    char code[20];
    int i,j;
    welcome();
    for(i=0;i<3;i++)
    {
        cout<<"管理员初始帐号为:xiaobai"<<endl;
        cout<<"管理员初始密码为:888888"<<endl;
        cout<<"请输入你的帐号:";
        cin>>setname;
        cout<<"请输入密码:";
        for(j=0,j<20,j++)
        {
            cin>>code[j];
            cout<<"*";
        }
        setcode=code;
        if((strcmp(setname,"xiaobai")==0)&&(strcmp(setcode,"888888")==0))
        {
            cout<<"用户名和密码正确";
            mainneun();
            break;
        }
        else
        {
            if(i<2)
            {
                cout<<"用户名或密码错误,请重新输入";
            }
            else
            {
                cout<<"您已经连续输入3次错误,系统将退出"
            }
        }
    }
    return 0;
}
搜索更多相关主题的帖子: welcome private long 
2011-06-14 13:57
yuutian
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:137
专家分:686
注 册:2010-10-27
收藏
得分:0 
你可以把错误的提示信息发给看一下。
        这么长的代码,难看呢。
2011-06-14 15:46
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
收藏
得分:0 
f:\c++作业设计\xuesheng.cpp(306) : error C2248: 'name' : cannot access private member declared in class 'student'
        f:\c++作业设计\xuesheng.cpp(16) : see declaration of 'name'
f:\c++作业设计\xuesheng.cpp(306) : error C2664: 'strcmp' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
f:\c++作业设计\xuesheng.cpp(306) : error C2248: 'next' : cannot access private member declared in class 'student'
        f:\c++作业设计\xuesheng.cpp(23) : see declaration of 'next'
f:\c++作业设计\xuesheng.cpp(306) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.

xuesheng.exe - 4 error(s), 0 warning(s)
这就是错误提示了,麻烦各位看看哈
2011-06-14 16:17
szgg520
Rank: 5Rank: 5
等 级:职业侠客
威 望:3
帖 子:79
专家分:307
注 册:2011-6-13
收藏
得分:0 
那一行报错都说了,类型转化错误呀。。。。。

[url=http://www.]深圳复印机出租[/url]
2011-06-14 16:23
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
收藏
得分:0 
呃。。。麻烦详细点吧,错误在(按姓名查找)     那个地方,我这里好像也没有类型转换啊
2011-06-14 16:31
try_catch
Rank: 2
等 级:论坛游民
帖 子:32
专家分:82
注 册:2011-6-17
收藏
得分:20 
第一个和第三个很简单,就是你在class外面调用private的东西了,不懂的话去查private和public的区别
第二个我明白你是怎么错了,不过代码太长了,懒的在你程序里面找,就是你把stirng和char*搞混了,想把string换成char*就用string.c_str()就好了
2011-06-17 04:36
快速回复:求一哥们帮忙解决下问题,看看下面这个代码,有两处错误,一直看不出来 ...
数据加载中...
 
   



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

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