}
}
voidinput()
{
inti,j;
cout<<"Pleaseinputyour3*3matrix:
"<for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
}
}
intmain()
{
input();
showTrans();
return0;
}
2」ab6_2.cpp
#include
usingnamespacestd;
int*p[9];
voidshowTrans()
{
inti,j;
cout<<"Thetranspositionmatrixis:
"<for(i=0;i<3;i++)
{
for(j=i;j<9;j=j+3)
{
cout<<*p[j];
cout<<"";
}
cout<}
}
voidinput()
{
inti,n;
cout<<"Pleaseinputyour3*3matrix:
"<{
cin»n;
p[i]=newint(n);
}
}
intmain()
{
input();
showTrans();
inti;
for(i=0;i<9;i++)
{
deletep[i];
}
return0;
}
3」ab6_3.cpp
#include
//不使用系统自带函数strcpy
usingnamespacestd;
chara[20]={"/0"},b[20]={"/0"},c[45]={"/0"};
intmain()
{
inti,j,k;
cout<<"Inputthefirststring:
"<cin.getline(a,20,'\n');
cout<<"Inputthesecondstring:
"<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<<"lnputthefirststring:
"<cout<<"lnputthesecondstring:
"<strings1=a;
strings2=b;
strings3=s1+s2;
cout<return0;
}
5.Employee.h
#ifndefEmployee』」NCLUDED
#defineEmployee_H」NCLUDED
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」NCLUDED
Employee.cpp
#include
#include"Employee.h"
usingnamespacestd;
Employee:
:
Employee(){}
Employee:
:
Employee(charn,chara,charc,intp){
name[O]=n;
name[1]='\0:
address[O]=a;
address[1]='\0:
city[O]=c;
city[1]='\0:
postcode=p;
}
Employee:
:
~Employee(){}
voidEmployee:
:
change_name()
{
cout<<"Pleaseinputyourchangedname:
"<}
voidEmployee:
:
change_address()
{
cout<<"Pleaseinputyourchangedaddress:
"<}
voidEmployee:
:
change_city()
{
cout<<"Pleaseinputyourchangedcity:
"<cin.getline(city,10,'\n');
}
voidEmployee:
:
change_postcode()
{
cout<<"Pleaseinputyourchangedpostcode:
"<>postcode;
}
voidEmployee:
:
display()
{
cout<<"Yourinformationshowsasfollow:
"<"<"<
cout<<"city:
"<"<}
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」NCLUDED
#defineEmployee_H」NCLUDED
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」NCLUDED
Employee.cpp
#include
#include"Employee.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<<"Pleaseinputyourchangedname:
"<cin.getline(name,15,'\n');
}
voidEmployee:
:
change_address()
{
cout<<"Pleaseinputyourchangedaddress:
"<cin.getline(address,25,'\n');
}
voidEmployee:
:
change_city()
{
cout<<"Pleaseinputyourchangedcity:
"<cin.getline(city,10,'\n');
}
voidEmployee:
:
change_postcode()
{
cout<<"Pleaseinputyourchangedpostcode:
"<cin>>postcode;
}
voidEmployee:
:
display()
{
cout<<"Yourinformationshowsasfollow:
"<cout<<"name:
"<cout<<"address:
"<
cout<<"city:
"<cout<<"postcode:
"<}
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<<"Theemp"<
}
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<<"lnputtheyear:
";
cin»y;
cout<<"Inputthemonth:
";
cin»m;
cout<<"Inputtheday:
";
cin>>d;
year=y;
month=m;
day=d;
}
//Date内联成员函数,输出年月日
inlinevoidDate:
:
showDate()
{
cout<<"Birthdayis"<}
//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<<"Pleaseinputtheperson'sname:
";
cin.getline(name,11,'\n');
}
voidPeople:
:
setNumber()
{
cout<<"Inputnumber:
";
cin.getline(number,7,'\n');
}
voidPeople:
:
setSex()
{
cout<<"Inputsex:
";
cin.getline(sex,3,'\n');
}
voidPeople:
:
setId()
{
cout<<"Inputid:
";
cin.getline(id,16,'\n');
}
//People内联成员函数,输出人员信息
inlinevoidPeople:
:
showPeople()
{
cout<<"Name:
"<cout<<"Number:
"<cout<<"Sex:
"<cout<<"ID:
"<}
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("0","0","0",date[0],"0"),People("0","0","0",date[1],"0"),People("0","0","0",date[2],"0")};
//设置这3个对象的各类信息
for(i=0;i<3;i++)
{
person[i].setName();
person[i].setNumber();
person[i].setSex();
person[i].setld();
date[i].setDate();spaceA=getchar();
}
//输出这3个对象的各类信息
for(i=0;i<3;i++)
{
person[i].showPeople();
date[i].showDate();
}
return0;
}
6.运行结果
1.
Pleaseinputyom*3*3matrix:
123
456
789
Thetranspositionnatrixis:
147
258
369
2.
Pleaseinputyour3*3matrix:
123
456
789
Thetpan&positionmatrixis:
147
25K
36?
ProcessretuiTied0(0x0》executiontime:
3.
Inputthefirststring:
^bcl23456
Inputthesecondstrinsr-defgh789
kbcl23456def^h789
Processf台turned0<0x0>executiontime:
12.967sPressanykeytocontinue・
Votirinfopmationshousasname:
0
Vouirin£ornationshousfollau:
nane:
lizhibo
address=shisheCl75
city:
shenyansfpostcode:
1234567
Processreturned