| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 278 人关注过本帖
标题:怎么我从文件里面读入的数据打印出来就是地址了~~代码如下!!请各位帮忙看 ...
只看楼主 加入收藏
书生小白
Rank: 2
等 级:论坛游民
帖 子:39
专家分:16
注 册:2011-6-14
结帖率:42.86%
收藏
 问题点数:0 回复次数:0 
怎么我从文件里面读入的数据打印出来就是地址了~~代码如下!!请各位帮忙看看!!
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
#define NULL 0
class student
{
private:
    long int num;//学生数据
    string name;
    string birthday;
    long int age;
    string dizhi;
    string dianhua;
    long int youbian;
    string E_mail;
   
public:
    class student *next;
    const student *getnext(){return next;};
    void setnext(class student *itnext){next=itnext;};
    const int getnum(){return num;};
    void setnum(int itnum){num=itnum;};
    const string getname(){return name;};
    void setname(string itname){name=itname;};
    const string getbirthday(){return birthday;};
    void setbirthday(string itbirthday){birthday=itbirthday;};
    const int getage(){return age;};
    void setage(int itage){age=itage;};
    const string getdizhi(){return dizhi;};
    void setdizhi(string itdizhi){dizhi=itdizhi;};
    const string getdianhua(){return dianhua;};
    void setdianhua(string itdianhua){dianhua=itdianhua;};
    const int getyoubian(){return youbian;};
    void setyoubian(int ityoubian){youbian=ityoubian;};
    const string getE_mail(){return E_mail;};
    void setE_mail(string itE_mail){E_mail=itE_mail;};
    void student_delet();
    void readdate();
    void reserve();
    void look_at_by_name();
    void student_scan();
    void look_at_by_num();
    void student_record();
    void student_insert(class student *stu);
    void mainmenu();
};

void welcome();
void student::mainmenu();
void change(class student *p);
void display(class student *p);
void student_changeall();
void student_change();
void student_look();
void freeall();
void freeall();
//void readdate();
//void reserve();
int totall_num=0;
class student *head=NULL;
void welcome()//显示欢迎信息
{
    cout<<"           "<<"+---------------------------+"<<endl;
    cout<<"           "<<"|                           |"<<endl;
    cout<<"           "<<"|  欢迎使用学生信息管理系统 |"<<endl;
    cout<<"           "<<"|     小白制作,复制必究    |"<<endl;
    cout<<"           "<<"|                           |"<<endl;
    cout<<"           "<<"+---------------------------+"<<endl;
}
void student::mainmenu()
{
    int temp;
    temp=-1;
   
    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;
        switch(temp)
        {
        case 0:
            reserve();
            freeall();
            break;
        case 1:
            student_record();
            break;
        case 2:
            readdate();
            student_delet();
            break;
        case 3:
            readdate();
            student_scan();
            break;
        case 4:
            readdate();
            student_look();
            break;
        case 5:
            readdate();
            student_change();
            break;
        case 6:
            readdate();
            student_changeall();
            break;
        default:
            {
                cout<<"输入有无,请重新输入"<<endl;
                return;
            }
        }


    }
    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>>p1->E_mail;
     p1->setname(p1->name);
     p1->setnext(p1->next);
     
     cout<<"该学生的信息为:"<<endl;
     cout<<"---------------------------------------------------------------------------"<<endl;
     cout<<"学号"<<setw(10)<<"姓名"<<setw(10)<<"生日"<<setw(10)<<"年龄"<<setw(10)
         <<"地址"<<setw(10)<<"电话"<<setw(14)<<"邮编"<<setw(10)<<"邮箱"<<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->getnum()>p1->getnum())&&(p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->getnum()<=p1->getnum())
        {
            if(head==p1)
                head=p0;
            else
            {
                p2->next=p0;
                p0->next=p1;
            }
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    totall_num=totall_num+1;
}
void display(class student *p)
{
    cout<<"学生总数为:"<<totall_num<<endl;
    cout<<p->getnum()<<setw(10)
        <<p->getname()<<setw(10)
        <<p->getbirthday()<<setw(10)
        <<p->getage()<<setw(10)
        <<p->getdizhi()<<setw(14)
        <<p->getdianhua()<<setw(12)
        <<p->getyoubian()<<setw(10)
        <<p->getE_mail()<<endl;
    cout<<"--------------------------------------------------------------------------"<<endl;
    cout<<endl;
   
}
void student::student_delet()//删除学生信息
{
    long int a;
    class student *p1,*p2;
    if(head==NULL)
    {
        cout<<"没有该学生信息!!";
        return;
    }
    cout<<"请输入您需要删除学生的学号"<<endl;
    cin>>a;
    p2=p1=head;
    while(a!=p1->getnum()&&p1->getnext()!=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(10)<<"姓名"<<setw(10)<<"生日"<<setw(10)<<"年龄"<<setw(10)
         <<"地址"<<setw(10)<<"电话"<<setw(14)<<"邮编"<<setw(10)<<"邮箱"<<endl;
        cout<<"------------------------------------------------------------------------";
        do
        {
            display(p);
            p=p->next;
        }
        while(p!=NULL);
    }
    cout<<endl;
}
void student_look()//学生信息查看
{
    class student *ps=NULL;
    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:ps->look_at_by_num();break;
        case 2:ps->look_at_by_name();break;
        default:cout<<"选项错误";break;
        }
    }
    while(temp!=0);

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

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

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

    }
    p=head;
    while((name==p->getname())&&(p->getnext()!=NULL))
    {
        p=p->next;
    }
    if(name==p->getname())
    {
        cout<<"学号"<<setw(10)<<"姓名"<<setw(10)<<"生日"<<setw(10)<<"年龄"<<setw(10)
         <<"地址"<<setw(10)<<"电话"<<setw(14)<<"邮编"<<setw(10)<<"邮箱"<<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->getnum())&&(p1->next!=NULL))
    {
        p2=p1;
        p1=p1->next;
    }
    if(num==p1->getnum())
    {
        change(p1);
    }
    else
        cout<<"没有学生记录"<<endl;
}
void change(class student *p)
{
    int temp;
    temp=-1;
    long int num;
    string name;
    string birthday;
    long int age;
    string dizhi;
    string dianhua;
    long int youbian;
    string E_mail;
    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>>num;
            p->setnum(num);break;
        case 2:cout<<"请输入新的姓名:"<<setw(3);
            cin>>name;
            p->setname(name);break;
        case 3:cout<<"请输入新的年龄:"<<setw(3);
            cin>>age;
            p->setage(age);break;
        case 4:cout<<"请输入新的地址:"<<setw(3);
            cin>>dizhi;
            p->setdizhi(dizhi);break;
        case 5:cout<<"请输入新的出生年月:"<<setw(3);
            cin>>birthday;
            p->setbirthday(birthday);break;
        case 6:cout<<"请输入新的邮编:"<<setw(3);
            cin>>youbian;
            p->setyoubian(youbian);break;
        case 7:cout<<"请输入新的电话:"<<setw(3);
            cin>>dianhua;
            p->setdianhua(dianhua);break;
        case 8:cout<<"请输入新的E-mail:"<<setw(3);
            cin>>E_mail;
            p->setE_mail(E_mail);break;
        default:
            cout<<"输入错误";
            continue;
        }
    }
    while(temp!=0);

}
void student_changeall()
{
    class student *p1,*p2;
    long int num;
    string name;
    string birthday;
    long int age;
    string dizhi;
    string dianhua;
    long int youbian;
    string E_mail;
    if(head==NULL)
    {
        cout<<"没有学生记录!!!!"<<endl;
        return;
    }
    cout<<"请输入您需要修改的学生学号:"<<setw(3);
    cin>>num;
    p2=p1=head;
    while(num!=p1->getnum()&&p1->next!=NULL)
    {
        p2->next=p1;
        p1=p1->next;

    }
   
    cout<<"请输入新的学号:"<<setw(3);
    cin>>num;
    p1->setnum(num);
    cout<<"请输入新的姓名:"<<setw(3);
    cin>>name;
    p1->setname(name);
    cout<<"请输入新的年龄:"<<setw(3);
    cin>>age;
    p1->setage(age);
    cout<<"请输入新的地址:"<<setw(3);
    cin>>dizhi;
    p1->setdizhi(dizhi);
    cout<<"请输入新的出生年月:"<<setw(3);
    cin>>birthday;
    p1->setbirthday(birthday);
    cout<<"请输入新的邮编:"<<setw(3);
    cin>>youbian;
    p1->setyoubian(youbian);
    cout<<"请输入新的电话:"<<setw(3);
    cin>>dianhua;
    p1->setdianhua(dianhua);
    cout<<"请输入新的E-mail:"<<setw(3);
    cin>>E_mail;
    p1->setE_mail(E_mail);

}
void student::reserve()//写入文件
{
    class student *p;
    p=head;
    ofstream outfile("f1.txt",ios::app);
    if(!outfile)
     {
         cerr<<"open error"<<endl;
         exit(1);
         return;
     }
    outfile<<totall_num;
     for(p=head;p!=NULL;p=p->next)
     {
         outfile<<p->getnum
             <<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 student::readdate()
{
    int i=0;
    class student *p1, *p2;
    ifstream infile("f1.txt",ios::in);
    if (!infile)
    {
        cout<<"文件打开错误!";
        return ;
    }
    infile>>totall_num;
    head=p1=p2=new class student;
        &p1->num, p1->name,p1->birthday,&p1->age,
           p1->dizhi,p1->dianhua,&p1->youbian,p1->E_mail;
    while(infile&&p1->getnum!=NULL)
    {
        if(i==totall_num)
        {
            p2->next = NULL;
            infile.close();
            return;
        }
   
        p1=new class student;
        &p1->num,p1->name,p1->birthday,&p1->age,
           p1->dizhi, p1->dianhua,&p1->youbian,p1->E_mail;
        p2->next = p1;
        p2 = p1;
        i++;
    }
        

}

int main()
{
    student* pStu=NULL;
    string setname;
    string setcode;
    string code;
    int i;
    welcome();   
    cout<<"管理员初始帐号为:xiaobai"<<endl;
    cout<<"管理员初始密码为:888888"<<endl;
    cout<<"温馨提示,为了数据安全,如果连续3次输入错误系统将推出。"<<endl;
    for(i=0;i<3;i++)
    {
   
        cout<<"请输入你的帐号:";
        cin>>setname;
        cout<<"请输入密码:";

        cin>>code;


        setcode=code;
        if(setname=="xiaobai"&&setcode=="888888")
        {
            cout<<"用户名和密码正确"<<endl;
            pStu->mainmenu();
            break;
        }
        else
        {
            if(i<2)
            {
                cout<<"用户名或密码错误,请重新输入"<<endl;
            }
            else
            {
                cout<<"您已经连续输入3次错误,系统将退出";
            }
        }
    }
    return 0;
}
搜索更多相关主题的帖子: private return 
2011-06-18 19:40
快速回复:怎么我从文件里面读入的数据打印出来就是地址了~~代码如下!!请各位帮 ...
数据加载中...
 
   



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

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