下面程序的预设功能是:将文本文件readme 中的内容读出,显示在屏幕上。
include <fstream>
using namespace std;
int main ()
{
char buf[ 80 ];
ifstream file("readme");
while (_______________)
{
file.getline(buf, 80 );
cout<<buf<<end1;
}
me. close();
}
则程序中空白处应填入的语句为【 】。
第1题
有如下程序:
include <iostream>
using namespaee std;
class ONE{
public:
virtual void f( ){cout<<"1";}
};
class TWO:public ONE{
public:
TWO( )1 cout<<"2";}
{;
class THREE:public TWO{
public:
virtual void f( )}TWO::f( );cout<<"3";}
};
int main( ){
ONE aa,*P;
TWO bb;
THREE cc;
P=&cc;
p->f( );
return 0;
}
程序的输出结果是______。
第2题
n(n≥2)位整数,函数求出s的n位数之和作为函数的返回值。
例如,s值为4315,则函数返回13。s值为13函数,则返回4。
注意:部分源程序已存在文件PROC15.cpp中。
请勿修改主函数和其他函数中的任何内容,仅在函数fun()的花括号中填写若干语句。
文件PROC15.cpp的内容如下:
//PROC15.cpp
include<iostream>
using namespace std;
unsigned short fun(unsigned short s);
int main()
{
unsigned short a;
cout<<"Enter a unsigned short integer number:";
cin>>a;
if(a<10)
cout<<"Data error!";
else
cout<<"The result: "<<fun(a)<<end1;
return 0;
}
unsigned short fun(unsigned short s)
{
//* * * * * *
}
第4题
问题,请改正程序中的错误,使该程序的输出结果为:
5
5
源程序文件test28_1.cpp清单如下:
include <iostream.h>
class A{
public:
/***************** found *****************
static int n=1;
A(){n++;};
~A() (n--;};
};
/***************** found *****************
int n=0;
int main() {
A a;
A b[3];
A *c=new A;
c=&a;
/***************** found *****************
cout<<c.n<<end1;
cout<<A::n<<end1;
return 0;
}
第5题
有以下面程序:
include <iostream>
using namespace std;
long fib(int n)
{
if (n>2)
return (fib(n-1)+fib(n-2));
else
return 2;
}
int main()
{
cout<<fib(3)<<endl;
return 0;
}
则该程序的输出结果应该是【 】。
第6题
operator=(const TestClass& rhs)
{
if(this==&rhs)return *this;
value=rhs.value;
return *this;
}
第7题
阅读下面程序:
include<iostream.h>
void fun(int n)
{
int x(5);
static int y(10);
if(n>0)
{
++x;
++y;
cout<<x<<","<<y<<end1;
}
}
void main()
{
int m(1);
fun(m);
}
则该程序的输出结果是______。
第8题
有以下程序:
include<iostream>
using namespace std;
class MyClass
{
public:
static int s;
MyClass();
void SetValue(int val);
};
int MyClass::s=0;
MyClass::MyClass()
{
S++;
}
void MyClass::SetValue(int val)
{
s=val;
}
int main()
{
MyClass my[3],*p;
p=my;
for(int k=0;k<3;k++)
{
p->SetValue(k+1);
p++;
}
cout<<MyClass::s<<end1;
return 0;
}
运行后的输出结果是______。
第9题
请在mian函数中填空使下面程序的输出结果为1 1。
include<iostream.h>
class A
{ private:
int a;
int b;
public:
A( ):a(0) ,b(1) { }
void show( ) { cout < < a < < " " < < b;} };
class B
{ private:
int a;
int c;
public:
B( ):a(1),
第10题
mystrlen函数的功能是计算str所指字符中的长度,并作为函数值返回,请填空。
int mystrlen(char * str)
{ int i;
for(i=0;【 】!='\0';i++);
return(i);}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!