简答题:说明以下类Words的功能,并给出程序执行结果。#include<iostream.h>#include<string.

  • 题目分类:C++
  • 题目类型:简答题
  • 查看权限:VIP
题目内容:
说明以下类Words的功能,并给出程序执行结果。
#include<iostream.h>
#include<string.h>
class Words
{
char *str;
public:
Words(char *s)
{
str=new char[strlen(s)+1];
strcpy(str,s);
}
void disp(){cout<<str<<endl;}
char operator[](int i)
{
if(str[i]>=’A’&& str[i]<='Z') // 大写字母
return char(str[i]+32);
else if(str[i]>='a'&&str[i]<='z') // 4'写字母
return char(str[i]-32);
else // 其他字符
return str[i];
}
}
void main()
{
int i;
char *s=”Hello”;
Words word(s);
word.disp();
for(i=0;i<strlen(s);i++)
cout<<word[i];
cout<<endl:
}
参考答案:
答案解析:

Questions are based on the following passage.According to a

Questions are based on the following passage.According to a paper to be publis

查看答案

听材料,回答下列问题:

听材料,回答下列问题:A.It is a very popular sport on TV. B.It is part of people's daily li

查看答案

这部“感觉敏锐、大胆放言、深度体验、深情呐喊”的稿子很对刊物的路子,阎纲______。但他毕竟是老编辑,比作者_____

这部“感觉敏锐、大胆放言、深度体验、深情呐喊”的稿子很对刊物的路子,阎纲______。但他毕竟是老编辑,比作者______,深知稿子“有胆有识有歧见,凛然正气也

查看答案

要求:将课堂实验中的display函数不放在time类中,而作为类外的普通函数,然后分别在time和date类中声明di

要求:将课堂实验中的display函数不放在time类中,而作为类外的普通函数,然后分别在time和date类中声明display函数为友元函数,在主函数中调

查看答案

常成员指的是类体内使用const关键字说明的常数据成员和常成员函数。

常成员指的是类体内使用const关键字说明的常数据成员和常成员函数。

查看答案