给出下面程序的输出结果
#include"iostream.h"
int main( )
{
int i=17;
while(i>=10)
if(--i%4==3)continue;
else
cout<<"i="< } 试题出自试卷《C++程序设计2009年1月真题试题及答案解析(04737)》 参考答案
}
定义堆栈类模板Stack(先进后出),栈的大小由使用者确定。要求该类模板对外提供如下二种基本操作:
(1)push入栈(2)pop出栈,用数组来实现
#include
using namespace std;
template
class Stack{
T x[size];
int current;
public:
Stack( ){current=0;}
....push(....);
....pop(....);
};
请写出两个函数的过程(如果需要形式参数,请给出形参类型和数量,以及返回值类型)
cout<<"i="< }
void main( )
int num=300;
int &ref=num;
cout< ref=ref-100; cout<<" "< num=num-50; cout<<" "< }
ref=ref-100;
cout<<" "< num=num-50; cout<<" "< }
num=num-50;
cout<<" "< }
class Simple
int x, y;
public:
Simple( ){x=y=0;}
Simple(int i, int j){x=i; y=j;}
void copy(Simple&s);
void setxy(int i, int j){x=i; y=j;}
void print( ){cout<<"x="<};void Simple:: copy(Simple&s){x=s.x; y=s.y;}void func(Simple s1,Simple&s2){s1.setxy(30, 40);s2.setxy(70, 80);}void main( ){Simple obj1(1, 2), obj2;obj2.copy(obj1);func(obj1,obj2);obj1.print( );obj2.print( );}
void Simple:: copy(Simple&s)
x=s.x; y=s.y;
void func(Simple s1,Simple&s2)
s1.setxy(30, 40);
s2.setxy(70, 80);
Simple obj1(1, 2), obj2;
obj2.copy(obj1);
func(obj1,obj2);
obj1.print( );
obj2.print( );
在下划线处填上缺少的部分。源程序如下:
___________
T fun(T x)
_________y;
y=x*x-T(5);
return y;
float a=2;
cout< }
请写出myTextl.txt文本文件中的内容
ofstream myFile1;
myFile1.open("myText1.txt");
cout<<"Enter the data in Chinese format(e.g.,2008,May 25):"<string Date("2008,January 1");string Year=Date.substr(0,4);int k=Date.find(",");int i=Date.find(" ");string Month=Date.substr(k+1, i-k-1);string Day=Date.substr(i+1, 2);string NewDate=Day+" "+Month+" "+Year;myFile1<<"original date:"<myFile1<<"Converted date:"<myFile1.close( );}
string Date("2008,January 1");
string Year=Date.substr(0,4);
int k=Date.find(",");
int i=Date.find(" ");
string Month=Date.substr(k+1, i-k-1);
string Day=Date.substr(i+1, 2);
string NewDate=Day+" "+Month+" "+Year;
myFile1<<"original date:"<myFile1<<"Converted date:"<myFile1.close( );}
myFile1<<"Converted date:"<myFile1.close( );}
myFile1.close( );
下面程序的运行结果如下:
B::display( )
C::display( )
class B
_________display( ) {cout<< "B::display( ) "< }; class C: public B { public: __________display( ){cout<<"C::display( )"< }; void fun(B*p) { p->display( ); } void main( ) { B b, *pb; C c; pb=&b; fun(pb); pb=&c; fun(pb); }
class C: public B
__________display( ){cout<<"C::display( )"< }; void fun(B*p) { p->display( ); } void main( ) { B b, *pb; C c; pb=&b; fun(pb); pb=&c; fun(pb); }
void fun(B*p)
p->display( );
B b, *pb;
C c;
pb=&b;
fun(pb);
pb=&c;
This is line1
This is line2
This is line3
#include_________
fstream fin, fout;
fout.open("my. txt", ios:: out);
if(!fout.is_open( ))
return;
for(int i=0;i<3;i=i+1)
fout<<"This is line"<
fout.close( );
fin.open("my.txt",ios:: in);
if(! fin.is_open( ))
char str[100];
while(_________)
fin.getline(str,100);
cout< } fin.close( ); }
fin.close( );
完成下面程序,使其输出10,并在退出运行时正确释放分配给指针的存储空间。
int *a, *p;
a=new int(10);
p=_________;
cout<<*p<_________}
_________
class base
private: int x;
public: base(int a){x=a;}
int get( ){return x;}
void showbase( ) {cout<<"x="<};class Derived: public base{private: int y;public: Derived(int a,int b): base(a){y=b;}void showderived( ){cout<<"x="<}; void main( ){base b(3);Derived d(6,7);b.showbase( );d.showderived( );___________;b.showbase( );___________;b1.showbase( );base* pb=&b1;pb->showbase( );d.showderived( );b.showbase( );}输出结果如下:x=3x=6,y=7x=6x=6x=6x=6,y=7x=6
class Derived: public base
{private: int y;
public: Derived(int a,int b): base(a){y=b;}
void showderived( )
{cout<<"x="<}; void main( ){base b(3);Derived d(6,7);b.showbase( );d.showderived( );___________;b.showbase( );___________;b1.showbase( );base* pb=&b1;pb->showbase( );d.showderived( );b.showbase( );}输出结果如下:x=3x=6,y=7x=6x=6x=6x=6,y=7x=6
void main( ){
base b(3);
Derived d(6,7);
b.showbase( );
d.showderived( );
___________;
b1.showbase( );
base* pb=&b1;
pb->showbase( );
输出结果如下:
x=3
x=6,y=7
x=6
热门试卷
经济师初级(经济基础知识)模拟试卷5
经济师初级经济基础知识(商品经济的基
经济师(初级)工商管理专业知识与实务
初级经济师试题及答案3(公路运输)
经济师初级人力资源管理专业知识与实务
初级经济师《工商专业》全真模拟试卷(
初级经济师《经济基础知识》考前突破试
订单号:
遇到问题请联系在线客服