分析下面程序功能,并写出程序运行结果
分析下面程序功能,并写出程序运行结果#include<iostream.h>Classbase{Inb;Public:Base(intnum){b=num;count<=...
分析下面程序功能,并写出程序运行结果
# include<iostream.h>
Class base
{
Inb;
Public:
Base(int num )
{ b=num; count<=”base create/n “ ;}
-base()
{ count<=” base destroy/n” ;}
};
Class deriver; public base
{
Int d ;
Public;
Deriver (int nmm1,int nom2): base(nmm1)
{d=num2;count<<”deriver create/n” ; }
-deriver()
{ count<<”deriver destroy/n” ;}
} ;
Void main()
{ base * pb1,*pb2;
Pb1=new base (1);
Pb2=new deriver (2,3) ;
Delete pb1:
Delete pb2:
Count<< “ **********/n “ ;
Base bobj(4);
}
程序的输出是: 展开
# include<iostream.h>
Class base
{
Inb;
Public:
Base(int num )
{ b=num; count<=”base create/n “ ;}
-base()
{ count<=” base destroy/n” ;}
};
Class deriver; public base
{
Int d ;
Public;
Deriver (int nmm1,int nom2): base(nmm1)
{d=num2;count<<”deriver create/n” ; }
-deriver()
{ count<<”deriver destroy/n” ;}
} ;
Void main()
{ base * pb1,*pb2;
Pb1=new base (1);
Pb2=new deriver (2,3) ;
Delete pb1:
Delete pb2:
Count<< “ **********/n “ ;
Base bobj(4);
}
程序的输出是: 展开
展开全部
靠,什么程序,都是错误,根本不会有结果,不知道是从哪里抄来的,下面是我帮你改的:
# include <iostream.h>
# include <conio.h>
class base
{
private:
int b;
public:
base(int num)
{ b=num; cout<<"base create\n";}
~base()
{ cout<<"base destroy\n" ;}
};
class deriver: public base
{
private:
int d ;
public:
deriver (int nmm1,int num2): base(nmm1)
{d=num2;cout<<"deriver create\n"; }
~deriver()
{ cout<<"deriver destroy\n";}
} ;
void main()
{ base *pb1,*pb2;
pb1=new base (1);
pb2=new deriver (2,3);
delete pb1;
delete pb2;
cout<< "**********\n " ;
base bobj(4);
getch();
}
运行结果如下:
base create
base create
deriver create
base destroy
base destroy
**********
base create
说明:这段程序是类的继承,构造和析构的练习,从你的程序我分析,你对C++语言的基础知识还不了解,首先C语言是严格区分大小写的,构造函数的命名应该跟类的命名要一致,析构函数前用~,而不是-,最后<iostream.h>中输出函数名是cout而不是count,使用方法是cout<<而不是count<=,多看看书,把这些先弄清楚了,对你帮助会更大
# include <iostream.h>
# include <conio.h>
class base
{
private:
int b;
public:
base(int num)
{ b=num; cout<<"base create\n";}
~base()
{ cout<<"base destroy\n" ;}
};
class deriver: public base
{
private:
int d ;
public:
deriver (int nmm1,int num2): base(nmm1)
{d=num2;cout<<"deriver create\n"; }
~deriver()
{ cout<<"deriver destroy\n";}
} ;
void main()
{ base *pb1,*pb2;
pb1=new base (1);
pb2=new deriver (2,3);
delete pb1;
delete pb2;
cout<< "**********\n " ;
base bobj(4);
getch();
}
运行结果如下:
base create
base create
deriver create
base destroy
base destroy
**********
base create
说明:这段程序是类的继承,构造和析构的练习,从你的程序我分析,你对C++语言的基础知识还不了解,首先C语言是严格区分大小写的,构造函数的命名应该跟类的命名要一致,析构函数前用~,而不是-,最后<iostream.h>中输出函数名是cout而不是count,使用方法是cout<<而不是count<=,多看看书,把这些先弄清楚了,对你帮助会更大
北京新国信
2023-07-11 广告
2023-07-11 广告
软件测试的流程包括以下几个方面:1. 测试需求分析阶段:这阶段主要任务是阅读需求,理解需求,对业务进行学习,并分析需求点。2. 测试计划阶段:这一阶段主要编写测试计划,参考软件需求规格说明书,项目总体计划,内容包括测试范围,进度安排,人力物...
点击进入详情页
本回答由北京新国信提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询