| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 671 人关注过本帖
标题:帮我看看这个程序,真不知道错了哪里??
只看楼主 加入收藏
renhu
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2005-11-27
收藏
 问题点数:0 回复次数:2 
帮我看看这个程序,真不知道错了哪里??

#include<iostream>
#include<string>

using namespace std;

const int maxe=100;
int top=0;

class employee{

public:
employee(string,string,int,int,int);

void setname(string,string);
void setdata(int,int,int);
void getname() const;
void getdata() const;
void printemployee() const;

private:
string firstname;
string lastname;
int day;
int year;
int month;

};

employee::employee(string wfirst,string wlast,int wmonth,int wday,int wyear)
{

setname(wfirst,wlast);
setdata(wmonth,wday,wyear);
top++;

}

void employee::setname(string wfirst,string wlast)
{
firstname=wfirst;
lastname=wlast;

}

void employee::setdata(int wmonth,int wday,int wyear)
{
month=wmonth;
day=wday;
year=wyear;

}

void employee::getname() const
{
cout<<"name : "<<firstname<<" "<<lastname<<endl;
}

void employee::getdata() const
{
cout<<"date :"<<month<<'/'<<day<<'/'<<year<<endl;

}


void employee::printemployee() const
{
getname();
getdata();

}

int main()
{
employee *ptr[maxe];

ptr[0]=new employee("xiao","min",11,21,1984);
ptr[1]=new employee("xiao","gang",9,23,1983);

int choice=1;
int i;
string ufirst;
string ulast;
int umonth;
int uyear;
int uday;

while(choice!=0)
{
cout <<endl<<endl<<"\t\t\t weclome to employee system \n\n\n";
cout <<"\t\t\t1.list\n\n\t\t\t2.add\n\n\t\t\t3.change\n\n\t\t\t4.leave"<<endl;
cin >>choice;

switch(choice)
{
case 1:
for(i=0;i<top;i++)
ptr[i]->printemployee();break;

case 2:
cout<<"please enter the employee.the firstname :";
cin>>ufirst;
cout<<" the lastname :";
cin>>ulast;
cout<<" the birthday.the month :";
cin>>umonth;
cout<<" the day :";
cin>>uday;
cout<<" the year :";
cin>>uyear;
int temp=top;
ptr[temp]=new employee(ufirst,ulast,umonth,uday,uyear);
break;
case 3:

cout<<"enter the full name.the firstname: ";
cin>>ufirst;
cout<<"the lastname: ";
cin>>ulast;

for(i=0;i<top;i++)
if(ufirst==ptr[i]->firstname && ulast==ptr[i]->lastname)
{
cout<<"1,change name\n2,change date\n";
cin>>choice;
switch(choice)
{
case 1: cout<<"enter the new name";
cin>>ufirst>>ulast;
ptr[i]->setname(ufirst,ulast);break;

case 2: cout<<"enter the new date";
cin>>umonth>>uday>>uyear;
ptr[i]->setdata(umonth,uday,uyear);break;
}
}
cout<<"no one here!!!!!"<<endl;break;
}
}
return 0;
}


搜索更多相关主题的帖子: employee private include public 
2005-12-06 20:04
howema
Rank: 1
等 级:新手上路
帖 子:336
专家分:0
注 册:2005-10-4
收藏
得分:0 

开头的包含头文件少了后缀.h了

2005-12-06 20:38
RL720
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2005-11-6
收藏
得分:0 
楼上的不知道就不要乱说

firstname和lastname是priavte的 外部访问不到
做一个接口或者改成public的

然后把temp指针的声明放在switch前面



2005-12-06 23:32
快速回复:帮我看看这个程序,真不知道错了哪里??
数据加载中...
 
   



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

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