#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace Std;
Class STRING
{
Char *str1;
Char *str2;
Public
STRING (char* s1,char* S2)
{
Str1=new Char[strlen (S1)];
Str2=new Char[strlen (S2)];
strcpy (STR1,S1);
strcpy (STR2,S2);
}
void Insertinorder ();
void process ();
void print ()
{
cout<<str1<<endl;
}
};
void STRING::p rocess ()
{
int len1,len2,count=1;
Char str[80];
int i,j=0,k=0;
Len1=strlen (STR1);
Len2=strlen (STR2);
int n=len2/len1;
for (i=0;i<len1+len2;i++)
{
if (count% (n+1) ==0)
{
Str[i]=str1[j++];
count++;
}else{
Str[i]=str2[k++];
count++;
}
}
str[i]= ' + ';
cout<<str<<endl;
strcpy (STR1,STR);
}
void String::insertinorder ()
{
char temp;
int i,j,k;
int Len1=strlen (STR1);
int Len2=strlen (STR2);
for (i=0;i<len2-1;i++)
{
K=i;
for (j=i+1;j<len2;j++)
if (Str2[k]<str2[j])
{
K=j;
Temp=str2[i];
STR2[I]=STR2[K];
Str2[k]=temp;
}
}
cout<<str2<<endl;
for (i=0;i<len1;i++)
{
for (j=len2-1+i;j>=0;j--)
{
if (Str1[i]>str2[j])
STR2[J+1]=STR2[J];
Else
Break
}
Str2[j+1]=str1[i];
}
cout<<str2<<endl;
}
int main (int argc, char *argv[])
{
STRING Test ("ABCD", "ABCDEFG");
Test. Insertinorder ();
Test.process ();
Test.print ();
System ("PAUSE");
return exit_success;
}
Rewrite requirements 2 and 3 to separate run that is commented out overwrite Insertinorder () to test the overwrite requirements 2 otherwise an error occurs because this is directly modified on STR1 and STR2
C + + Programming Practice Guide 1.14 string cross-insert rewrite requirements implementation