算法的计算量的大小称为计算的【 】。
请打开考生文件夹下的解决方案文件proj2,该工程中含有一个源程序文件proj2.cpp,其中定义了CharShape类、Triangle类和Rectangle类。 CharShape是一个抽象基类,它表示由字符组成的图形(简称字符图形),纯虚函数Show用于显示不同字符图形的相同操作接口。Triangle和Rectangle是CharShape的派生类,它们分别用于表示字符三角形和字符矩形,并且都定义了成员函数Show,用于实现各自的显示操作。程序的正确输出结果应为: * *** ***** ******* ######## ######## ######## 请阅读程序,分析输出结果,然后根据以下要求在横线处填写适当的代码并删除横线。 (1)将Triangle类的成员函数Show补充完整,使字符三角形的显示符合输出结果。 (2)将Rectangle类的成员函数Show补充完整,使字符矩形的显示符合输出结果。 (3)为类外函数fun添加合适的形参。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。//proj2.cpp#includeiostreamusing namespace std;class CharShape{public: CharShape(char ch):ch(ch){}; virtual void Show()=0;protected: char ch;//组成图形的字符};class Triangle:public Char-Shape{public: Triangle(char ch,int r):CharShape(ch), rows(r){} void Show();private: int rows;//行数};class Rectangle:public Char-Shape{public: Rectangle(char ch,int r,int c):CharShape(ch), rows(r), cols(c){) void Show();private: int rows , cols;//行数和列数};void Triangle::Show()//输出字符组成的三角形{ for(int i=1;i= rows ; i++) {//********found********for(int j=1 ; j=___________;j++) cout ch; coutendl; }}void Rectangle::Show()//输出字符组成的矩形{//********found******** for(int i=1;i=___________;i++){//********found******** for(int j =1;j =___________;j++) cout ch; coutendl; }}//********found******** 为fun函数添加形参void fun(___________){cs.Show(); }int main(){ Triangle tri('*',4); Rectangle rect('#',3,8); fun(tri); fun(rect); return 0;}
使用VC6打开考生文件夹下的源程序文件modi3.cpp,要求编写一个CMyShape类,含有求面积求周长等纯虚函数。然后编写一个CMyRectangle类和CMyCircle类继承CMyShape,并实现求面积、求周长的两个函数。在main()函数中测试得到下面的结果: 在CMyShape类构函数造内 在CMyCirele类构造函数内 在CMyShape类构造函数内 在CMyRectangle类构造函数内 myCircle:Area=314.159 Girth=62.8319 myReetangle:Area=900 Girth=120 具体要求如下: (1)定义求面积纯虚函数,.请在注释//********1********之处添加适当的语句。 (2)定义求周长纯虚函数,请在注释//********2********之处添加适当的语句。 (3)请在注释//*****3******和//******4*****之处添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。1 #include2 #include3 #define PI 3.14159264 class CMyPoint5 {6 public:7 int x,y;8 CMyPoint(int tx,int ty):x(tx),y(ty){}9 };10 class CMyShape11 {12 public:13 CMyShape(){cout14 //********1********1516 //********2********1718 protected:19 };20 class CMyCircle:public CmyShape21 {22 public:23 CMyCircle(CMyPoint i,double j):CMyShape(),arcCenter(i),radius(j) {24 cout25 }26 double GetArea()27 {28 return PI*radius*radius;29 }30 double GetGirth()31 {32 return 2*PI*radius;33 }34 private:35 CMyPoint arcCenter;36 double radius;37 };38 class CMyRectangle:public CmyShape39 {40 public:41 CMyRectangle(CMyPoint 1t,CMyPoint rb):leftTop(1t),rightBottom(rb),CMyShape() {42 cout43 }44 Double GetArea()45 {46 int width=abs (rightBottom.x-leftTop.x);47 int height=abs (rightBOttom.y-leftTop.y);48 Return width*height;49 }50 double GetGirth()51 {52 int width=abs (rightBottom.x-leftTop.x);53 int height=abs (rightBottom.y-leftTop.y);54 return 2*(width+height);55 }56 private:57 CMyPoint leftTop,rightBottom;58 };59 void main()60 {61 CMyShape *myShape=NULL;62 CMyCircle*myCircle=new CMyCircle(CMyPoint(5,5),10);63 CMyRectangle *myRectangle=new CMyRectangle(CMyPoint(0,0),CMyPoint(30,30));64 //********3********6566 coutGetArea()67 GetGirth()68 //********4********6970 coutGetArea()71 GetGirth()72 }
请打开考生文件夹下的解决方案文件proj3,其中声明IntSet是一个用于表示正整数集合的类。IntSet的成员函数Intersection的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在main函数中给出了一组测试数据,此时程序的输出应该是:求交集前:1 2 3 5 8 102 8 9 11 30 56 67求交集后:1 2 3 5 8 102 8 9 11 30 56 672 8要求:补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//IntSet.h#includeusing namespace std;const int Max=100;C1ass IntSet{public:IntSet( )//构造一个空集合{end=-1;)IntSet(int a[ ],int size)//构造一个包含数组a中size个元素的集合{if(size>=Max)end=Max-1;elseend=size-1;for(int i=0;ielement[i]=a[i];}bool IsMemberOf(int a)//判断a是否为集合中的一个元素{for(int i=0;iif(element[i]==a)return true;return false;}int GetEnd( ){return end;}//返回最后一个元素的下标int GetElement(int i){returnelement[i];}//返回下标为i的元素IntSet Intersection(IntSetset);//求当前集合与集合set的交void Print( )//输出集合中的所有元素{for(int i=0;iif((i+1)%20==0)coutelsecouttout}private:int element[Max];int end;};void writeToFile(constchar*);//main.cpp#include"IntSet.h"IntSet IntSet::Intersection(IntSetset){int]]a[Max],size=0;//********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;coutset1.Print( );set2.Print( );set3.Print( );set3=set1.Intersection(set2);coutset1.Print( );set2.Print( );set3.Print( );writeToFile(" ");return0;}
形如A::A(A &)的构造函数称为( )。
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,其中有点类Point和线段类Line和主函数main的定义,程序中位于每个“//ERROR****found****”之的一行语句有错误,请加以改正。改正后程序的输出应为: p1=(8,4)p2=(3,5) 注意:只修改两个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeiostream#includecmathusing namespace std;class Point{ double x,y;public: Point(double x=0.0,double y=0.0)//ERROR**********found********** {x=x;y=y;} double getX()const{return x;} double getY()const{return y;}//ERROR **********found********** void show()const{cout'('x','y')') ','y')')};class Line{ Point p1,p2;public: Line(Point pt1,Point pt2)//ERROR**********found********** {pt1=p1;pt2=p2;} Point getP1()const{return p1;} Point getP2()const{return p2;}};int main()f Line line(Point(8,4),Point(3,5));cout"p1=";line.getPl().show();cout"p2="; line.getP2().show();coutendl;return 0;}
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:0 最大载重量:12 车牌号:冀 ABC1234 品牌:ForLand 类别:卡车 当前档位:2 最大载重量:12 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:0 座位数:5 车牌号:沪 XYZ5678 品牌:QQ 类别:小轿车 当前档位:一1 座位数:5 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#includeiostream#includeiomanip#includecmathusing namespace std;class AutoMobile{ //“汽车”类 char*brand; //汽车品牌 char*number; //车牌号 int speed; //档位:1、2、3、4、5,空档:0,倒档:一1public: AutoMobile(conSt char * thebrand,const char * the number):speed(0){ brand=new char[strlen(the brand)+1];//********found********___________;//********found******** ___________; strcpy(number,the number); ~AutoMobile(){delete[]brand;delete[]number;} const char*theBrand()const{return brand;} //返回品牌名称 const char *theNumber()const{return number;} //返回车牌号 int currentSpeed()const{return speed;} //返回当前档位 void changeGearTo(int thespeed){ //换到指定档位 if(speed=-1 speed=5) speed=the speed; } virtual const char*category()const=0; //类别:卡车、小轿车等 virtual void show()const { cout"车牌号:"theNumber()//********found******** "品牌:"____________ "类别:"category() "当前档位:"currentSpeed(); }};class Car:public AutoMobile{ int seats;//座位数public: Car(const char*the brand,const char * the number,int the seats):AutoMobile(thebrand,the number),seats(the seats){} int numberOfSeat()const{return seats;}//返回座位数 const char*category()const{return "小轿车";} //返回汽车类别 void show()const{ AutoMobile::show(); cout "座位数:" number-OfSeat()endl; }};class Truck:public AutoMobile{//"卡车"类 int max load;//最大载重量public: Truck(const char * the brand,const char*the number,int the max load):AutoMobile(the brand,the number),max load(the max load){} int maxLoad()const{return max load;)//返回最大载重量//********found******** const char *category()___________//返回汽车类别 void show()const { AutoMobile::show(); cout"最大载重量:"max.Load()endl; }};int main(){ Truck truck("ForLand","冀ABC1234",12); truck.show(); truck.changeGearTo(2); truck.show(); Car car("QQ","沪XYZ5678",5); car.show(); car.changeGearTo(-1); car.show(); coutendl: return 0 ;}