编写如下事件过程: Private Sub Form. Click() Dim Char As String,i As Integer Const ch$="#" msg$= "Enter a String:" char=InputBox$(msg$) n=Len(Char) For i=1 To n If Mid$(char,i,1)=ch$ Then Exit For End If Next i Print i - 1 End Sub 其中InputBox函数的功能是弹出一个输入对话框,按所给参数给出提示,等待用户输入,并返回输入的内容。程序运行后,单击窗体,如果在输入对话框内输入字符串“12ab$%*/#fg”,则窗体上输出
A.2
B.2
C.5
D.8
第1题:
在窗体上添加一个命令按钮Command1,然后编写如下事件过程: Private Sub Command1_Click() Dim m(10) As Integer, n(10) As Integer i = 3 For t = 1 To 5 m(t) = t n(i) = 2 * i + t Next t Print n(i); m(i) End Sub 窗体运行后,单击命令按钮,显示结果为()。
A.3 11
B.3 15
C.11 3
D.15 3
第2题:
下面的代码用于输出字符数组ch中每个字符出现的次数,应该填入的代码是()public static void main(String[] args) { char[] ch = { 'a', 'c', 'a', 'b', 'c', 'b' }; HashMap map = new HashMap(); for (int i = 0; i < ch.length; i++) { < 填入代码 > } System.out.println(map); }
A.if (map.contains(ch[i])) { map.put(ch[i], map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }
B.if (map.contains(ch[i])) { map.put(ch[i], (Integer) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }
C.if (map.containsKey(ch[i])) { map.put(ch[i], (int) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }
D.if (map.containsKey(ch[i])) { map.put(ch[i], (Integer) map.get(ch[i]) + 1); } else { map.put(ch[i], 1); }
第3题:
编写类 String 的构造函数、析构函数和赋值函数
已知类 String的原型为:
class String
{
public:
String(const char *str = NULL); // 普通构造函数
String(const String &other); // 拷贝构造函数
~ String(void); // 析构函数
String & perate =(const String &other); // 赋值函数
private:
char *m_data; // 用于保存字符串
};
请编写 String的上述 4 个函数。
第4题:
已知类 String 的原型为
class string
{
public:
string(const char *str=null);//普通构造函数
string(const string &other);//拷贝构造函数
---string(void);
string &operate=(const string &other);//赋值函数
private:
char * m-data;//用于保存字符串
};
请编写 string 的上述4 个函数
第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 ;
}
第6题:
有如下程序:
#include<iostream>
using namespace std;
class Book{
public:
Book(char*t=””){strcpy(title,t);}
private:
char title[40];
};
class Novel:public Book{
public:
Novel(char *t=””):Book(t){}
char*Category()const{return”文学”;)
};
int main(){
Book *pb;
pb=new Novel();
cout<<pb->Category();
return 0;
}
若程序运行时输出结果是“文学”,则划线处缺失的语句是
A.char*Category();
B.char*Category()const;
C.virtual char*Category()const;
D.virtual char*Category()const=0;
第7题:
有如下程序: #inClude<iostream> using namespaCe std; Class Book{ publiC: Book(Char*t=””){strCpy(title,t);} private: Char titlel40]; }; Class Novel:publiC Book{ publiC: Novel(Char*t=””):Book(t){} Char*Category( )Const{return”文学”;} }; int main( ){ Book * pb; pb=new Novel( ); Cout<<pb→Category( ); delete pb; return 0; } 若程序运行时输出结果是“文学”,则横线处缺失的语句是( )。
A.Char*Category( );
B.Char*Category( )Const;
C.virtual Char*Category( )Const;
D.virtual Char*Category( )Const=0;
第8题:
如果存在如下过程:
Private Function Fun(a() As Integer)
Dim First As Integer, Last As Integer, i As Integer
First=LBound(a)
Last=UBound(a)
Max=a(First)
For i=First To Last
If a(i) > Max Then Max=a(i)
Next
Fun=Max
End Function
在窗体上添加一个命令按钮,然后编写如下事件过程:
Private Sub Command1_Click()
ReDim m(1 To 4) As Integer
m(1)=20: m(2)=30: m(3)=50: m(4)=100
c=Fun(m)
Print c
End Sub
单击命令按钮,其输出结果为 【 】。
第9题:
如果存在如下过程:
Private Function FMax(a() As Integer)
Dim First As Integer, Last As Integer, i As Integer
First=LBound(A)
Last=UBound(A)
Max=a(First)
For i=First To Last
If a(i) > Max Then Max=a(i)
Next i
FMax=Max
End Function
在窗体上添加一个命令按钮,然后编写如下事件过程:
Private Sub Command1_Click()
ReDim m(1 To 4) As Integer
m(1) =20: m(2) =30: m(3) =50: m(4) =100
c=FMax(m)
Print c
End Sub
单击命令按钮,其输出结果为 【12】 。