下面是类Shape的定义:class Shape{public:virtual void Draw()=0;}下列关于Shape类的描述中,正确
下面是类Shape的定义: class Shape{ public: virtual void Draw()=0; } 下列关于Shape类的描述中,正确的是()。
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“Shape s;”能够建立Shape的一个对象s
下面是类Shape的定义: class Shape{ public: virtual void Draw()=0; } 下列关于Shape类的描述中,正确的是()。
A.类Shape是虚基类
B.类Shape是抽象类
C.类Shape中的Draw函数声明有误
D.语句“Shape s;”能够建立Shape的一个对象s
(12 ) “ 图形 ” 类 Shape 中定义了纯虚函数 CalArea() ,“ 三角形 ” 类 Triangle 继承了类Shape ,请 将
Triangle 类中的 CalArea 函数补充完整。
class Shape{
public:
virtual int CalArea()=0;
}
class Triangle: public Shape{
public:
Triangle{int s, int h}: side(s),height(h) {}
【 12 】 { return side*height/2 ; }
private:
int side;
int height;
};
下面是一个类的定义,试将程序补充完整。
class A{
String s;
____int a=66;
A(String sl){
s=sl;
}
static int geta(){
return a;
}
}
已知: abstract class Shape { private int x, y; void setLocation(int x, int y) { this.x = x; this.y = y; } abstract void draw(); } class Circle extends Shape { void draw() {} } class Test { public static void main(String[] args) { _________________ } } 下面哪段代码在横线处是合法的
A、Shape s = new Shape(); s.setLocation(1,1); s.draw();
B、Circle c = new Shape(); s.setLocation(1,1); s.draw();
C、Shape s = new Circle() s.setLocation(1,1); s.draw();
D、Shape s = new Circle() s.Shape.setLocation(1,1); s.Shape.draw();
A.一切成功编译
B.Shape可以编译,Square不能编译
C.Square可以编译,Shape不能编译
D.Square,Shape都不能编译
下面程序是一个堆栈的类模板,在横线处填上适当语句,完成类模板的定义。
define MAXSIZE 100
template <class T>
class Stack
{
T s[MAXSIZE];
int top;
public:
stack()
{
top=1;
}
void push(T newValue)
{
if(top<MAXSIZE)
{
top=top+1;
s[top]=newValue;
}
else
cout<<"堆栈满,无法进栈"<<end1;
}
void pop();
};
【 】
{
if(top>1)
{
cout<<s[top]<<end1;
top=top-1;
}
else
cout<<"堆栈空! "<<end1;
}
完成下面类中成员函数的定义。 #include <iostream.h> class vehicle {protected: int size; int speed; public: void set(int s){speed=s;} _____get(){return speed/10;} }; class car:public vehicle { public: int get(){return speed;} }; class truck:public vehicle { public: int get(){return speed/2;} }; int max(vehicle &v1,vehicle &v2) { if(v1.get()>v2.get()) return 1; else return 2; } void main() { truck t; car c; t.set(160); c.set(80); cout< <max(t,c)> < <endl; 此结果输出为2>
完成下面类中成员函数的定义。 #include <iostream> #include <string> using namespace std; class str {private: char *st; public: str(char *a) {set(a); } str & operator=(str &a) {delete st; set(a.st); return *this; } void show(){cout< <st> < <endl;} ~str(){delete st;} void set(char *s) 初始化st {_____ strcpy(st,s); } }; main() {str s1("he"),s2("she"); s1.show(),s2.show(); s2="s1;">
【单选题】6.3 若有如下程序: class Teacher{ String name="李";} class Student{ void show(Teacher t){System.out.print(t.name);}} class Main{ public static void main(String []args){ Student s = new Student(); s.show(new Teacher());}} 则下面描述正确的是()
A、System.out.print(t.name);语句有语法错误
B、Teacher类的定义有错误,因为缺成员方法
C、s.show(new Teacher());语句有语法错误
D、程序运行结果显示“李”
根据下面类中Give 函数的原型和注释写出它的类外定义。
class Strings {
char *s; // 指向动态分配的字符串数组空间
int n; // 记录字符串长度
public:
Strings(char*str); // 构造函数,利用str 字符串长度初始化n,
// 利用str 字符串初始化s 所指的字符串空间
Strings(Strings& str); // 拷贝构造函数
Strings& Give(Strings& str); // 实现str 赋值给*this 的功能并返回*this
Strings Uion(Strings& str); // 实现*this 和str 中的字符串合并的
// 功能,把合并结果存入临时对象并返回
int Lenth() {return n;} // 返回字符串长度
void Print() {cout<<s<<endl;} // 输出字符串
};
为了保护您的账号安全,请在“简答题”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!