有以下程序: #include <iostream> #include <cmath> using namespace std; class Distance; class point { public: friend class Distance; Point(int a,int B) { x=a; Y=b; } void Print() { cout<<"X= "<<X<<end1; cout<<"Y= "<<Y<<end1; } private: float X,Y; }; class Distance { public: float Dis(Point &p,Point &q); }; float Distance :: Dis(Point &p,Point &q) { float result; result=sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y)); cout<<result<<end1; retUrn result; } int main() { Point p(10,10),q(10,30); Distance d; d.Dis(p,q); return 0; } 运行后的输出结果是( )。
A.10
B.30
C.0
D.20
第1题:
以下程序的执行结果是【 】。
include<iostream.h>
include<iomanip.h>
void pnnt(int n)
{
if (n!=0)
{
Print(n-1);
for (int i=1;i<=n;i++)
cout<<setw(3)<<i;
cout<<endl;
}
}
void main()
{
print(4);
}
第2题:
有以下程序:
include”iostream.h”
void main()
{int i=10;
int j=5;
cout((j+i++<<endl;}
的结果为______。
第3题:
以下程序的输出结果是【 】。
include<iostream.h>
include <string.h>
void main 0 {
char s[50];
strcpy(&s[O], "No" );
strcpy(&s[1], "123" );
strcpy (&s[2], "23456" );
cout<<s;
}
第4题:
下面程序的执行结果是【 】。
include<iostream>
include<iomanip>
using namespace std;
void main()
{
cout<<setfill('x')<<setw(10);
cout<<"Hello"<<endl;
}
第5题:
有以下程序 #include<string.h> #include<iostream.h> void main( ) { char*p="abcde\0fghjik\0"; cout<<strlen(p);} 程序运行后的输出结果是
A.12
B.15
C.6
D.5
第6题:
以下程序的执行结果是【 】。
include <iostream.h>
include <fstream.h>
include <stdlib.h>
int main()
{
fstream outfile, infile;
outfile.open("D:\\text.dat",ios::out);
if(!outfile)
{
cout<<"text.dat can't open"<<end1
第7题:
如有以下程序: #include(iostream> usingnamespacestd; longfun(intn) { if(n)2) return(fun(n-1)+fun(n-2)); else return2; } intmain( ) { cout<<fun(3)<<endl; return0; } 则该程序的输出结果应该是( )。
A.2
B.3
C.4
D.5
第8题:
有以下程序: #include <iostream> #include <fstream> using namespace std; int main ( ) { ofstream ofile; char ch; ofile.open ("abc.txt"); cin>>ch; while (ch!='#' ) { cin>>ch; ofile.put(ch);
A.程序编译时出错
B.abc#
C.abc
D.#
第9题:
以下程序的运行结果是【 】。
include<iostream>
include<string>
using namespace std;
void main(){
chara[10]="China",b[]="Chin",c[]="ese";
cout<<strlen(strcat(strcpy(a,b),c))<<endl;
}
第10题:
有以下程序: #include<iostream> #include<string> using namespace std; int main() { char arr[2][4]; strcpy(arr[0],"you"); strcpy(arr[1],"me"); arr[0][3]='&'; cout<<arr[0]<<end1; return 0; } 执行后的输出结果是( )。
A.you&me
B.you
C.me
D.err
第11题:
有以下程序: #include <iostream> #include <string> using namespace std; int main ( ) { char b1[8] = "abcdefg"; char b2[8],*pb=b1+3; while (--pb>=b1) strcpy (b2, Pb) ; cout<<strlen (b2) <<end1; return 0; } 程序运行后的输出结果是( )。
A.8
B.3
C.1
D.7
第12题:
下列程序的输出结果是 #include <iostream> using namespace std; int main () { char a [] = "Hello,World": char*ptr = a; while (*ptr) { if(*ptr>= 'a' &&*ptr <='z' cout<<char{*ptr+'A'-'a'); else cout<<*ptr; ptr++; } return 0; }
A. HELLO. WORLD
B. Hello, World
C. hELLO, wORLD
D. hello, world
第13题:
以下程序的输出结果 ______。
include<iostream.h>
void main()
{
int a=0;
a+ =(a=8);
cout<<a;
}
第14题:
有以下程序:
include <iostream>
using namespace std;
int main()
{
int i=010,j=10;
cout<<(++i)<<","<<i--<<end1;
return 0;
}
则该程序运行后的输出结果是【 】。
第15题:
有以下程序:
include <iostream>
using namespace std;
class CFactorial
{
private:
int value;
int fact;
public:
CFactorial ( int val );
void CalculateFactorial();
void Display();
};
CFactorial :: CFactorial( int val )
{
value = val;
fact = 1;
}
void CFactorial :: CalculateFactorial()
{
int i = value;
while ( i > 1 )
fact *= i--;
}
void CFactorial :: Display()
{
cout<<value<<"!="<<fact<<end1;
}
int main()
{
CFactorial A( 5 );
A.CalculateFactorial();
A.Display();
return 0;
}
程序中,类CPactorial的功能是【 】,该程序运行的结果是【 】。
第16题:
有以下程序:
include<iostream>
using namespace std;
class Base
{
public:
Base()
{
K=0;
}
int x;
};
class Derivedl:virtual public Base
{
public:
Derivedl()
{
x=10;
}
};
class Derived2:virtua1 public Base
第17题:
有以下程序: #include <iostream> using namespace std; int main() { int num[2][3],*p; int t,i,j,k=10; p=num[0]; for(i=0;i<2;i++) { for(j=0;j<3;j++) { k++; *p=k; for(t=2;t<*p;t++) { if(!(*p%t)) { j--; *p--; break; } *p++; } } cout<<*(p-1)<<end1; return 0; } 程序运行后的输出结果是( )。
A.19
B.11
C.29
D.23
第18题:
有以下程序: #include <iostream> using namespace std; #define PI 3.14 class Point { private: int x,y; public: Point(int a,int b) { x=a; y=b; } int getx() { return x; } int gety() { return y; } }; class Circle : public Point { private: int r; public: Circle(int a,int b,int c):Point(a,b) { r=c; } int getr() { return r; } double area() { return PI*r*r; } }; int main() { Circle c1(5,7,10); cout<<cl.area()<<endl; return 0; } 程序执行后的输出结果是
A.314
B.157
C.78.5
D.153.86
第19题:
有以下程序: #include <iostream> #include <string> using namespace std; class base { private: char baseName[10]; public: base ( ) { strcpy (baseName, "Base"); } virtual char *myName() {
A.DerivedBase
B.BaseBase
C.DerivedDerived
D.BaseDerived
第20题:
有下列程序:
include<iostream>
using namespace std;
class ONE
{
public:
virtual void f(){COUt<<"1";}
};
c1assTWO:public ONE
{
public:
TWO(){cout<<"2";}
};
class THREE:public TWO
{
pub
第21题:
有以下程序: #include(iostream) usingnamespacestd; intmain( ) { intx=15: while(x>10&&x<50) { x++; if(x/3) { x++;break; }
} cout<<x<<endl; return0; } 执行后的输出结果是( )。
A.15
B.16
C.17
D.18
第22题:
有以下程序: #include<iostream> using namespace std; Class A{ public: A(){tout{("A"} }; classB{public:B(){cout<<"B";>> classC:public A{ B b; public: C(){cout<<"C";} }; int main(){C obj;return 0;} 执行后的输出结果是( )。
A.CBA
B.BAC
C.ACB
D.ABC
第23题:
有以下程序:#include <iostream.h>#include void main(){ double d= 123.456789; cout<<setprecision(3)<<d<<","; cout<<setprecision(4)<<d<<","; cout<<setprecision(5 )<<d<<end1;}程序执行后的输出结果是( )。
A.123,123.4,123.45
B.123,123.5,123.46
C.123,123,123.4
D.123.456789,123.456789,123.456789