完成下面类中成员函数的定义。
#include
template
class f
{private:
T x,y,s;
public:
f(T a=0,T b=0){x=a;y=b;}
void sum()
{s=x+y;
T gets();
};
____________
{
return s;
}
void main()
{____________a(1.5,3.8);
cout<
下面Shape类是一个表示形状的抽象类,Are()为求图形面积的函数。请从Shape类派生梯形类(Trapezoid)圆形类(Circle)三角形类(Triangle)并给出具体的求面积函数。其中所有派生类计算面积需要用到的参数由构造函数给出,梯形面积计算需要上底、下底和高,三角形面积需要底和高,圆形面积需要半径。
状的抽象类声明如下:
class Shape{
virtual double Area( )=0;
给出下面程序的输出结果。
int min(int a,int b)
{if(a
else return b;
return 0;
{cout<
#include< iostream.h>
class example
{int a;
example(int b=5){a=b++;}
void print(){a=a+1;cout<
void print()const
{example x;
const example y(2);
x.print();
y.print();
有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字
符串。
using namespace std;
void copystr(_________)
{int n=0;
while(n{n++;P1++;}while(*p1!='\0'){*p2=*p1;p1++;p2++;}*p2=’\0’;}void main(){int m;char strl[20],str2[20];cout<"输入字符串1:";____________cout<<从第m个字符开始复制,请输入m:”;cin>>m:if(strlen(strl)cout<<"输入超过str1的长度"<else{copystr(str1,str2,m);cout<<"复制的字符串是:"<}}
{n++;
P1++;
while(*p1!='\0')
{*p2=*p1;
p1++;
p2++;
*p2=’\0’;
{int m;
char strl[20],str2[20];
cout<"输入字符串1:";
cout<<从第m个字符开始复制,请输入m:”;
cin>>m:
if(strlen(strl)cout<<"输入超过str1的长度"<else{copystr(str1,str2,m);cout<<"复制的字符串是:"<}}
cout<<"输入超过str1的长度"<else{copystr(str1,str2,m);cout<<"复制的字符串是:"<}}
else
{copystr(str1,str2,m);
cout<<"复制的字符串是:"<}}
在下面程序横线处填上适当的语句,使其输出结果为0,15,15。
class base
{public:
__________f(){return 0;}
class derived:public base
int a,b,c;
__________set(int x,int y,int z){a=x;b=y;c=z;}
int f(){return a+b+c;}
{base b;
derived d;
d.set(3,5,7);
cout<base &p=d;cout<}
base &p=d;
class vehicle
{protected:
int size;
int speed;
void set( int s){speed =s;}
_________get(){return speed/10;}
class car:public vehicle
int get(){return speed;}
class truck:public vehicle
int get(){return speed/2;}
int max(_________)
return 1;
return 2;
{truck t;
car c;
t.set(160);
c.set(80);
cout<}
在下面程序的横线处填上适当内容,以使该程序执行结果为:50 4 34 21 10 0 7.1 8.1 9.1 10.1 11.1
void f(____________)
{____________
for(int i=0;i{t=a[i];a[i]=a[n-1-i;a[n-1-i]=t;}void main(){int a[5]=10,21,34,4,50};double[6]=11.1,10.1,9.1,8.1,7.1};f(a,5);f(d,6);for (int i=0;i<5;i++)cout<cout<for(i=0;i<6;i++)cout<cout< endl;}
{t=a[i];a[i]=a[n-1-i;a[n-1-i]=t;}
{int a[5]=10,21,34,4,50};
double[6]=11.1,10.1,9.1,8.1,7.1};
f(a,5);f(d,6);
for (int i=0;i<5;i++)
cout<for(i=0;i<6;i++)cout<cout< endl;}
for(i=0;i<6;i++)
cout<cout< endl;}
cout< endl;
运行程序,从键盘上输入“This is a C++ prog!”后输出到一个文件中,并显示在屏幕上,显示结果:This is a C++ prog!。
{char str[20];
ofstream outf("D:\tem.dat", ios::trunc);
Cin>>str;
outf<Outf.close();int i=0;while(str[i]! ='\0'){cout<i++;}cout<}
Outf.close();
int i=0;
while(str[i]! ='\0')
{cout<i++;}cout<}
i++;
class B
{int a,b
const int c;
Public;
B(int i=0,int j=0){a=i;b=j;c=i-j;}
{B a,b(3,5);
B x=a,z(5,9);
热门试卷
经济师初级(经济基础知识)模拟试卷5
经济师初级经济基础知识(商品经济的基
经济师(初级)工商管理专业知识与实务
初级经济师试题及答案3(公路运输)
经济师初级人力资源管理专业知识与实务
初级经济师《工商专业》全真模拟试卷(
初级经济师《经济基础知识》考前突破试
订单号:
遇到问题请联系在线客服