| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 513 人关注过本帖
标题:[求助]C++基础问题
只看楼主 加入收藏
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
 问题点数:0 回复次数:3 
[求助]C++基础问题

我的程序能运行但是有乱码,请大虾帮助看一下,在下不胜感激,谢谢!

#include <cstring>
#include<iostream>
using namespace std;
class Employee{
private:char name[10];
char address[20];
char city[15];
char stampno[6];
public:void change_name(char str[10]);
void display();
void Setname(char *namestr);
void Setaddress(char *addr);
void Setcity(char *cty);
void Setstampno(char *no);
};

void Employee::Setname(char *namestr)
{strcpy(name,namestr);}

void Employee::Setaddress(char *addr)
{strcpy(address,addr);}

void Employee::Setcity(char *cty)
{strcpy(city,cty);}

void Employee::Setstampno(char *no)
{strcpy(stampno,no);}

void Employee::change_name (char *str)
{ strcpy(name,str);}

void Employee::display()
{cout<<"name:"<<name<<endl<<"address:"<<address<<endl<<"city:"<<city<<endl<<"stampno:"<<stampno<<endl;}


void main()
{ char namestr[10],addr[20],cty[15],str[10],no[6] ;

Employee employee;

cout<<"please enter employeer's name :"<<endl;
cin>>namestr[10];
employee.Setname(namestr);


cout<<"please enter employeer's address:"<<endl;
cin>>addr[20];
employee.Setaddress(addr);

cout<<"please enter employeer's city:"<<endl;
cin>>cty[15] ;
employee.Setcity(cty);

cout<<"please enter employeer's stampno:"<<endl;
cin>>no;
employee.Setstampno(no);

employee.display();

cout<<"please enter your new name :"<<endl;
cin>>str;
employee.change_name(str);

employee.display();
}

搜索更多相关主题的帖子: 不胜感激 private display include 
2006-10-12 16:13
雨夜微醺
Rank: 1
等 级:新手上路
威 望:1
帖 子:147
专家分:0
注 册:2006-9-25
收藏
得分:0 

#include <cstring>
#include<iostream>
using namespace std;
class Employee{
private:char name[10];
char address[20];
char city[15];
char stampno[6];
public:void change_name(char str[10]);
void display();
void Setname(char *namestr);
void Setaddress(char *addr);
void Setcity(char *cty);
void Setstampno(char *no);
};

void Employee::Setname(char *namestr)
{strcpy(name,namestr);}

void Employee::Setaddress(char *addr)
{strcpy(address,addr);}

void Employee::Setcity(char *cty)
{strcpy(city,cty);}

void Employee::Setstampno(char *no)
{strcpy(stampno,no);}

void Employee::change_name (char *str)
{ strcpy(name,str);}

void Employee::display()
{cout<<"name:"<<name<<endl<<"address:"<<address<<endl<<"city:"<<city<<endl<<"stampno:"<<stampno<<endl;}


void main()
{ char namestr[10],addr[20],cty[15],str[10],no[6] ;

Employee employee;

cout<<"please enter employeer's name :"<<endl;
cin>>namestr/*[10]*/;//namestr[10]不是一个字符串,不要误用,数组声明时带下标才表示数组,其他时候
//只表示一个数足元素,
employee.Setname(namestr);


cout<<"please enter employeer's address:"<<endl;
cin>>addr/*[20]*/;
employee.Setaddress(addr);

cout<<"please enter employeer's city:"<<endl;
cin>>cty/*[15] */;
employee.Setcity(cty);

cout<<"please enter employeer's stampno:"<<endl;
cin>>no;
employee.Setstampno(no);

employee.display();

cout<<"please enter your new name :"<<endl;
cin>>str;
employee.change_name(str);

employee.display();
}


我若想到你就有种莫名的开心 我一见到你就有种莫名的悸动
2006-10-12 17:03
cl_zdl
Rank: 1
等 级:新手上路
威 望:1
帖 子:71
专家分:0
注 册:2006-10-11
收藏
得分:0 
谢谢 雨夜微醺 !
2006-10-12 18:36
lyy5552489
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2006-10-9
收藏
得分:0 
厉害,学习了

2006-10-23 16:52
快速回复:[求助]C++基础问题
数据加载中...
 
   



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

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