更多"有以下程序#include <iostream>using names"的相关试题:
[单项选择]有以下程序:
#include <iostream>
using namespace std;
class sampleprivate:
int x;
static int y;
public:
sample(int a);
static void print(sample s);
;
sample:: sample(int a) x=a;
y+=x;void sample:: print(sample s) cout<<"x="<<s. x<<",y="<<y<<end1;int sample:: y=0;
int main( ) sample s1(10);
sample s2(20);
sample:: print(s2);
return 0;程序运行后的输出结果是( )。
A. x=10,y=20
B. x=20,y=30
C. x=30,y=20
D. x=30,y=30
[单项选择]有如下程序:
#include <iostream>
using namespace std;
class Baseprivate:
char c;
public:
Base(char n):c(n)
~Base( )
cout<<c;
;
class Derived: public Baseprivate:
char c;
public:
Derived(char n):Base(n+1),c(n)
~Derived( )
cout<<c;
;
int main( ) Derived obj('x');
return 0;
执行上面的程序将输出()。
A. xy
B. yx
C. x
D. y
[单项选择]有以下程序
#include <iostream>
using namespace std;
class Complex
public:
Complex(double r=0,double i=0):re(r),im(i)
double real( ) const return re;
double irnag( ) const return im;
Complex operator+(Complex c)const
( return Complex(re+c.re,im+c.im),
private:
double re,im;
;
int main( )
Complex a=Complex(1,1)+Complex(5);
cout<<a.real( )<<'+'<<a.imag( )<<'i'<<endl;
return 0;
程序执行后的输出结果是( )。
A. 6+6i
B. 6+1i
C. 1+6i
D. 1+1i