更多“类型转换函数实例: class CMyPoint { int x, y; public: CMyPoint(int i, int j) { x = i; y = j; } operator doubl…”相关的问题
第1题
有以下程序 #include "iostream" using namespace std; void point(char *p){p+=3;} int main() { char b[4]={'a','b','c','d'},*p=b; point(p); cout<<*p< return 0; } 程序运行后的输出结果是(> A、a
点击查看答案
第2题
类运算符重载实例如下: class CMyPoint { int x, y; public: CMyPoint(int i, int j){ x=i; y=j; } CMyPoint operator+(CMyPoint &p) //二元运算符 {return CMyPoint(x+p.x, y+p.y);} CMyPoint operator–(CMyPoint &p) //二元运算符 {return CMyPoint(x-p.x, y–p.y);} }; p1,p2为该类的实例,则如下调用方法中,错误的是( )
A、CMyPoint p3=p1+p2;
B、operator +(p1,p2);
C、p1=p1.operator +(p2);
D、p1=p1 +(p2);
点击查看答案
第3题
#include <iostream> using namespace std; class Point{ public: int x, y; Point(int a, int b=1){ x=a; y=b; } Point(Point &obj){ x=obj.x; y=obj.y; } }; void main(){ Point obj1(5); Point obj2(obj1); Point obj3=obj2; cout< <obj1.y> <<”,”<> <<”,”< } 则程序运行后的输出为:(> A、5,5,5
点击查看答案
第4题
有如下程序 #include<iostream> using namespace std; class Test{ public: Test(){data=0;k++;} ~Test(){} int getK(){return k;} private: static int k; int data; }; int Test::k=0; int main() { Test a[2],*ptr; Test b; cout<<b.getk()<<endl; return 0; }> A、0
点击查看答案
第5题
有如下程序: #include usingnamespacestd; classPoint{ intX,y; public: Point(intx1=0,inty1=0):X(x1),y(y1){} intget(){returnx+y;} }; classCircle{ Pointcenter; intradius; public: Circle(intCX,intcy,intr):center(CX,cy),radius(r) {} intget(){returncenter.get()+radius;} }; intmain(){ Circlec(3,4,5); cout$amp;A.5
点击查看答案
第6题
23. Sale by sample includes sale by seller’s sample, sale by buyer’s sample and sale by duplicate sample.
点击查看答案
第7题
已知: package p; class C { public int x; } 那么,在哪种情况下可以访问 x
A、任意类
B、只有类 C
C、只有类 C 的子类
D、包 p 中的类
点击查看答案
第8题
Number类定义如下: public class Number { public int x; } swap方法定义如下: public static void swap(Number number1, Number number2) { int temp = number1.x; number1.x = number2.x; number2.x = temp; } 运行如下代码: Number number1 = new Number(); Number number2 = new Number(); Number number3 = new Number(); number1.x = 1; number2.x = 2; number3.x = 3; swap(number1, number2); swap(number2, number3); 则number1.x, number2.x, number3.x的值分别为:
A、1, 2, 3
B、2, 3, 1
C、3, 2, 1
D、1, 3, 2
点击查看答案
第9题
现有分数类: class Fraction { public: Fraction(int x, int y) {fenzi = x;fenmu = y;} private: int fenzi; int fenmu; };
点击查看答案