资源简介
分为encode.cpp和decode.cpp两个文件,运行环境为VC++6.0

代码片段和文件信息
#include
using namespace std;
#define M 100 //最大消息长度
#define N 4 //最大信源符号个数
class decode
{
private:
char symbol[N]; // 信源符号数组
char s; //用于接收信源符号的输入
long double chance[N]; //信源符号对应概率
long double c; //用于接收概率输入
long double sum; //概率和
long double code; //待译码的字段
char msg[M]; //消息内容
int length; //译码长度(译码停止标志)
int count; //实际信源符号个数
long double LowHigh; //每次区间缩减后得到的新区间
long double lowhigh;
long double wid; //信源符号概率宽度
public:
decode() //构造函数
{
sum=0;
Low=0;High=0;
}
void get_symbol();
void get_code();
void decoding();
~decode(){} //析构函数
};
//获取信源符号极其概率
void decode::get_symbol()
{
cout<<“please input the symbol and its chance:“< for(int i=0;i {
cin>>s>>c;
symbol[i]=s;
chance[i]=c;
sum+=c;
}
count=i; //将实际信源符号个数赋给count
if(sum!=1)
{
cout<<“The probability you input has mistakes!“< exit(-1);
}
}
//获取译码字和译码长度
void decode::get_code()
{
cout<<“Please input the code to decode it:“< cin>>code;
cout<<“Please input the length you want decode:“< cin>>length;
}
//算数译码过程
void decode::decoding()
{
int ij;
//判断code落在第一个区间(首区间确定)
for(i=0;i {
if(code {
msg[0]=symbol[i-1];
break;
}
else
{
Low=High;
High+=chance[i];
wid=chance[i];
}
}
//区间缩减
for(i=1;i for(j=0;j {
low=Low;
high=low+wid*chance[j];
if(high>code)
{
msg[i]=symbol[j];
Low=low; High=high; wid=High-Low;
break;
}
else
Low=high;
}
//结果输出
for(i=0;i cout< cout< }
int main()
{
decode d;
d.get_symbol(); //A 0.1 B 0.4 C 0.2 D 0.3
d.get_code(); //Java=0.5143876 C++=0.514388
d.decoding();
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-11 16:51 算术编码C++简单实现\
文件 2050 2017-04-21 17:30 算术编码C++简单实现\decode.cpp
文件 3122 2017-04-21 16:29 算术编码C++简单实现\encode.cpp
- 上一篇:进程调度算法(优先权)
- 下一篇:实现对任意格式文件压缩 C++
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- C++纯文字DOS超小RPG游戏
- VC++MFC小游戏实例教程(实例)+MFC类库
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
- C++标准库第1、2
- 大数类c++大数类
- C++语言编写串口调试助手
- c++素数筛选法
- C++ mqtt 用法
- 商品库存管理系统 C++ MFC
- c++ 多功能计算器
- C++17 In Detail
- 嵌入式QtC++编程课件
- 颜色识别形状识别STM103嵌入式代码
- c++ 邮件多附件群发
- c++ 透明代理(hookproxy)
- mfc 调用redis
- FTP客户端源码(c++)
- c++ 画图(14Qt-XPS)
- c++多边形交并差运算
- VC++基于OpenGL模拟的一个3维空间模型
评论
共有 条评论