1.vcԴ?源码??ȫ
2.求vc写的直接从一个网站上下载exe程序得源代码!
3.急求VC源代码
vcԴ???ȫ
哈弗曼压缩
#include <string.h>
#include <stdlib.h>
#include<iostream.h>
#include<fstream.h>
#define MaxNodes
#define MaxBufSize
#define MaxBits
struct Node
{
unsigned char b;
int count;
int parent,lch,rch;
char bits[MaxBits];
}Nodes[MaxNodes];
ifstream ifile;
ofstream ofile;
char *fname=new char();
unsigned char c;
char buf[MaxBufSize];
int flen;
int NodesNum;
void decompress();
void compress();
void charCount();
void initNodes();
void creatHuffTree();
void huffCoding();
void sortByCount();
int FindMin(int curlen);
void comToFile();
void decomToFile();
void clearSDS();
void locChar(int loc,int i);
void main()
{
char choice;
while(1)
{
cout<<" ------------------------------------------------------"<<endl;
cout<<" # 0.退出 #"<<endl;
cout<<" # 1.压缩 #"<<endl;
cout<<" # 2.解压 #"<<endl;
cout<<" ------------------------------------------------------"<<endl;
do
{
cout<<"请选择:"<<endl;
cin>>choice;
if(choice!='0' && choice!='1' && choice!='2')
{
cout<<"输入出错!请重新输入!大全"<<endl;
}
}
while(choice!='0' && choice!='1' && choice!='2');
switch(choice)
{
case '0':cout<<"成功退出!源码"<<endl;exit(0); break;
case '1':compress();break;
case '2':decompress();break;
}
}
}
void compress()
{
cout<<"请输入待压缩的大全源码贴码刮码文件名:";
cin>>fname;
ifile.open(fname,ios::nocreate|ios::binary);
if(!ifile)
{
cout<<"文件不存在!"<<endl;
return;
}
charCount();
initNodes();
sortByCount();
creatHuffTree();
huffCoding();
cout<<"请输入压缩后的文件名:";
cin>>fname;
ofile.open(fname,ios::binary);
ofile.write((char*)&NodesNum,sizeof(NodesNum));
ofile.write((char*)&flen,sizeof(flen));
for(int i=0;i<NodesNum;i++)
{
ofile.write((char*)&Nodes[i].b,sizeof(Nodes[i].b));
ofile.write((char*)&Nodes[i].count,sizeof(Nodes[i].count));
}
comToFile();
ifile.close();
ofile.close();
clearSDS();
}
void decompress()
{
clearSDS();//不加此句,关闭程序再解压,源码会提示BUF出错
cout<<"请输入待解压的大全星辰奇缘突破源码文件名:";
cin>>fname;
ifile.open(fname,ios::nocreate|ios::binary);
if(!ifile)
{
cout<<"文件不存在!"<<endl;
return;
}
ifile.read((char*)&NodesNum,sizeof(NodesNum));
ifile.read((char*)&flen,sizeof(flen));
cout<<NodesNum<<" "<<flen<<endl;
for(int i=0;i<NodesNum;i++)
{
ifile.read((char*)&Nodes[i].b,sizeof(Nodes[i].b));
ifile.read((char*)&Nodes[i].count,sizeof(Nodes[i].count));
}
creatHuffTree();
cout<<"请输入解压后的文件名:";
cin>>fname;
ofile.open(fname);
decomToFile();
ifile.close();
ofile.close();
clearSDS();
}
void clearSDS()//SDS is short for Shared Data Structure
{
NodesNum=flen=c=0;
for(int i=0;i<MaxNodes;i++)
{
Nodes[i].b=0;
Nodes[i].count=0;
Nodes[i].parent=Nodes[i].lch=Nodes[i].rch=-1;
buf[i]=0;
for(int j=0;j<MaxBits;j++) Nodes[i].bits[j]=0;
}
}
void comToFile()
{
ifile.clear();
ifile.seekg(0);
char tbuf[]="";
while(ifile.get(c))
{
for(int i=0;i<NodesNum;i++)
{
if(c==Nodes[i].b)
{
strcat(buf,Nodes[i].bits);
break;
}
}
while(strlen(buf)>=8)
{
memcpy(tbuf,buf,8);
c=(char)strtol (tbuf,NULL,2);
memmove(buf,buf+8,strlen(buf)+1-8);
ofile.write((char*)&c,sizeof(c));
}
}
if(strlen(buf)>0)//剩余
{
strcat(buf,"");//最多接7个0即可
memcpy(tbuf,buf,8);
c=(char)strtol (tbuf,NULL,2);
ofile.write((char*)&c,sizeof(c));
}
}
void decomToFile()
{
while (ifile.get(c)) //while(!ifile.eof()),老样子
{ //ifile.read((char*)&c,sizeof(c));
char tbuf[]="";
char rbuf[]="";
itoa((int)c,rbuf,2);
strcpy(tbuf+8-strlen(rbuf),rbuf);
memmove(buf+strlen(buf),tbuf,8);//末尾会多一个tbuf,无碍
while(strlen(buf)>&&flen>0) locChar(2*NodesNum-2,源码0);
}
while(strlen(buf)>0&&flen>0) locChar(2*NodesNum-2,0);
}
void locChar(int loc,int i)//递归得出字符
{
if((Nodes[loc].lch==-1)&&(Nodes[loc].rch==-1))
{
ofile.write((char*)&Nodes[loc].b,sizeof(Nodes[loc].b));
flen--;
//memmove(buf,buf+i,strlen(buf)-i+1);
//memmove(buf,buf+i,-i);//Very improtant code modified at here!
memcpy(buf,buf+i,-i);//Same result Like the line Above!Maybe not effective
return;
}
else
{
switch( buf[i])
{
case '0': loc=Nodes[loc].lch;break;
case '1': loc=Nodes[loc].rch;break;
default: cout<<"buf中出错!"<<endl;break;
}
i++;
locChar(loc,大全i);
}
}
void charCount()//统计字符出现次数
{
while(ifile.get(c))
{
Nodes[c].count++;
flen++;//得出文件长度
}
}
void initNodes()//初始化
{
for(int i=0;i<MaxNodes;i++)
{
if(Nodes[i].count!=0)
Nodes[i].b=(unsigned char)i;
else Nodes[i].b=0;
Nodes[i].parent=Nodes[i].lch=Nodes[i].rch=-1;
}
}
void creatHuffTree()//建树
{
int t=2*NodesNum-1;
for(int i=NodesNum;i<t;i++)
{
int loc=FindMin(i);
Nodes[i].count=Nodes[loc].count;
Nodes[loc].parent=i;
Nodes[i].lch=loc;
loc=FindMin(i);
Nodes[i].count+=Nodes[loc].count;
Nodes[loc].parent=i;
Nodes[i].rch=loc;
}
Nodes[t-1].parent=-1;
}
int FindMin(int curlen)//找没有父结点,且Count最小的源码节点
{
int loc=curlen-1;//找不到,返回最后一个,大全最后一个不在查找范围
for(int i=0;i<curlen;i++)
{
if(Nodes[i].count<=Nodes[loc].count)
{
if(Nodes[i].parent==-1)
loc=i;
}
}
return loc;
}
void huffCoding()//根据树来编码
{
int Pid,源码t;//Parent id
for(int i=0;i<NodesNum;i++)
{
t=i;
while(Nodes[t].parent!=-1)
{
Pid=Nodes[t].parent;
if(Nodes[Pid].lch==t) //置左分支编码0
{ //函数原型:void *memmove( void *dest, const void *src, size_t count );
memmove(Nodes[i].bits+1,Nodes[i].bits,strlen(Nodes[i].bits)+1);
Nodes[i].bits[0]='0';
}
else //置右分支编码1
{
memmove(Nodes[i].bits+1,Nodes[i].bits,strlen(Nodes[i].bits)+1);
Nodes[i].bits[0]='1';
}
t=Pid;
}
}
}
//降序
void sortByCount()
{
Node tempNode;
for(int i=0;i<MaxNodes;i++)
for(int j=MaxNodes-1;j>i;j--)
{
if(Nodes[i].count<Nodes[j].count)
{
tempNode=Nodes[i];
Nodes[i]=Nodes[j];
Nodes[j]=tempNode;
}
}
for(i=0;i<MaxNodes;i++) if(Nodes[i].count==0) break;
NodesNum=i;//关键得出有效叶子结点个数NodesNum
}
求vc写的直接从一个网站上下载exe程序得源代码!
首先引入头文件#include"afxinet.h"。使用函数BOOL GetFromWeb(LPSTR pURL,大全LPSTR SaveAsFilePath)进行操作。
其中,源码iapp源码导入软件参数pURL为URL路径,大全SaveAsFilePath为保存路径。源码初始化CInternetSession session;作为会话期对象,spring扩展点源码CHttpConnection *pServer=NULL;指向服务器地址(URL),CHttpFile *pHttpFile=NULL;为HTTP文件指针。
定义CString strServerName;为服务器名,htmlcss登录页面源码CString strObject;为查询对象名(会话。if(pHttpFile!=NULL) delete pHttpFile; if(pServer!=NULL) delete pServer; session.Close(); return TRUE;
至此,从指定网站下载exe程序的源代码的过程完成。通过调用该函数并传入URL和保存路径即可实现。
急求VC源代码
(1)
#include<iostream>
using namespace std;
int main()
{
float num1,num2;
char ch;
begin:
cout<<"请输入第1个数:\n";
cin>>num1;
cout<<"请输入运算符:\n";
cin>>ch;
cout<<"请输入第2个数:\n";
cin>>num2;
switch(ch)
{
case '+':
cout<<"结果:"<<num1+num2<<endl;
break;
case '-':
cout<<"结果:"<<num1-num2<<endl;
break;
case '*':
cout<<"结果:"<<num1*num2<<endl;
break;
case '/':
if(int(num2)!=0)
{
cout<<"结果:"<<num1/num2<<endl;
}
else
{
cout<<"除数不能为0,请重新输入.\n";
goto begin;
}
break;
default:
cout<<"你输入的运算符错误,请重新输入.\n";
goto begin;
}
getchar();
return 0;
}
(2)
#include <iostream>
#include<string>
using namespace std;
int main()
{
char num1[];
char num2[];
char ch;
int n=0;
int i=0;
float count=0;
string inStr;
begin:
cout<<"请输入:";
cin>>inStr;
memset(num1,0,);
memset(num2,0,);
for(i=0; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num1[i]=inStr[i];
}
}
ch=inStr[i];
i++;
for(; inStr[i]!='\0'; i++)
{
if(inStr[i]=='+' ||inStr[i]=='-' ||inStr[i]=='*' ||inStr[i]=='/' )
{
break;
}
else
{
num2[n]=inStr[i];
n++;
}
}
switch(ch)
{
case '+':
count=float(atoi(num1))+float(atoi(num2));
break;
case '-':
count=float(atoi(num1))-float(atoi(num2));
break;
case '*':
count=float(atoi(num1))*float(atoi(num2));
break;
case '/':
if(atoi(num2)!=0)
{
count=float(atoi(num1))/float(atoi(num2));
}
else
{
cout<<"除数不能为0"<<endl;
goto begin;
}
break;
}
cout<<"结果是:"<<count<<endl;
}
祝你好运了!!!!!!!!!!!!!