know yourselves. information, computer, 7 wonders, various.

Sunday, November 12, 2017

C++ programming language part: 41 Standard String-Handling function


Standard String-Handling function

strcpy()

The strcpy() function is used to copy the content of second string to first string. second string must be a pointer to a null-terminated string. The strcpu() function returns a pointer to the end of first string.

Program 30
{
              char a1[10],a2[10];
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              cout<
              }

strcat()

The strcat() function work the same as the strcpy() function except that the characters from the second string are copied onto the end of the first string. 




Program 31
         {               char a1[10],a2[10];
              char x[20];
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              //x=strcat(a1,a2);
              cout<
               //cout<
             
Note:Mind it that  the second string would be the same.You can do also cout<

Exercise: Make some program by using strcat(a1,"Nova") or (strcpy(a1, "Hello")

strcmp()
The strcmp() function compares two string and returnes an integer value, what is the ASCII value.

Program 32
           { char a1[10],a2[10];
              int x;
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              x=strcmp(a1,a2);
              cout<
strlen()

This function returns the number of characters in the string passed to it. The length does not include the NULL character.

Program 33
         {   char a1[10],a2[10];
              int len1;
              int len2;
              int sum;
              cout<<"Type a string "<
              cin>>a1;
              cout<<"Type another string "<
              cin>>a2;
              len1=strlen(a1);
              len2=strlen(a2);
              sum=len1+len2;
              char *p;
              p=a1+len1-2;  // last two letters   
             cout<<"The length of two string is "<
            cout<< "The last two letters of furst string is "<

Note: The file string.h should be included as a header file

Exercise: 1. Write a program to compare two stringusing string handle

                2. Write a program to marge two stringusing string handle


Part- 86 assign the content of twostring



জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯


C++ programming language part: 42 String Array


String Array

Recall that two-dimensional array  is really a one-dimensional array whose component themselvs are one -dimensional array. When those component arrays are string, we have an array of string called String array. the usual way to declaration is char name[4][20]

Program 33_ext
                      {            char *name[]={ "Mousumi Akther",
                                 "Raj Ashraf",
                                 "Goerge Michel"
                                };
                        cout<<"The names are"<
                        for(int i=1;i<3 correct="" error="" i="" if="" misspelled="" nbsp="" o:p="" some="" the="">
                        cout<<"\t" <

Exercise: 1. Write and test the function that returns the plural from of the singular English word passed to it.

Hints: Make a function with  suppose {int len=strlen(s);  char* p=s+len-1; char* q=s+len-2 and if..else ladder    

            and make a Boolean function (isvowel) to check the letter is a vowel one. &  Try.  






জ্ঞানকোষ প্রকাশনী
৩৮/২-ক, বাংলাবাজার (২য় তলা), ঢাকা।
       ফোনঃ ৭১১৮৪৪৩, ৮১১২৪৪১, ৮৬২৩২৫১.         
                                                     
কলকাতায় পরিবেশক/প্রাপ্তিস্থান
রিতা ইন্টারন্যাশনাল
৩৬, পি.এন. ব্যানার্জি রোড, কলকাতা
ফোনঃ ২৫১৩৮৩৫৯, ৯৮৩০৪৩৯৬৭৯, +৯১৯৮৩০৪৩৯৬৭৯