问答题

综合应用 请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中包含主程序文件main.cpp和用户定义的头文件Array.h,整个程序包含有XArray类的定义和main主函数的定义。请在主程序文件中写出成员函数XArray::sort()的定义,经补充后运行程序,得到的输出结果为: 3 6 5 4 16 10 20 15 3 4 5 6 10 15 16 20 注意:只能在"//********333********"和"//********666********"之间填入若干语句,不得改动程序中的其他部分。 //Array.h #include #include using namespace std; class XArray { //数组类 int *a; int size; public: XArray(int b[], int len): size(len) //构造函数 { if(len<1 || len>100) {cout<<"参数值不当!\n"; exit(1);} a=new int[size]; for(int i=0; i
【参考答案】

int temp; for (int i = 0; i < size; ++i) { for ......

(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)

热门 试题

问答题
简单应用请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程包含程序文件main.cpp,其中有类Animal( 动物 )、类Dog( 狗 )、类Cat( 猫 )的定义和主函数main的定义。请在程序中 ****found**** 下的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:Dog named Lucky speaks WoofCat named Daisy speaks Miaow注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不能删除或移动 ****found**** 。#include using namespace std;class Animal{public:Animal(char* str= Animal ){ **********found********** name = new ___________________;strcpy(name,str);}virtual ~Animal() { delete[] name; }char* getName() const { return name; }virtual char* getType() const { return Animal ; }virtual char* getVoice() const { return Voice ; }private:char* name;};class Dog : public Animal {public:Dog(char* str) : Animal(str) { }char* getType() const { return Dog ; } **********found**********char* getVoice() const { ___________________ }};class Cat : public Animal {public: **********found**********Cat(char* str) : ______________ { }char* getType() const { return Cat ; }char* getVoice() const { return Miaow ; }};void type(Animal& a) {cout<<a.getType()<< named <<a.getName();} **********found**********void speak(___________________){cout<< speaks <<a.getVoice();}int main(){Dog d( Lucky );type(d);speak(d);cout<<endl;Cat c( Daisy );type(c);speak(c);cout<<endl;return 0;}