更多"有如下的程序:#include<iostream>#include<f"的相关试题:
[填空题]有如下的程序:
#include<iostream>
#include<fstream>
using namespace std;
int main( )
char s[25]="Programming language";
ofstream f1(DATA.TXT");
f1<<"C++ Programming";
f1.close( );
ifstream f2 ("DATA.TXT");
if(f2.good( ))f2>>s;
f2. close( );
cout<<s;
return 0;执行上面的程序交输出 【9】 。
[单项选择]有如下程序
#include <iostream>
#include <iomanip>
using namespace std;
int main( )
cout<<setprecision(3)<<fixed<<setfill(’*’)<<setw(8);
cout<< 12.345 <<___________ <<34.567;
return 0;若程序的输出是:
**12.345**34.567
则程序中下划线处遗漏的操作符是( )。
A. setprecision(3)
B. fixed
C. setfill(’*’)
D. setw(8)
[单项选择]执行如下程序,输出星号(*)的个数为
#include<iostream>
using namespaee std;
class Sample
public:
Sample( )
~Sample( )cout<<’*’;
;
int main( )
Sample temp[2],*pTemp[2];
return 0;
A. 1
B. 2
C. 3
D. 4
[填空题]有如下的程序:
#include <iostream>
#include <fstream>
using namespace std;
int main( )
ofstream outf("D://temp.txt",ios_base::trunc) ;
outf<<"World Wide Web";
outf.close( );
ifstream inf("D://temp.txt");
char s[20];
inf>>s;
inf.close( );
cout<<s;
return 0;
执行后的输出结果是 【15】 。
[填空题]下列程序的输出结果是【 】
#include<iostream>
using namespace std;
template<typenameT>
Tfun(Ta,TB) {return (a<=B) a:b;}
int main ( )
{
cout<<fun(3,6)<<’’,’’<<fun(3.14F,6.28F)<<end1;
return 0;
}
[填空题]有如下的程序:
#include<iostream>
#include<fstream>
using namespace std;
int main( ) {
char s[25]="Programming language";
ofstream f1(DATA.TXT");
f1<<"C++ Programming";
f1.close( );
ifstream f2 ("DATA.TXT");
if(f2.good( ))f2>>s;
f2. close( );
cout<<s;
return 0;
}
执行上面的程序交输出 【9】 。
[单项选择]有以下程序
#include<iostream>
#include<string>
using namespace std;
class base
private:
charbaseName[10];
public:
base( )
strcpy(baseName,"Base");
virtual char*myName( )
return baseName;
char *className( )
return baseName;
;
class Derived: public base
private:
char derivedName[10];
public:
Derived( )
strcpy(derivedName,"Derived");
char *myName( )
return derivedName;
char *className( )
return derivedName;
;
void showPtr(base &p)
cout<<p.myName0<<" "<<p.className( );
int main( )
base bb;
Derived dd;
showPtr(dD) ;
retum 0;
动行后的输出结果为
A. Derived Base
B. Base Base
C. Derived Derived
D. Base Derived
[填空题]以下程序的执行结果为【 】。
#include<iostream>
using namespace std;
class base
{
public:
virtual void who( )
{
cout < < "base class" < <end1;
};
class derivel:public base
{
public:
void who( )
{
cout < <"derivel class" < <end1;
};
} class derive2:public base
{
public:
void who( )
{
cout< <"derive2 class"< <end1;
}
};
void main( )
{
base obj1,* p;
derivel obi2;
derive2 obj3;
p=&obj1;
p->who( );
p=&obj2;
p->who( );
p=&obj3;
p->who( );
}
[填空题]下列程序的输出结果是 【10】 。
#include <iostream>
using namespace std;
int main( )
int data=1;
int &r = data;
data+=5;
r+=5;
cout<<data<<end 1;
return 0;
[填空题]下面程序输出的结果是 【11】 。
#include <iostream>
using namespacc std;
class A {
public:
void show( ){tout<<"A!";}
};
class B: public A{
public:
virtual void show( ){cout<<"B!";}
};
class C: public B{
public:
virtual void show( ){cout<<"C!";}
};
void show_info(A *i){i->show( );}
void main( ){
A ia;B ib;C ic;show_info(&ia); show_info(&ib);show_info(&ic);
}
[填空题]下面程序输出的结果是 【10】 。
#include <iostream>
using namespace std;
class A {
public:
virtual void show( ) {cout<<"A!";
};
class B: public A {
public:
void show( ) {cout << "B!";}
};
class C: public B{
public:
void show( ){cout << "C!";}
};
void show_info(A &i) {i. show( );}
void main( ) {
A ia; B ib; C ic; show_info(ia);show_info(ib); show_info(ic); }
[填空题]下列程序的输出结果是 【15】 。
#include <iostream>
using namespace std;
class base {
public:
int n;
base(iht x) {n=x;}
virtual void set(int m) {n=m;cout<<n<<’’;}
};
class deriveA: public base {
public:
deriveA(int x):base(x) {}
void set(int m){n+=m;cout<<n<<’’;}
}:
class deriveB:public base {
public:
deriveB(int x):base(x) { }
void set(int m) {n+=m;cout<<n<<’’;}
};
int main( )
deriveA d1(1);
deriveB d2(3);
base *pbase;
pbase=&d 1;
pbase->set(1);
pbase=&d2;
pbase->set(2);
return 0;