Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- void getStr(string &str , char);
- void Print_length(string &str, char );
- void Print_Char_Str(string a);
- void Comp_length (string a, string b);
- void Swap_Str( string &a, string &b);
- int main(void)
- {
- string a;
- string b;
- getStr(a,'a');
- getStr(b,'b');
- Print_length(a,'a');
- Print_length(b,'b');
- Comp_length (a,b);
- cout << endl << a.compare(b) << endl;
- if ( a > b)
- {
- Swap_Str(a,b);
- cout << "DO a > b nen hoan vi 2 chuoi a b" << endl;
- cout << "chuoi a: "<< a << endl;
- cout << "chuoi b: " << b << endl;
- }
- string c = a;
- c = c+b;
- cout << "chuoi c: " << c;
- string d = c.string( a.length(), a.length()+b.length());
- return 0;
- }
- void getStr(string &str, char a)
- {
- cout << "Nhap Chuoi " << a << ": ";
- getline(cin, str);
- }
- void Print_length(string &str, char a)
- {
- int k = str.length();
- cout << endl << "Do dai chuoi " << a <<": " << k;
- }
- void Print_Char_Str(string a)
- {
- int l = a.length();
- cout << endl;
- for ( int i = 0; i < l; i++)
- cout << a[i] << ".";
- cout << endl;
- }
- void Comp_length(string a, string b)
- {
- int l1 = a.length();
- int l2 = b.length();
- if ( l1 > l2)
- {
- Print_Char_Str(a);
- return;
- }
- if ( l1 == l2)
- {
- Print_Char_Str(a);
- Print_Char_Str(b);
- return;
- }
- if ( l1 < l2)
- {
- Print_Char_Str(b);
- return;
- }
- }
- void Swap_Str( string &a, string &b)
- {
- string Temp = a;
- a = b;
- b = Temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement