发布网友 发布时间:2022-05-08 16:47
共1个回答
热心网友 时间:2024-01-25 23:09
#include <iostream>#include <cstring> using namespace std;class STRING{ char str1[60]; char str2[40]; char str3[100];public: STRING(char *s1,char *s2); void process(); void print();}; STRING::STRING(char *s1,char *s2){ strcpy(str1,s1); strcpy(str2,s2);} void STRING::process(){ int count=0; int i,j; for( i=0;str1[i]!='\0'&&str2[i]!='\0';i++) { str3[count++]=str1[i]; str3[count++]=str2[i]; } for(j=i;str2[j]!='\0';j++) str3[count++]=str2[j]; for(j=i;str1[j]!='\0';j++) str3[count++]=str1[j]; str3[count]='\0';} void STRING::print(){ cout<<"str3="<<str3<<endl;}int main(){ char *s1="abcde"; char *s2="ABCDEFG"; STRING test(s1,s2); test.process(); test.print(); return 0;}