| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY 
共有 312 人关注过本帖
标题:万分火急的求教,会的进C++简单运行结果题
收藏  订阅  推荐  打印 
yzhp518
Rank: 1
来自:广州
等级:新手上路
帖子:9
积分:196
注册:2008-3-26
万分火急的求教,会的进C++简单运行结果题

1、    写出下列程序的结果
#include <iostream.h>
Class Myclass
{
    Public:
            Myclass(int a){x=a;}
            Void fun1(){x++;}
            Void fun2(){x+=2;}
            Void fun3(){x+=3;}
            Void print(){cout<<”x=”<<x<<endl;}
    Private:
            Int x;
};
Void main()
{
    Myclass my(8);
    Void(Myclass::*pf)();
    my.print();
    pf=Myclass::fun2;
    (my.*pf)();
    my.print();
    pf=Myclass::fun3;
    (my.*pf)();
    my.print();
}
运行结果为:


2、写出下列程序的运行结果。
#include<iostream.h>
int Div(int x,int y)
{
if(y= =0)
throw y;
retrun x/y;
}
viod main()
{
try
{
cout<<"7/3="<<Div(7,3)<<endl;
cout<<"9/0="<<Div(9,0)<<endl;
cout<<"8/4=""<<Div(8,4)<<endl;
}
catch(int)
{
cout<<"Exception of dividing zero. "<<endl;
}
cout<<"It is OK."<<endl;
}

运行结果为:
搜索更多相关主题的帖子: Void  火急  Myclass  int  
2008-3-26 12:49
yzhp518
Rank: 1
来自:广州
等级:新手上路
帖子:9
积分:196
注册:2008-3-26

哪位会的前辈帮帮忙哈,谢谢了
2008-3-26 13:38
sunkaidong
Rank: 12Rank: 12Rank: 12
来自:南京师范大学
等级:版主
威望:4
帖子:4131
积分:44881
注册:2006-12-28

第一题是:8,10,13 这是一个指向类成员函数指针..看看书就好了
#include <iostream.h>
class Myclass
{
    public:
            Myclass(int a){x=a;};
            void fun1(){x++;};
            void fun2(){x+=2;};
            void fun3(){x+=3;};
            void print(){cout<<"x="<<x<<endl;};
    private:
            int x;
};
void main()
{
    Myclass my(8);
    void(Myclass::*pf)();
    my.print();
    pf=Myclass::fun2;
    (my.*pf)();
    my.print();
    pf=Myclass::fun3;
    (my.*pf)();
    my.print();
}
第二:
7/3=2
Exception of dividing zero.
It is OK.
这是个处理异常的例子...当遇到异常的时候抛出....
#include<iostream.h>
int Div(int x,int y)
{
if(y==0)
throw y;
return x/y;
}
void main()
{
try
{
cout<<"7/3="<<Div(7,3)<<endl;
cout<<"9/0="<<Div(9,0)<<endl;
cout<<"8/4="<<Div(8,4)<<endl;
}
catch(int)
{
cout<<"Exception of dividing zero. "<<endl;
}
cout<<"It is OK."<<endl;
}

学习需要安静。。海盗要重新来过。。
2008-3-26 13:58
無邪的睡脸
Rank: 3Rank: 3
来自:湖北武汉
等级:中级会员
威望:1
帖子:331
积分:3830
注册:2007-9-11

x=8
x=10
x=13

7/3=2
Exception of dividing zero.
It is OK.

不要仅为成功而努力.要为做一个有价值的人而努力
kobe24j@sina.com

2008-3-26 14:04
yzhp518
Rank: 1
来自:广州
等级:新手上路
帖子:9
积分:196
注册:2008-3-26

前辈们,这题到底是怎么做的呀?我糊涂了~~
2008-3-27 11:49
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.051238 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved