写出下列程序运行结果(二)

来源:百度知道 编辑:UC知道 时间:2024/07/07 19:22:11
5. # include <iostream >
using namespace std;
void main()
{
char a[]="welcome to c++";
int i1=0,i2=0,i=0;
while (a[i]) {
if (a[i]=='c') i1++;
if (a[i]=='o') i2++;
i++;
}
cout <<i1<<' '<<i2<<endl;
}
6. #include<iostream >
class Sample
{
char c1,c2;
public:
Sample(char a){c2=(c1=a)-32;}
void disp()
{
cout<<c1<<"转换为"<<c2<<endl;
}
};
void main()
{Sample a('a'),b('b');
a.disp();
b.disp();
}

7. # include <iostream >
using namespace std;
void LE(int * a,int * b) {
int x=*a;
*a=*b; *b=x;
cout <<*a<<”,”<<*b<<endl;
}
void main()
{
int x=5,y=10;

5. 输出:2 2

6. 输出:a转换为A
b转换为B

7. 输出:10,5
10,5
8.你程序运行不过去,我改了一下
# include <iostream >
# include <string >
using namespace std;
void main()
{
string s="this is a book";
for (int i=0; s[i]; i++)
if (s[i]>='a' && s[i]<='z')
s[i]=s[i]-'a'+'A';
cout <<s<<endl;
}

输出:THIS IS A BOOK