请问下述代码中: int operator+(…)起什么作用?this 是什么?ccc 的值最终为多少?
class Fruit
{
public:
Fruit()
{
weight = 2;
}
Fruit(int w)
{
weight = w;
}
int operator+(Fruit f)
{
return this->weight * f.weight;
}
private:
int weight;
};
Fruit aaa;
Fruit bbb(4);
int ccc = aaa + bbb;
第1题:
若有以下程序:#include <iostream>using namespace std;class A{private: int x;public: int z; void setx(int i) { x=i; } int getx() { return x; }};class B: public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a); z=b; m=c; } void display() { cout<<getx()<<","<<z<<","<<m<<end1; }};int main(){ B obj; obj.setvalue(2,3,4); obj.display(); return 0;程序运行以后的输出结果是( )
A.产生语法错误
B.2,3,4
C.2,2,2
D.4,3,2
第2题:
有以下程序: #include <iostream> using namespace std; class A { private: int x,y; public: void set (int i,int j) { x=i; y=j; } int get_y() { return y; } }; class box { private: int length,width; A label; public: void set(int 1,int w, int s,int p) { length=1; width=w; label.set(s,p); } int get_area() { return length*width; } }; int main() { box small; small.set(2,4,1,35); cout<<small.get_area()<<end1; return 0; } 运行后的输出结果是( )。
A.8
B.4
C.35
D.70
第3题:
调用函数bbb后,输出是什么
void ccc(int x)
{
char szTemp[10] = "";
x = 2;
sprintf(szTemp, "%d,", x);
afxDump << szTemp;
if(x = 3)
{
int x = 4;
sprintf(szTemp, "%d,", x);
afxDump << szTemp;
}
sprintf(szTemp, "%d,", x);
afxDump << szTemp;
}
void bbb()
{
char szTemp[10] = "";
int x = 7;
ccc(x);
sprintf(szTemp, "%d,", x);
afxDump << szTemp;
}
第4题:
请解释“func”为何种类型,这种类型的作用什么,变量ttt 的值是多少?
typedef int (*func)(int, int*);
int xxx(int a, int *p)
{
return a + *p;
}
int dowork(func aaa, int bbb, int *ccc)
{
return aaa(bbb, ccc);
}
int sss = 4;
int ttt = dowork(&xxx, 3, &sss);
第5题:
有下列程序: #include<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=O):amount(n){} Int getAmount()const{return amount;} Amount &operator+=(AmountA) {
A.*this
B.this
C.&amount
D.amount
第6题:
若有以下程序:#include<iostream>using namespace std;class A {private: int x;public: int z; void setx(int i) { x=i; } int getx () { return x; }}:class B : public A{private: int m;public: int p; void setvalue(int a, int b, int c) { setx(a) ; z=b; m=c; } void display{) { cout<<getx ()<<", "<<z<<", "<<m<<end1; }};int main(){ B obj; obj. setvalue(2,3,4); obj.display(); return 0;} 程序运行以后的输出结果是
A.产生语法错误
B.2,3,4
C.2,2,2
D.4,3,2
第7题:
下列对shell变量FRUIT操作,正确的是()
第8题:
Given: 1. public class Method Over { 2. public void set Var (int a, int b, float c) { 3. } 4. } Which two overload the set Var method()?
第9题:
public class Score implements Comparable
第10题:
public class MethodOver { public void setVar (int a, int b, float c) { } } Which two overload the setVar method?()
第11题:
public abstract class Shape { private int x; private int y; public abstract void draw(); public void setAnchor(int x, int y) { this.x = x; this.y = y; } } Which two classes use the Shape class correctly?()
第12题:
restore 400
restore 403
restore 453
Compilation fails.
An exception is thrown at runtime.
第13题:
下列选项成员变量声明正确的是
A.public protected final int i;
B.abstract class F1{…}
C.private double height;
D.double weight{}
第14题:
下列成员变量声明中,正确的是______。
A.public protected final int i;
B.abstract class F1{…}
C.private double height;
D.double weight
第15题:
int func1(int& b)
{
return 0;
}
void func2()
{
int bbb = 3;
func1(&bbb);
func1(bbb);
}
func2中有何错误,func1的参数b 的类型是什么。
第16题:
下列中 a的值是_________
#define AAA 200
#define BBB AAA+100
int a= BBB*2
第17题:
A.l = [1, 2, 3, 4, 5]; del l[2:4]; 则运算之后l为[1,2, 3]。
B.basket = ['apple', 'banana', 'apple', 'orange'] ;fruit = set(basket);fruit2 = set(['apple', 'melo']); len(fruit |fruit2) 的结果是5。
C.basket = ['apple', 'banana', 'apple', 'orange'] ;fruit = set(basket); len(fruit) 的运算结果是4。
D.l = [2, 1, 3, 5, 4]; l.remove(3); l.sort(); 则运算之后l为[1, 2, 4, 5]
第18题:
A.为变量赋值:$FRUIT=apple
B.显示变量的值:fruit=apple
C.显示变量的值:echo $FRUIT
D.判断变量是否有值:[-f“$FRUIT”]
第19题:
class A { protected int method1(int a, int b) { return 0; } } Which two are valid in a class that extends class A?()
第20题:
Assuming that the serializeBanana2() and the deserializeBanana2() methods will correctly use Java serialization and given: import java.io.*; class Food {Food() { System.out.print(”1”); } } class Fruit extends Food implements Serializable { Fruit() { System.out.print(”2”); } } public class Banana2 extends Fruit { int size = 42; public static void main(String [] args) { Banana2 b = new Banana2(); b.serializeBanana2(b); // assume correct serialization b = b.deserializeBanana2(b); // assume correct System.out.println(” restored “+ b.size + “ “); } // more Banana2 methods } What is the result?()
第21题:
11. class Payload { 12. private int weight; 13. public Payload(int wt) { weight = wt; } 13. public void setWeight(mt w) { weight = w; } 15. public String toString { return Integer.toString(weight); } 16. } 17. 18. public class TestPayload { 19. static void changePayload(Payload p) { 20. /* insert code here */ 21. } 22. 23. public static void main(String[] args) { 24. Payload p = new Payload(); 25. p.setWeight(1024); 26. changePayload(p); 27. System.out.println(”The value of p is “+ p); 28. } 29. } Which statement, placed at line 20, causes the code to print “The value of p is 420.”?()
第22题:
Assuming that the serializeBanana() and the deserializeBanana() methods will correctly use Java serialization and given: import java.io.*; class Food implemertts Serializable {int good = 3;} class Fruit externds Food {int juice = 5;} public class Banana extends Fruit { int yellow = 4; public static void main(String [] args) { Banana b = new Banana(); Banana b2 = new Banana(); b.serializeBanana(b); // assume correct serialization b2 = b.deserializeBanana(); // assume correct System.out.println(”restore “+b2.yellow+ b2.juice+b2.good); } // more Banana methods go here } What is the result?()
第23题:
1. public class Blip { 2. protected int blipvert(int x) { return 0; } 3. } 4. class Vert extends Blip { 5. // insert code here 6. } Which five methods, inserted independently at line 5, will compile?()