我用C++写的
源代码:
//方法一
/*
#include "stdafx.h"
#include <iostream>
using namespace std;
void lower_upper_and_upper_lower(){
char a[100];
int i;
cin>>a;
for (i = 0; a[i] != '\0'; i++)
if (a[i] >= 'a'&&a[i] <= 'z')
a[i] -= 32;
else if (a[i] >= 'A'&&a[i] <= 'Z')
a[i] += 32;
cout<<a<<endl;
}
void upper_lower(){
char a[100];
int i;
cin >>a;
for (i = 0; a[i] != '\0'; i++){
if (a[i] >= 'A'&&a[i] <= 'Z')
a[i] += 32;
else if (a[i] >= 'a'&&a[i] <= 'z')
a[i] += 0;
}
cout << a << endl;
}
void lower_upper(){
char a[100];
字符串函数title()是使字符串开头首字母大写 int i;
cin >> a;
for (i = 0; a[i] != '\0'; i++)
if (a[i] >= 'a'&&a[i] <= 'z')
a[i] -= 32;
else if (a[i] >= 'A'&&a[i] <= 'Z')
a[i] -= 0;
cout << a << endl;
}
int main(){
int a,b;
cout <<" *****************大小写转换说明********************* "<< endl;
cout << "1:字符串中的大写转小写and小学转大写" << endl;
cout << "2:字符串中的大写转小写" << endl;
cout << "3:字符串中的小学转大写" << endl;
cout <<" **************************************************** "<< endl;
cout << "请输入你的选择:";
cin >> a;
if (a==1)
{
lower_upper_and_upper_lower();
main();
}
if (a == 2)
{
upper_lower();
main();
}
if (a == 3)
{
lower_upper();
main();
}
cin >> b;
}
*/
// 方法二
#include "stdafx.h"
#include <iostream>
using namespace std;
void lower_upper_and_upper_lower(){
char a[100];
int i;
cin >> a;
for (i = 0; a[i] != '\0'; i++)
if (a[i] >= 'a'&&a[i] <= 'z')
a[i] = toupper(a[i]);
else if (a[i] >= 'A'&&a[i] <= 'Z')
a[i] = tolower(a[i]);
cout << a << endl;
}
void upper_lower(){
char a[100];
int i;
cin >> a;
for (i = 0; a[i] != '\0'; i++){
if (a[i] >= 'A'&&a[i] <= 'Z')
a[i] = tolower(a[i]);
else if (a[i] >= 'a'&&a[i] <= 'z')
a[i] += 0;
}
cout << a << endl;
}
void lower_upper(){
char a[100];
int i;
cin >> a;
for (i = 0; a[i] != '\0'; i++)
if (a[i] >= 'a'&&a[i] <= 'z')
a[i] = toupper(a[i]);
else if (a[i] >= 'A'&&a[i] <= 'Z');
a[i] -= 0;
cout << a << endl;
}
int main(){
int a, b;
cout << " *****************大小写转换说明********************* " << endl;
cout << "1:字符串中的大写转小写and小学转大写" << endl;
cout << "2:字符串中的大写转小写" << endl;
cout << "3:字符串中的小学转大写" << endl;
cout << " **************************************************** " << endl;
cout << "请输入你的选择:";
cin >> a;
if (a == 1)
{
lower_upper_and_upper_lower();
main();
}
if (a == 2)
{
upper_lower();
main();
}
if (a == 3)
{
lower_upper();
main();
}
cin >> b;
}
上面的代码是可以粘贴的
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论