问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。请完成函数fun(char*data),此函数的功能是,找出字符串数组中最小的ASCII值,如果有相同变量,则输出最后一个所在的位置;如果字符串为空,则返回-1;或者不存在时也返回-1。
注意:请勿改动主函数main与其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。计算数字如果第一个字母最小,则返回0。依次增加。
#include
int fun(char*data)
{
}
void main()
{
char str[1024];
cout<<"请输入一行英文字符串:\n";
cin.getline(str,1024);
cout<<”最小的字母出现在距离头部”<
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,该工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句有错误。请改正这些错误,使程序的输出结果为:1 2 3 4 5 6 7 8 9 10注意:只能修改注释“//ERROR****found****”的下一行语句,不要改动程序中的其他内容。//projl.cpp#include<iostream>using namespace std;class MyClass {public: MyClass(int len) { array=new int[len]; arraySize=len; for(int i=0;i<arraySize;i++)array[i]=i+1;}~MyClass(){//ERROR**********found********** delete array[i];}void Print()const{for(int i=0;i<arraySize;i++)//ERROR**********found********** cin<<array[i]<<”; cout<<endl;}private: int*array; int arraySize;},int main(){//ERROR********** found**********MyClass obj;obj.Print();return 0;}
问答题用VC6打开考生文件夹下的源程序文件modi3.cpp,其中定义了多个类,但类不能达到输出要求,按照定义的输出修改函数,使得输出如下:
TestClass3
TestClass2
TestClass1
其中定义的类并不完整,按照要求完成下列操作,将类的定义补充完整。
(1)类TestClass2公共继承于TestClassI,请在注释∥********1********后添加适当的语句。
(2)print函数为虚函数,请在注释∥********2********后添加适当的语句。
(3)修改语句,使得P指定对象obj3,请在注释∥********3********后添加适当的语句。
(4)修改语句,利用P调用print()函数,完成输出信息,注释∥********4********后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
#include
using namespace std;
class TestClassl
{
public:
void print(){
cout<<“TestClasSl”<
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。其中有向量基类VectorBase、向量类Vector和零向量类ZeroVector的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序正确输出结果应为:(1.2.3.4,5)(0,0,0,0,0,0)注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#include<iostream>usingnamespacestd;classVectorBase{//向量基类,一个抽象类intlen;public:VectorBase(intlen):fen(len){}intlength()const{returnlen;}//向量长度,即向量中元素的个数virtualdoublegetElement(inti)const=0;//取第i个元素的值virtualdoublesum()const=0;//求所有元素的和voidshow()const{//显示向量中所有元素cout<<"(";for(inti=0,i<length()-1;i++)cout<<getElement(i)<<",";//**********found**********cout<<________<<")"<<end1;//显示最后一个元素}};classVector:publicVectorBase{//向量类double*val;public:Vector(intlen,doublev[]=NULL):VectorBase(len){val=newdouble[len];for(inti=0;i<len;i++)val[i]=(v==NULL?0.0:v[i]),}//**********found**********~Vector(){________;}doublegetElement(intindex)const{returnval[index];}doublesum()const{doubles=0.0;//**********found**********for(inti=0;i<length();i++)________;returns;}};classZeroVector:publicVectorBase{//零向量类public:ZeroVector(intlen):VectorBase(len){}//**********found**********doublegetElement(intindex)const{________;}doublesum()const{return0.0;}};intmain(){VeCtorBaSe*v;doubled[]={1,2,3,4,5};V=newVector(5,d);v->show();deletev;v=newZeroVector(6);v->show();deleteV;return0,}
问答题请使用VC6或使用【答题】菜单打开
proj3下的工程proj3,其中声明IntSet是一个用于表示正整数集合的类。IntSet的成员函数Intersection的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在main函数中给出了一组测试数据,此时程序的输出应该是:
求交集前:
1 2 3 5 8 10
2 8 9 11 30 56 67
求交集后:
1 2 3 5 8 10
2 8 9 11 30 56 67
2 8
要求:
补充编制的内容写在“// *******333*******”与“// *******666*******”之间,不得修改程序的其他部分。
注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。
//Intset.h
#include <iostream>
using namespace std;
const int Max=100;
class IntSet
{
public:
IntSet()
//构造一个空集合
{
end = -1;
}
IntSet (int a[], int size) //构造一个包含数组a中size个元素的集合
{
if (size >= Max)
end = Max - 1;
else
end = size - 1;
for (int i = 0; i <= end; i ++)
element[i] = a[i];
}
bool IsMemberOf (int a)
//判断a是否为集合中的一个元素
{
for (int i = 0; i <= end; i ++)
if (element[i] == a)
return true;
return false;
}
int GetEnd() {return end;}
//返回最后一个元素的下标
int GetElement (int i) {return element[i];}
//返回下标为i的元素
IntSet Intersection (IntSet
//求当前集合与集合set的交
void Print ()
//输出集合中的所有元素
{
for(int i=0;i<=end;i++)
if((i+1)% 20==0)
cout << element[i] << endl;
else
cout << element[i] << "";
cout << endl;
}
private:
int element[Max];
int end;
};
void writeToFile (const char *);
//main.cpp
#include "IntSet.h"
IntSet IntSet::Intersection(IntSet
// *******333*******
// *******666*******
return IntSet(a,size);
}
int main()
{
int a[] = {1,2,3,5,8,10};
int b[] = {2,8,9,11,30,56,67};
IntSet set1 (a, 6), set2 (b, 7), set3;
cout << "求交集前:" << endl;
set1.Print();
set2.Print();
set3.Print();
set3 = set1.Intersection (set2);
cout << endl << "求交集后:" << endl;
set1.Print();
set2.Print();
set3.Print();
writeToFile (" ");
return 0;
}
问答题请编写一个函数void fun(int a [],int n),其中a为数组,n为数组a的长度。函数fun()的功能是冒泡排序法将数组a元素按从小到大的顺序排列,实现数组a的升序排列。 注意:部分源程序已存在文件PROC12.cpp中。 请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。 文件PROC12.cpp的内容如下: //PROC12. cpp #include <iostream> using namespace std; #define MAX 100 void fun(int a[],int n); int main () int a[MAX],n,i; cout<<"Please enter the array size n:/n"; do cin>>n; if (n>100) cout<<"array size flowover! ReEnter a number(0-100)/n"; while (n>100); cout<<"Enter the array data:/n"; for (i=0; i<n; i++) cin>>a [ii; fun(a[],n); for (i=0; i<n; i++) cout<<a [i] <<" "; cout<<end1; return 0; void fun(int a[ ],int n) // * * * * * * * *
判断题一维字符数组就是字符串。
判断题一维数组属于构造数据类型。
判断题函数的默认参数没有次序要求,可以随意定义。
判断题用初值表给数组赋初值时,初值表中数据项的个数可以多于数组元素的个数。
判断题带有返回值的函数只能有一个返回值。
判断题函数可以返回数组类型的返回值。
判断题一个数组的数组名与指向该数组的指针是一样的。
判断题用下标表示数组和用指针表示数组对程序计算速度没有什么影响。
选择题将E-R图转换到关系模式时,实体与实体间的联系可以表示成
选择题派生类对象对其基类中的什么成员是可访问的?
选择题执行下列语句段后, 输出字符*的个数是
for(int i=50; i>1; i-=2)count< *;
选择题下列有关类继承的叙述中,错误的是
选择题有如下程序:
#include
usingnamespacestd;
classCon
charID;
public:
Con():ID(A){cout1;}
Con(charID):ID(ID){eout2;}
Con(Conc):ID(c
选择题下列语句中错误的是