沙锋
小水手

UID 30030
精华
0
积分 3
帖子 3
阅读权限 10
注册 2007-4-30 来自 广东
状态 离线
|
给大家一个c++标准编程格式
一个小程序"字符串处理"
//=====================================================
//编程将两个字符串连接成一个字符串,并将连接后的字符串按升序排列
//如字符串s1的值为"pear",字符串s2的值为"apple",将s1和s2连接后得到的字符串"pearapple",
//存入字符数组s3,排序后得到"aaeelpppr".要求排序用函数实现.
//===============================================================
#include < iostream >
using namespace std;
#include < string >
//==============================================================
class String
{
public:
void input_str();
void add_str();
void output_str();
void length_str();
void arr_str();
void cout_str();
private:
string str1;
string str2;
string str3;
int number;
};
//******************************************************************
void String::input_str()
{
cout << " Please input the two strings : ";
cin >> str1 >> str2;
}
//*******************************************************************
void String::add_str()
{
str3 = str1 + str2;
}
//********************************************************************
void String: utput_str()
{
cout << " The add of string is : " << str3 << endl;
}
//********************************************************************
void String::length_str()
{
number = str3.length()-1;
}
//********************************************************************
void String::arr_str()
{
int i, j;
char t;
for(j = 0; j<number; j++ )
for ( i = 0; i < number-j ; i++ )
if ( str3 > str3[i+1] )
{
t = str3;
str3[ i] = str3[i+1];
str3[ i+1]=t;
}
}
//******************************************************************
void String::cout_str()
{
cout<<"The sort of string is from small to big:";
cout << str3 << endl;
}
//*****************************************************************
int main()
{
String array;
array.input_str();
array.add_str();
array.output_str();
array.length_str();
array.arr_str();
array.cout_str();
return 0;
}
//****************************************************************
|  沙锋 |
|