| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 832 人关注过本帖
标题:实现多态.
取消只看楼主 加入收藏
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
结帖率:78.95%
收藏
 问题点数:0 回复次数:2 
实现多态.
程序代码:
/*
标准库文件ctype.h描述的各种字符分类函数。这些函数很简单,它们对满足条件的字符返回非0值,
否则返回0值。下面是有关函数:
isalpha(c)
c是字母字符
isdigit(c)
c是数字字符
isalnum(c)
c是字母或数字字符
isspace(c)
c是空格、制表符、换行符
isupper(c)
c是大写字母
islower(c)
c是小写字母
iscntrl(c)
c是控制字符
isprint(c)
c是可打印字符,包括空格
isgraph(c)
c是可打印字符,不包括空格
isxdigit(c)
c是十六进制数字字符
ispunct(c)
c是标点符号
*/
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
typedef int (*typefun)(int);
typefun* ctype[]={isalpha,
                isdigit,
                isalnum,
                isspace,
                isupper,
                islower,
                iscntrl,
                isprint,
                isgraph,
                isxdigit,
                ispunct
               };
typedef enum {is_alpha,
             is_digit,
             is_alnum,
             is_space,
             is_upper,
             is_lower,
             is_cntrl,
             is_print,
             is_graph,
             is_xdigit,
             is_punct,
             }types;

int gettype(char str, types type);
int main(void)
{
        printf("%d",gettype('1',is_digit));
        printf("%d",gettype('a',4));

        system("pause");
        return 0;
}

int gettype(char str, types type)
{
         typefun* mytype=ctype;
         return   mytype[type](str);
}
搜索更多相关主题的帖子: 多态 
2008-01-02 11:21
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 
2008-01-02 12:36
ioriliao
Rank: 7Rank: 7Rank: 7
来 自:广东
等 级:贵宾
威 望:32
帖 子:2829
专家分:647
注 册:2006-11-30
收藏
得分:0 
知音少之又少啊...
2008-01-02 19:03
快速回复:实现多态.
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013278 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved