单项选择题

下列关于函数模板的表述中,正确的是

A.函数模板是一个实例函数
B.使用函数模板定义的函数没有返回类型
C.函数模板的虚拟类型参数就是函数参数
D.通过使用不同的类型参数,可以从函数模板得到不同的实例函数
热门 试题

问答题
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中包含了类Imege~和主函数main的定义。一个Integers对象就是一个整数的集合,其中包含0个或多个可重复的整数。成员函数add的作用是将一个元素添加到集合中,成员函数remove的作用是从集合中删除指定的元素(如果集合中存在该元素),成员函数sort的作用是将集合中的整数按升序进行排序。请编写这个sort函数。此程序的正确输出结果应为:52824532752766315282453275276631528245327527663161952845327527663161952845327527663161942344556192728316675要求:补充编制的内容写在“//**********333**********”与“//**********666**********”之间。不得修改程序的其他部分。注意:相关文件包括:mmn.cpp、Integers.h。程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。//Integers.h#ifndefINTEGERS#defineINTEGERS#include<iostream>usingnamespacestd;constintMAXELEMENTS=100;//集合最多可拥有的元素个数classIntegers{intelem[MAXELEMENTS];//用于存放集合元素的数组intcounter;//用于记录集合中元素个数的计数器public:Integers():counter(O){}//创建一个空集合Integers(intdata[],intsize);//利用数组提供的数据创建一个整数集合voidadd(intelement);//添加一个元素到集合中voidremove(intelement);//删除集合中指定的元素intgetCount()const{returncounter;}//返回集合中元素的个数intgetElement(inti)const{returnelem[i];}//返回集合中指定的元素voidsort();//将集合中的整数按由小到大的次序进行排序voidshow()const;//显示集合中的全部元素};voidwriteToFile(constchar。path);#endif//main.cpp#include Integers.h #include<iomanip>Integers::Integers(intdata[],intsize):counter(0){for(inti=0;i<Size;i++)add(data[i]);}voidIntegers::add(intelement){if(counter<MAXELEMENTS)elem[counter++]=element;}voidIntegers::remove(intelement){intj;for(j=counter-1;j>=0;j--)if(elem[j]=element)break;for(inti=j;i<counter-1;i++)elem[i]=elem[i+1];counter--;}voidIntegers::sort(){//********333********//********666********}voidIntegers::show()const{for(inti=0;i<getCount();i++)cout<<setw(4)<<getElement(i);cout<<end1;}intmain(){intd[]={5,28,2,4,5,3,2,75,27,66,31);Integerss(d,11);s.show();s.add(6);s.show();s.add(19);s.show();s.Eemove(2);s.show();s.add(4);s.show();s.sort();s.show();writeToFile( );return0;}
问答题
请使用“答题”菜单或使用VC6打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motocar和bicycle作为基类,再派生出motocycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:801501001注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动“//**********found**********”。#include<iostream.h>classvehicle{private:intMaxSpeed;intWeight;public://**********found**********vehicle(intmaxspeed,intweight):________________~vehicle(){};intgetMaxSpeed(){returnMaxSpeed;}intgetWeight(){returnWeight;}};//**********found**********classbicycle:________publicvehicle{private:intHeight;public:bicycle(intmaxspeedlintweight,intheight):vehicle(maxspeed,weight),Height(height){}intgetHeight(){returnHeight;};};//**********found**********classmotorcar:________publicvehicle{private:intSeatNum;public:motorcar(intmaxspeed,intweight,intseatnum):vehicle(maxspeed,weight),SeatNum(seatnum){)intgetSeatNum(){returnSeatNum;};};//**********found**********classmotorCyCle:________{public:motorcycle(intmaxspeed,intweight,intheight):vehicle(maxspeed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}};voidmain(){motorcyclea(8.0,150,100);cout<<a.getMaxSpeed()<<end1;cout<<a.getWeight()<<end1;cout<<a.getHeight()<<end1;cout<<a.getSeatNum()<<end1;}