cout<<;
}
cout<}
}
voidinput()
{
inti,j;
cout<<for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
.
精品文档
cin>>a[i][j];
}
}
}
intmain()
{
input();
showTrans();
return0;
}
2.lab6_2.cpp
#include
usingnamespacestd;
int*p[9];
voidshowTrans()
{
inti,j;
cout<<for(i=0;i<3;i++)
{
for(j=i;j<9;j=j+3)
{
cout<<*p[j];
cout<<;
}
cout<}
}
voidinput()
{
inti,n;
cout<<for(i=0;i<9;i++)
{
cin>>n;
p[i]=newint(n);
}
}
intmain()
{
input();
showTrans();
.
精品文档
inti;
for(i=0;i<9;i++)
{
deletep[i];
}
return0;
}
3.lab6_3.cpp
#include
//不使用系统自带函数strcpy
usingnamespacestd;
chara[20]={\/0},b[20]={\/0},c[45]={\/0};
intmain()
{
inti,j,k;
cout<<cin.getline(a,20,'\n');
cout<<cin.getline(b,20,'\n');
intm=0,n=0;
//将数组a中的字符串拷贝到数组c中
for(k=0;k<45,a[m]!
='\0';k++,m++)
{
c[k]=a[m];
}
//将数组b中的字符串接着a,拷贝到数组c中
for(;k<45,b[n]!
='\0';k++,n++)
{
c[k]=b[n];
}
cout<return0;
}
4.lab6_4.cpp
#include
#include
usingnamespacestd;
chara[20]={\/0},b[20]={\/0};
intmain()
{
.
精品文档
cout<<cin.getline(a,20,'\n');
cout<<cin.getline(b,20,'\n');
strings1=a;
strings2=b;
strings3=s1+s2;
cout<return0;
}
5.Employee.h
#ifndefEmployee_H_INCLUDED
#defineEmployee_H_INCLUDED
classEmployee
{
private:
charname[15];
charaddress[25];
charcity[10];
intpostcode;
public:
Employee();
Employee(charn,chara,charc,intp);
~Employee();
voidchange_name();
voidchange_address();
voidchange_city();
voidchange_postcode();
voiddisplay();
};
#endif//Employee_H_INCLUDED
Employee.cpp
#include
#includeEmployee.h
usingnamespacestd;
Employee:
:
Employee(){}
Employee:
:
Employee(charn,chara,charc,intp)
{
.
精品文档
name[0]=n;
name[1]='\0';
address[0]=a;
address[1]='\0';
city[0]=c;
city[1]='\0';
postcode=p;
}
Employee:
:
~Employee(){}
voidEmployee:
:
change_name()
{
cout<<cin.getline(name,15,'\n');
}
voidEmployee:
:
change_address()
{
cout<<cin.getline(address,25,'\n');
}
voidEmployee:
:
change_city()
{
cout<<cin.getline(city,10,'\n');
}
voidEmployee:
:
change_postcode()
{
cout<<cin>>postcode;
}
voidEmployee:
:
display()
{
cout<<cout<<
ame:
<cout<<
cout<<cout<<}
intmain()
{
Employeeperson(1,1,1,1);
person.display();
person.change_name();
person.change_address();
person.change_city();
.
精品文档
person.change_postcode();
person.display();
return0;
}
6.Employee.h
#ifndefEmployee_H_INCLUDED
#defineEmployee_H_INCLUDED
classEmployee
{
private:
charname[15];
charaddress[25];
charcity[10];
intpostcode;
public:
Employee();
Employee(charn,chara,charc,intp);
~Employee();
voidchange_name();
voidchange_address();
voidchange_city();
voidchange_postcode();
voiddisplay();
};
#endif//Employee_H_INCLUDED
Employee.cpp
#include
#includeEmployee.h
usingnamespacestd;
Employee:
:
Employee(){}
Employee:
:
Employee(charn,chara,charc,intp)
{
name[0]=n;
name[1]='\0';
address[0]=a;
address[1]='\0';
city[0]=c;
.
精品文档
city[1]='\0';
postcode=p;
}
Employee:
:
~Employee(){}
voidEmployee:
:
change_name()
{
cout<<cin.getline(name,15,'\n');
}
voidEmployee:
:
change_address()
{
cout<<cin.getline(address,25,'\n');
}
voidEmployee:
:
change_city()
{
cout<<cin.getline(city,10,'\n');
}
voidEmployee:
:
change_postcode()
{
cout<<cin>>postcode;
}
voidEmployee:
:
display()
{
cout<<cout<<
ame:
<cout<<
cout<<cout<<}
intmain()
{
Employee
emp[5]={Employee(1,1,1,1),Employee(2,2,2,2),Employee(3,3,3,3),Employee(4,4,4,4),Employee(5,5,5,5)};
inti;
for(i=0;i<5;i++)
{
emp[i].display();
emp[i].change_name();
emp[i].change_address();
emp[i].change_city();
.
精品文档
emp[i].change_postcode();
cin.get();
}
for(i=0;i<5;i++)
{
cout<emp[i].display();
}
return0;
}
7.
#include
#include
usingnamespacestd;
//Date类
classDate
{
private:
intyear;
intmonth;
intday;
public:
Date();
Date(inty,intm,intd);
Date(Date&p);
~Date();
voidsetDate();
voidshowDate();
};
//People类,其中含Date类型的数据
classPeople
{
private:
charname[11];
charnumber[7];
charsex[3];
Datebirthday;
charid[16];
public:
People();
People(char*n,char*nu,char*s,Dateb,char*i);
People(People&p);
.
精品文档
~People();
voidsetName();
voidsetNumber();
voidsetSex();
voidsetId();
voidshowPeople();
};
//Date构造函数
Date:
:
Date(){}
Date:
:
Date(inty,intm,intd)
{
year=y;
month=m;
day=d;
}
Date:
:
Date(Date&p)
{
year=p.year;
month=p.month;
day=p.day;
}
//析构
inlineDate:
:
~Date(){}
//Date成员函数,设置出生年月日
voidDate:
:
setDate()
{
inty,m,d;
cout<;
cin>>y;
cout<;
cin>>m;
cout<;
cin>>d;
year=y;
month=m;
day=d;
}
//Date内联成员函数,输出年月日
inlinevoidDate:
:
showDate()
{
潣瑵?
?
物桴慤?
獩尠?
敹牡?
年?
洼湯桴?
月?
搼祡?
日<}
//People构造函数
People:
:
People(){};
.
精品文档
People:
:
People(char*n,char*nu,char*s,Dateb,char*i)
{
strcpy(name,n);
strcpy(number,nu);
strcpy(sex,s);
birthday=b;
strcpy(id,i);
}
People:
:
People(People&p)
{
strcpy(name,p.name);
strcpy(number,p.number);
birthday=p.birthday;
strcpy(id,p.id);
}
//People析构
inlinePeople:
:
~People(){}
//People成员函数,设置各类数据
voidPeople:
:
setName()
{
cout<;
cin.getline(name,11,'\n');
}
voidPeople:
:
setNumber()
{
cout<;
cin.getline(number,7,'\n');
}
voidPeople:
:
setSex()
{
cout<;
cin.getline(sex,3,'\n');
}
voidPeople:
:
setId()
{
cout<;
cin.getline(id,16,'\n');
}
//People内联成员函数,输出人员信息
inlinevoidPeople:
:
showPeople()
{
.
精品文档
cout<<cout<<cout<<cout<<}
intmain()
{
inti;
charspaceA;
//生成3个Date类型的对象
Datedate[3]={Date(0,0,0),Date(0,0,0),Date(0,0,0)};
//生成3个People类型的对象
People
person[3]={People(e[2],
//设置这3个对象的各类信息
for(i=0;i<3;i++)
{
person[i].setName();
person[i].setNumber();
person[i].setSex();
person[i].setId();
date[i].setDate();
spaceA=getchar();
}
//输出这3个对象的各类信息
for(i=0;i<3;i++)
{
person[i].showPeople();
date[i].showDate();
}
return0;
}
运行结果6.
1.
.
精品文档
2.
3.
4.
5
.
精品文档
.6.
7.
.
精品文档
7.心得体