}
}
voidinput()
{
inti,j;
cout<<"Pleaseinputyour3*3matrix:
"<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<<"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:
"<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<<"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;
}
3.lab6_4.cpp
#include
#include
usingnamespacestd;
chara[20]={"/0"},b[20]={"/0"};
intmain()
{
cout<<"Inputthefirststring:
"<cin.getline(a,20,'\n');
cout<<"Inputthesecondstring:
"<cin.getline(b,20,'\n');
strings1=a;
strings2=b;
strings3=s1+s2;
cout<return0;
}
4.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
#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()
{
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