I wrote one, I don’t know if it will work. Please point out if there is anything wrong. If you want the format, please add me and I will send it to you
School of Computer Science, Sichuan University, Software College
Lab Report
Student Number: Name: Major: Computer Science and Technology Class: 5 Week 13
Course Name c/C++ Experiment Class 2
Experimental project Copying and appending strings Experiment time 08.5.16
Experiment purpose 1. Master the basic operations of strings and understand the data structure
Experimental environment VC 6.0
Experimental content (algorithms, procedures, steps and methods) First calculate the number of characters in S1 and S2, Allocate space for S3, use existing library functions to copy S1 to S3 first, and then append S2 to S3. When the display is completed, remember to reclaim the space and deal with the aftermath.
The source code is as follows:
#include
#include
using namespace std;
p>int main()
{
char *s1="abcdef";
char *s2="123456f";
int n=strlen(s1)+strlen(s2);//Calculate the total length n of s1 and s2
char *s3=new char[n+1]; //Definition S3 and allocate space size n
strcpy(s3,s1); //Copy s1 to s3
strcat(s3,s2); //Append s2 to s3 Behind
cout<<"s3="< delete []s3; //Recover space s3=NULL; / /Point the pointer to null return 0; } (continued) Experimental content (algorithm, program, steps and Method) The structure is a sequential storage structure, algorithm sequential linking method Data recording and calculation data include: string S1, S2; and an unknown character String S3 Just calculate the sum of the lengths of the first two strings Conclusion (Result) Character arrays can be used to store character data sequentially, and can Processing data; Algorithm complexity O(n+m); neutral Summary Character arrays can bring a good storage structure and are easy to operate, but the algorithm is not very good , can only traverse the array sequentially, so the complexity is not very small Instructor’s comment Score evaluation: Instructor’s signature: