标题:逻辑错误
取消只看楼主
你爸边哭边
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2017-10-30
结帖率:66.67%
 问题点数:0 回复次数:0 
逻辑错误
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
class base
{
public:
protected:string name;char sex;string addr;
};
class teacher:public base
{public:
void show1();
void display1();
private:
    float wages;
};
class student:public base
{
public:
    void show2();
    void display2();
private:
    float grade;
};
void teacher::display1()
{
    cout<<"请输入姓名:"<<endl;
   
    cout<<"请输入性别"<<endl;
    cin>>sex;
    cout<<"请输入地址"<<endl;

    cout<<"请输入工资"<<endl;
    cin>>wages;
}
void student::display2()
{
    cout<<"请输入姓名:"<<endl;
    cin>>name;
    cout<<"请输入性别"<<endl;
    cin>>sex;
    cout<<"请输入地址"<<endl;
    cin>>addr;
    cout<<"请输入成绩"<<endl;
    cin>>grade;
}
void teacher::show1()
{    cout<<"name:"<<name<<endl;
cin>>name;
    cout<<"sex:"<<sex<<endl;
cin>>addr;
    cout<<"address:"<<addr<<endl;
    cout<<"wages:"<<wages<<endl;
}
void student::show2()
{    cout<<"name:"<<name<<endl;
    cout<<"sex:"<<sex<<endl;
    cout<<"address:"<<addr<<endl;
    cout<<"grade:"<<grade<<endl;
}
#include<fstream>
void main()
{
    int a,b,i,c;
    cout<<"请选择:1.输入  2.查询"<<endl;
    cin>>a;
    if(a==1)
    {
        cout<<"请选择: 1老师 2学生"<<endl;
        cin>>b;
        if(b==1)
        {
            teacher tea[2];
            do
            {
                tea[2].display1();
                i--;
            }while(i==0);
            ofstream outfile("teacher.dat",ios::binary|ios::trunc);
            if(!outfile)
            {cerr<<"open error"<<endl;
            abort();
            }
            for(i=0;i<2;i++)
                outfile.write((char*)&tea[i],sizeof(tea[i]));
            outfile.close();
            
        }
        if(b==2)
        {   
            student stud[2];
            do
            {
                stud[2].display2();
                i--;
            }while(i==0);
            ofstream outfile("student.dat",ios::binary|ios::trunc);
            if(!outfile)
            {cerr<<"open error"<<endl;
            abort();
            }
            for(i=0;i<2;i++)
                outfile.write((char*)&stud[i],sizeof(stud[i]));
            outfile.close();
        }
        
    }
    if(a==2)
    {
        cout<<"请选择: 1老师 2学生"<<endl;
        cin>>c;
        if(c==1)
        {   
            teacher tea[2];
            ifstream infile("teacher.dat",ios::binary);
            if(!infile)
            {cerr<<"open error"<<endl;
            abort();
            }
            for(i=0;i<2;i++)
                infile.read((char*)&tea[i],sizeof(tea[i]));
            infile.close();
            for(i=0;i<2;i++)
            {
                tea[i].show1();
            }
            if(c==2)
            {   
                student stud[2];
                ifstream infile("student.dat",ios::binary);
                if(!infile)
                {cerr<<"open error"<<endl;
                abort();
                }
                for(i=0;i<2;i++)
                    infile.read((char*)&stud[i],sizeof(stud[i]));
                infile.close;
                for(i=0;i<2;i++)
                {
                    stud[i].show2();
                }
               
            }
        }
    }
}
刚学,不知道怎么改
搜索更多相关主题的帖子: name void cout 输入 cin 
2018-05-29 23:12



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-487406-1-1.html




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

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