设有如下通用过程: Public Function Fun(xStr As String)As String Dim tStr As String,strL As Integer tStr="" strL=Len(xStr) i=1 Do While i<=strL/2 tStr=tStr & Mid(xStr,i,1) & Mid(xStr,strL-i+1,1) i=i+1 Loop Fun=tStr End Function 在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按

题目

设有如下通用过程: Public Function Fun(xStr As String)As String Dim tStr As String,strL As Integer tStr="" strL=Len(xStr) i=1 Do While i<=strL/2 tStr=tStr & Mid(xStr,i,1) & Mid(xStr,strL-i+1,1) i=i+1 Loop Fun=tStr End Function 在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮。然后编写如下的事件过程: Private Sub Command1_Click() Dim S1 As String S1="abcdef" Text1.Text=UCase(Fun(S1)) End Sub 程序运行后,单击命令按钮,则Text1中显示的是______。

A.ABCDEF

B.abcdef

C.AFBECD

D.DEFABC


相似考题
更多“设有如下通用过程:Public Function Fun(xStr As String)As StringDim tStr As String,strL As In ”相关问题
  • 第1题:

    设有如下通用过程:

    Pubfic Function Fun(xStr As String)As String

    Dim tStr As String,strL As Integer

    tstr=“”

    strL=Len(xStr)

    i=1

    Do While i<=strL/2

    tStr=tStr&Mid(xStr,i,1)&Mid(xStr,strL-i+1,1)

    i=i+1

    Loop

    Fun=tStr

    EndFunction

    在窗体上画一个名称为Commandl的命令按钮。然后编写如下的事件过程:

    Private Sub Commandl_Click()

    Dim S1 As String

    S1=“abcdef”

    Print UCase(Fun(S1))

    End Sub

    程序运行后,单击命令按钮,输出结果是

    A.ABCDEF

    B.abedef

    C.AFBECD

    D.DEFABC


    正确答案:C
    解析:此题主要考核Mid函数、UCASE函数,MID返回文本字符串中从指定位置开始的特定数目的字符,其格式为:MID(text,start-num,hum-chars)。Text包含要提取字符的文本字符串。Start-num文本中要提取的第一个字符的位置。文本中第一个字符的start-num为1,以此类推。Num_chars指定希望MID从文本中返回字符的个数。UCASE函数则将小写字母转换成大写字母。

  • 第2题:

    设有下列通用过程: Public Function Fun(xStr As String)As String Dim tStr As String,strL As Integer tStr="" strL=Len(xStr) i=strL/2 DO While i<=StrL tStr=tStr&Mid(xStr,i+1,1) i=i+1 Loop Fun=tStr&tStr End Function 在窗体上画一个名称为Textl的文本框和一个名称为Command1的命令按钮。然后编写下列的事件过程: Private Sub Commandl Click( ) Dim S1 As String S1="ABCDEF" Text1.Text=LCase(Fun(S1)) End Sub 程序运行后,单击命令按钮,文本框中显示的是( )。

    A.ABCDEF

    B.abedef

    C.defdef

    D.defabc


    正确答案:C
    C。【解析】LCase函数用于将字符串中大写字母转化为小写字母,原本小写或非字母字符保持不变。Mid(字符串,起始位置[个数])函数用于从已有字符串中取出按指定位置开始的含指定个数字符的字符串。在本题源程序的Fun函数过程中,当第1次执行Do循环体后,变量tStr=Mid("ABCDEF",3+1,1)="D";当第2次执行D0循环体后,变量tStr="D"&Mid("ABCDEF",4+1,1)="DE";当第3次执行Do循环体后,变量tStr="DE"&Mid("ABCDEF",5+1,1)="DEF"。函数返回值为“DEFDEF”,故文本框中显示内容为“defdef”。

  • 第3题:

    设有下列通用过程:

    Public Function Fun(xStr As String)As String

    Dim tStr As String,strL As Integer

    tStr=""

    strL=Len(xStr)

    i=strL/2

    DO While i<=StrL

    tStr=tStr&Mid(xStr,i+1,1)

    i=i+1

    Loop

    Fun=tStr&tStr

    End Function

    在窗体上画一个名称为Textl的文本框和一个名称为Command1的命令按钮。然后编写下列的事件过程:

    Private Sub Commandl Click( )

    Dim S1 As String

    S1="ABCDEF"

    Text1.Text=LCase(Fun(S1))

    End Sub

    程序运行后,单击命令按钮,文本框中显示的是( )。

    A.ABCDEF

    B.abedef

    C.defdef

    D.defabc


    正确答案:C
    C。【解析】LCase函数用于将字符串中大写字母转化为小写字母,原本小写或非字母字符保持不变。Mid(字符串,起始位置[个数])函数用于从已有字符串中取出按指定位置开始的含指定个数字符的字符串。在本题源程序的Fun函数过程中,当第1次执行Do循环体后,变量tStr=Mid("ABCDEF",3+1,1)="D";当第2次执行D0循环体后,变量tStr="D"&Mid("ABCDEF",4+1,1)="DE";当第3次执行Do循环体后,变量tStr="DE"&Mid("ABCDEF",5+1,1)="DEF"。函数返回值为“DEFDEF”,故文本框中显示内容为“defdef”。

  • 第4题:

    设有如下通用过程:Public Function Fun (xStr As String) As String Dim tStr As String,strL As Integer tStr=-" " strL=Len(xStr) i=strL/2 Do Whilei<=strL tStr=tStr &id(xStr,i+1,1) i=i+1 Loop Fun=tStr & tStrEnd Function 在窗体上画—个名称为Text1的文本框和—个名称为Command1的命令按钮,然后编写如下的事件过程:Private Sub Command1_ Click() Dim S1 String S1="ABCDEF" Text1.Text=LCase(Fun(S1))End Sub 程序运行后,单击命令按钮,文本框中显示的是 ______。

    A.ABCDEF

    B.abcdef

    C.defdef

    D.defabc


    正确答案:C
    解析:Mid(字符串,p,n):从第p个字符开始,向后截取n个字符。p和n都是算术表达式。
    “&”:字符串连接运算符,将两个字符串按顺序连接起来。
    LCase(字符串):将字符串所有的字母都转换成小写字符。
    Len(字符串):返回字符串的长度。
    由LCase可知,最后结果为小写字符串,可排除选项A。当Fun过程用语句Fun(S1)调用后,S1的值“ABCDEF”被赋给xStr,执行第一次循环时Mid(xStr,i+1,1)相当 Mid(xStr,4,1),此时tStr=D,执行第二次循环时Mid(xStr,i+1,1)相当于Mid(xStr,5,1),此时tStr=DE,执行第三次循环时Mid(xStr,i+1,1)相当于Mid(xStr,6,1),此时tStr=DEF,执行第四次循环时Mid(xStr,i+1,1)相当于Mid(xStr,7,1),没有取到值,此时tStr=DEF,i的值为7,不满足循环条件,循环结束,Fun=tStr & tStr=DEFDEF,由此判断选项C正确。

  • 第5题:

    已知String类定义如下:

    class String

    {

    public:

    String(const char *str = NULL); // 通用构造函数

    String(const String &another); // 拷贝构造函数

    ~ String(); // 析构函数

    String & perater =(const String &rhs); // 赋值函数

    private:

    char *m_data; // 用于保存字符串

    };

    尝试写出类的成员函数实现。


    正确答案:

     

    String::String(const char *str)
    {
    if ( str == NULL ) //strlen在参数为NULL时会抛
    异常才会有这步判断
    {
    m_data = new char[1] ;
    m_data[0] = '\0' ;
    }
    else
    {
    m_data = new char[strlen(str) + 1];
    strcpy(m_data,str);
    }
    }
    String::String(const String &another)
    {
    m_data = new char[strlen(another.m_data) + 1];
    strcpy(m_data,other.m_data);
    }
    String& String::operator =(const String &rhs)
    {
    if ( this == &rhs)
    return *this ;
    delete []m_data; //删除原来的数据,新开一块内

    m_data = new char[strlen(rhs.m_data) + 1];
    strcpy(m_data,rhs.m_data);
    return *this ;
    }
    String::~String()
    {
    delete []m_data ;
    }