| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 762 人关注过本帖
标题:请大家帮帮看看啊!!!
只看楼主 加入收藏
weiqi1716
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-1-22
收藏
 问题点数:0 回复次数:5 
请大家帮帮看看啊!!!
   运行时我输入 完名称 在后面总是跳出1个数字   还有最后显示数据的时候也是这样到底哪里出问题了啊
    请大家运行看看    可以运行的  检查也没出错啊
 源代码是这样的
// 设计.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
const N=50; // 定义系统可录入的员工最大数值
string Ename[N];
long Enum[N];
char Esex[N];
int Eage[N];
int Eworktime[N];
float Epay[N];
class Employee
{
public:
string Employeename;
long Employeenum;
char Employeesex;
int Employeeage;  
int Employeeworktime;
float Employeepay;

static long EmployeeMaxNum;
static float EmployeeBasePay;
void NewInfo();
void ShowInfo();
void showall();
void showage(int min,int max);
void shownum(long number);
void RefreshInfo();
void DeleteInfo();
float Pay(int Employeegrade);
static int MaxNum();
};

class DBOperate
{
public:
string Employeename;
long Employeenum;
char Employeesex;
int Employeeage;
int Employeeworktime;
float Employeepay;

static long EmployeeMaxNum;
static float EmployeeBasePay;

void WriteIn(int iflag);
void ReadOut();
void RefreshMaxNum(int iflag); //i=1 or -1 or 0
};


long Employee::EmployeeMaxNum =0;
float Employee::EmployeeBasePay =800;

int Employee::MaxNum() //系统已经存储的人数
{
int MN = 0;
ifstream myf;
myf.open("EmployeeMaxNum.txt");
myf>>MN;
cout<<MN<<endl;
myf.close();
return MN;
}

void Employee::NewInfo() //添加新成员函数
{
cout<<"新员工姓名: ";
cin>>Employee::Employeename;
Employee::Employeenum = EmployeeMaxNum + Employee::MaxNum()+1;
cout<<"新员工性别 (F为女性,M为男性): ";
cin>>Employee::Employeesex;
cout<<"新员工年龄: ";
cin>>Employee::Employeeage;
cout<<"新员工的工作时(不需要输入单位): ";
cin>>Employee::Employeeworktime;

Employee::Employeepay = Employee::Pay(Employee::Employeeworktime);
DBOperate dbo;
dbo.ReadOut();
int MaxNum = Employee::MaxNum();
Enum[MaxNum] = Employee::Employeenum;
Ename[MaxNum] = Employee::Employeename;
Esex[MaxNum] = Employee::Employeesex;
Eage[MaxNum] = Employee::Employeeage;
Eworktime[MaxNum] = Employee::Employeeworktime;
Epay[MaxNum] = Employee::Employeepay;
dbo.WriteIn(1);
cout<<" 添加新成员成功!"<<endl;
return;
}

void Employee::ShowInfo() //程序主体 数据输出函数
{
int choice1,min,max;
long searchnum;
Employee e;

cout<<" 请选择查询方式:"<<endl;
cout<<"******************************************"<<endl;
cout<<"* 输出全体职工信息--------------------- 1"<<endl;
cout<<"* 按职工年龄输出----------------------- 2"<<endl;
cout<<"* 按职工编号输出----------------------- 3"<<endl;
cout<<"******************************************"<<endl;
cin>>choice1;
switch(choice1)
{
case 1: showall();break;
case 2: cout<<"请输入要查询的年龄范围: ";
cout<<"最小值: ";
cin>>min;
cout<<"最大值: ";
cin>>max;
e.showage(min,max);break;
case 3: cout<<"请输入要查询的员工号: ";
cin>>searchnum;
e.shownum(searchnum);break;
default: cout<<"出错啦! "<<endl;break;
}
}
void Employee::showall() //全体员工输出函数
{ int i;
int number;
for(i=0;i<Employee::MaxNum();i++)
{
number = Enum[i];
}
}

void Employee::showage(int min,int max) //按员工年龄段输出函数
{
int i;
for(i=0;i<Employee::MaxNum();i++)
{
if(Eage[i]>=min&&Eage[i]<=max)
{
long number = Enum[i];
shownum(number);
}
else continue;
}
}


void Employee::shownum(long number) //按员工编号输出函数
{
int i;
for(i=0;i<Employee::MaxNum();i++)
{
if(Enum[i] == number)
{
cout<<"**********************************"<<endl;
cout<<"员工编号 >"<<Enum[i]<<endl;
cout<<"姓 名 >"<<Ename[i]<<endl;
cout<<"性 别 >";
if(Esex[i]=='F') cout<<"女 "<<endl;
else if(Esex[i]=='M') cout<<"男 "<<endl;
cout<<"年 龄 >"<<Eage[i]<<"岁"<<endl;
cout<<"工作时长 >"<<Eworktime[i]<<"小时"<<endl;
cout<<"额定工资 >"<<Epay[i]<<"元"<<endl;
cout<<"**********************************"<<endl;
}
else continue;
}
}

void Employee::RefreshInfo() //修改员工信息的函数
{
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
//void Employee::shownum(long number);
cout<<"请输入您要修改的员工编号: >";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++) //遍历数据文件,查找要修改的员工数据
{
if(Enum[i] == cNum)
{
Employee::shownum(cNum);
cout<<"请输入该员工的新信息: "<<endl;
cout<<"新员工姓名: "; //录入员工的新的数据,员工号保持不变
cin>>Employee::Employeename;
Ename[i] = Employee::Employeename;
cout<<"新员工性别: [F为女性,M为男性]: ";
cin>>Employee::Employeesex;
Esex[i] = Employee::Employeesex;
cout<<"新员工年龄: ";
cin>>Employee::Employeeage;
Eage[i] = Employee::Employeeage;
cout<<"新员工的工作时 (不需要输入单位): ";
cin>>Employee::Employeeworktime;
Eworktime[i] = Employee::Employeeworktime;
Epay[i] = Employee::Pay(Employee::Employeeworktime);
break;
}
}

dbo.WriteIn(0);
}
void Employee::DeleteInfo() //删除员工数据的函数
{ char tmp;
int cNum = 1000;
DBOperate dbo;
dbo.ReadOut();
//void Employee::shownum(long number);
cout<<"请输入您要修改的员工编号>: ";
cin>>cNum;
int MN;
MN = Employee::MaxNum();
for(int i=0;i<MN;i++) //遍历数据文件,查找要删除的员工
{
if(Enum[i] == cNum)
Employee::shownum(cNum);
}
cout<<"确认要删除该员工信息?(Y为确认 N为放弃): ";
cin>>tmp;
if(tmp=='Y')
{
if(i==MN-1)
dbo.WriteIn(-1);
else
{
for(int j=i;j<MN-1;j++)
{ Enum[j] = Enum[j+1]; }
dbo.WriteIn(-1);
}
cout<<" 删除操作成功 ! "<<endl;
}
}
float Employee::Pay(int Employeeposition) //根据员工职位计算工资的函数
{
float tmpPay;
tmpPay = Employee::EmployeeBasePay + Employee::Employeeworktime * Employee::EmployeeBasePay;
return tmpPay;
}

void DBOperate::WriteIn(int iflag) //数据操作函数 写入
{
DBOperate::RefreshMaxNum(iflag);
ofstream myf("Employee.txt");
Employee e;
int MN;
MN = e.MaxNum();
for(int i=0;i<MN;i++)
{
myf<<Enum[i]<<'\n'<<Ename[i]<<'\n'<<Esex[i]<<'\n'<<Eage[i]<<'\n'<<Eworktime[i]<<'\n'<<Epay[i]<<'\n';
}
myf.close();
return;
}

void DBOperate::ReadOut() //数据操作函数 读出
{
ifstream myf("Employee.txt");
Employee e;
int MN;
MN = e.MaxNum();
for(int i=0 ;i<MN;i++)
{
myf>>DBOperate::Employeenum>>DBOperate::Employeename>>DBOperate::Employeesex>>DBOperate::Employeeage>>DBOperate::Employeeworktime>>DBOperate::Employeepay;
Enum[i] = DBOperate::Employeenum;
Ename[i] = DBOperate::Employeename;
Esex[i] = DBOperate::Employeesex;
Eage[i] = DBOperate::Employeeage;
Eworktime[i] = DBOperate::Employeeworktime;
Epay[i] = DBOperate::Employeepay;
}
myf.close();
}

void DBOperate::RefreshMaxNum(int iflag) //更新系统中员工计数文件的函数
{
int MaxNum = 0;
ifstream myif("EmployeeMaxNum.txt");
myif>>MaxNum;
myif.close();
MaxNum = MaxNum+iflag;
ofstream myof("EmployeeMaxNum.txt");
myof<<MaxNum;
myof.close();
}

int main() //主函数
{
int select = 0;
while(select!=5)
{
cout<<"         《主菜单》"<<endl;
cout<<"      请选择功能 "<<endl;
cout<<" ——————————————————————————————"<<endl;
cout<<"  1.新建并输入职工数据 "<<endl;
cout<<"  2.按条件输出职工数据 "<<endl;
cout<<"  3.修改指定职工的数据 "<<endl;
cout<<"  4.删除数据 "<<endl;
cout<<"  5.退出 ∣"<<endl;
cout<<" ——————————————————————————————"<<endl;
cout<<" 请选择您要服务的类别: " ;
cin>>select;
Employee e;
DBOperate dbo;
switch(select)
{
case 1:
e.NewInfo(); break;
case 2:
dbo.ReadOut();
e.ShowInfo(); break;
case 3:
e.RefreshInfo(); break;
case 4:
e.DeleteInfo(); break;
case 5: break;
default:
cout<<"命令错误!"<<endl;
}
if(select == 5)
break;
}
exit(1);
return 0;
}
搜索更多相关主题的帖子: 源代码 include 定义 int string 
2008-01-23 11:31
天使梦魔
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:37
帖 子:564
专家分:2754
注 册:2007-8-29
收藏
得分:0 
这么长................

你还是自己琢磨吧
2008-01-23 15:35
三月里de小雨
Rank: 1
等 级:新手上路
帖 子:76
专家分:0
注 册:2007-10-2
收藏
得分:0 
看不懂

请问小雨谁带我追寻
追寻那一颗爱我的心
2008-01-23 16:50
流浪飘泊
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-4-12
收藏
得分:0 
也是看不懂。。。。
2008-01-25 15:14
中学者
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:20
帖 子:3554
专家分:80
注 册:2007-9-14
收藏
得分:0 
是学C转C++的么???看到你的类就汗了.........
  实现与接口不分离......和用strcut有什么不同??

樱花大战,  有爱.
2008-01-25 16:42
eagleboycn
Rank: 1
等 级:新手上路
帖 子:191
专家分:0
注 册:2007-9-26
收藏
得分:0 
int Employee::MaxNum() //系统已经存储的人数
{
    int MN = 0;
    ifstream myf;
    myf.open("EmployeeMaxNum.txt");
    myf>>MN;
    /*cout<<MN<<endl; */    [bold][italic]注释掉这一句,不然,每次调用MaxNum()运行一次[/italic][/bold]
     myf.close();
    return MN;
}

[[italic] 本帖最后由 eagleboycn 于 2008-1-26 07:24 编辑 [/italic]]

兵法的精要在于韬晦自己
2008-01-26 07:22
快速回复:请大家帮帮看看啊!!!
数据加载中...
 
   



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

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