اگر با انگلیسی مشکلی نداری تو سایت بوکتولرن دات کام چیرای خوبی پیدا میکنی که خودمم ازش کتابای زیادی دارمنقل قول:
Sent from my Nexus 4 using Tapatalk
Printable View
اگر با انگلیسی مشکلی نداری تو سایت بوکتولرن دات کام چیرای خوبی پیدا میکنی که خودمم ازش کتابای زیادی دارمنقل قول:
Sent from my Nexus 4 using Tapatalk
انگلیسیم ضعیفه ولی خب بفکرش هستم که تقویتش کنم . از اینترنت کتاب دکتر احمد فراهی رو دانلود کردم . فک کنم این هم راحته هم کامله .نقل قول:
من این کتابرو خوندم اخراش یه سری سولا داره با اینکه چندبارخوندم ولی اخر نفهیدم . جوابشو .. اگه اشکال نداره جواب بدین . سی پلاس پلاس هستش ممنون .
7- اگه m و n از نوع short باشند و m=6 و n=4 حاصل m/n میشود با :
ممنون میشم با دلیل بگین.
حاصل تقسیم m و n می شه از جنس int. مقدار int هم اعشار نداره. پس می شه برابر
جزء صحیح m/n مساوی 1
تو محاسبات اعشاری خروجی برابر دقت بالاترین عملونده. بنابراین اگه یکی از m و n از جنس float و اون یکی از جنس int باشه، خروجی float می شه.
ممنون . نمیدونم چرا چیزی نمیفهمم ؟ فک کنم ضقعم تو نشناختن نوع مغیر ایناس ؟نقل قول:
خوب شد گفتی فهمیدم خودمم بلد نیستم درست باید بپرسمنقل قول:
Sent from my Nexus 4 using Tapatalk
یعنی چی ؟نقل قول:
دوستان ممنون میشم به این تابپیک سر بزنید .
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
خوب من یه خورده جامع تر توضیح می دم. در مورد متغیر ها هم توضیح می دم، که احتمالا بلدید:نقل قول:
وقتی یه متغیر توی برنامه تعریف می کنیم، این متغیر به صورت چند بایت پشت سر هم نگه داشته می شه. مثلا وقتی من یه متغیر از جنس short تعریف می کنم، توی کامپیوتر من این متغیر 2 بایت فضا می گیره و وقتی یه متغیر ازنوع long تعریف می کنم، توی کامپیوتر من 4 بایت فضا می گیره.
مزیت این 4 بایت نسبت به 2 بایت اینه که توی 2 بایت می شه اعداد بین –32,768 تا 32,767 رو نگه داشت. اما توی 4 بایت اعداد بین –2,147,483,648 تا 2,147,483,647 رو می شه نگه داشت. این برای ما مزیت داره، چون وقتی بخوایم اعداد بزرگ رو ذخیره کنیم از یه نوع متغیر و برای ذخیره اعداد متوسط از یه نوع دیگه از متغیر ها استفاده می کنیم.
یه نکته دیگه اینه که انواعی مثل int و long و short به صورتی داخل رایانه ذخیره می شن که اعداد اعشاری رو نمی تونن نگه دارن. برعکس انواعی مثل float و double برای نگه داشتن اعداد اعشاری در نظر گرفته شدن.
...
خب. وقتی یه عملیات ریاضی رو روی دو تا متغیر انجام می دیم کامپیوتر به صورت موقت متغیر کوچکتر رو به نوع متغیر بزرگتر تبدیل می کنه و عملیات رو انجام می ده.
مثلا ممکنه متغیر ها یه این شکل باشن:
[PHP]short a = 10;long b = 10000000;[/PHP]
در این صورت قبل از انجام عملیات a هم به نوع long تبدیل می شه، محاسبه انجام می شه و نتیجه ای هم از نوع long تولید می شه.
(البته در صورتی که هر دو متغیر از نوعی کوچکتراز int باشن هم هر دو به int تبدیل می شن)
...
برای اطلاعات بیشتر
قواعد دقیقی که استاندارد C++ برای تبدیل ها تعریف کرده به شکل زیر هستن:
- If either operand is of type long double, the other operand is converted to type long double.
- If the above condition is not met and either operand is of type double, the other operand is converted to type double.
- If the above two conditions are not met and either operand is of type float, the other operand is converted to type float.
- If the above three conditions are not met (none of the operands are of floating types), then integral conversions are performed on the operands as follows:
- If either operand is of type unsigned long, the other operand is converted to typeunsigned long.
- If the above condition is not met and either operand is of type long and the other of typeunsigned int, both operands are converted to type unsigned long.
- If the above two conditions are not met, and either operand is of type long, the other operand is converted to type long.
- If the above three conditions are not met, and either operand is of type unsigned int, the other operand is converted to type unsigned int.
- If none of the above conditions are met, both operands are converted to type int.
ممنون قشنگ فهمیدم. مشکلم موقع انجام عملیاتو بود که با توضیحاتتون حل شد واقعا مرسینقل قول:
سلام، فردا باید کد زیرو ببرم به استادمون تحویل بدم و زیاد ازش سر در نمیارم.
داشتم با نا امیدی تو اینترنت سرچ میکردم که به سایت شما برخوردم و دقیقا یه نفر قبلا در مورد اون توضیح خواسته بود..
اگه کسی هست کمکم کنه.:n03::n28:..
مخصوصا در مورد قسمت coding به بعد تو ضیح لازم دارم...
کد در مورد درخت هافمن:
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
class treenode{
public:
int data;
int num;
treenode *next;
treenode *right;
treenode *left;
}*start=NULL,*end=NULL,*p;
class code{
public:
char bcode[12];
int ch;
}coding[256];
class tree{
public:
int data;
int num;
}atree[512];
int o=0;
int search(int i);
void insert(int i);
void insertm(class treenode *l);
void sort();
void create();
void binary(class treenode *n,char byte[],int i);
int searchc(int i);
void write();
void read();
void tree(class treenode *n,int i);
int numnode=0;
int numchar=0;
char filename[25];
void main()
{
FILE *fp1,*fp2;
cout<<"**** haffman ****"<<endl<<endl<<"Enter The Location And Name Of The Source File To Compress : ";
cin>>filename;
fp1=fopen(filename,"r+b");
if (fp1==NULL)
{
cout<<endl<<"Error In Open File...";
getch();
exit(1);
}
int i=getc(fp1);
while (i!=-1)
{
numchar++;
if (search(i)==-1)
insert(i);
i=getc(fp1);
}
fclose(fp1);
sort();
create();
char byte[20]={0};
binary(start,byte,0);
tree(start,1);
write();
cout<<"\n\nComplete Succssfuly Coding To Code.txt\n";
read();
cout<<"Complete Succssfuly Encoding To Decode.txt";
getch();
}
//*************************search******************* ***********
int search(int i)
{
class treenode *h;
h=start;
while(h)
{
if (h->data==i)
{
h->num=h->num+1;
return 0;
}
h=h->next;
}
return -1;
}
//**************************insert****************** ************
void insert(int i)
{
p=new treenode;
p->data=i;
p->num=1;
p->right=p->left=p->next=NULL;
if (start==NULL)
{
start=p;
end=p;
}
else
{
end->next=p;
end=p;
} }
//******************************Sort**************** ***
void sort()
{
class treenode *h1,*h2,*n2,*right,*left;
int d,n;
n2=start;
while(n2)
{ h1=start;
h2=start->next;
while(h2)
{
if (h1->num > h2->num)
{
d=h1->data;
n=h1->num;
right=h1->right;
left=h1->left;
h1->data=h2->data;
h1->num=h2->num;
h1->right=h2->right;
h1->left=h2->left;
h2->data=d;
h2->num=n;
h2->right=right;
h2->left=left;
}
h1=h2;
h2=h2->next;
}
n2=n2->next;
} }
//****************Create**************************** ***
void create()
{
class treenode *h;
while (start->next)
{
int i1,i2;
p=new treenode;
p->left=start;
p->right=start->next;
p->num=start->num+start->next->num;
p->data=-1;
p->next=NULL;
h=start;
start=start->next->next;
h->next->next=NULL;
h->next=NULL;
insertm(p);
sort();
}}
//********************Insertm*********************** *****
void insertm(class treenode *l)
{
if (start==NULL)
{
start=l;
end=l;
}
else
{
end->next=l;
end=l;
} }
//********************Binary************************ ****
void binary(class treenode *n,char byte[],int i)
{
if (n->data==-1)
{
char b1[20]={0},b2[20]={0};
strcpy(b1,byte);
strcpy(b2,byte);
b1[i]='1';
binary(n->right,b1,i+1);
b2[i]='0';
binary(n->left,b2,i+1);
}
else
{
cout<<"Char :"<<(char)n->data<<" Byte : "<<byte<<"\n";
strcpy(coding[o].bcode,byte);
coding[o++].ch=n->data;
}
}
//*********************Coding*********************** ********
void write()
{
FILE *fp1,*fp2;
fp1=fopen(filename,"r+b");
fp2=fopen("Code.txt","w+b");
//************************************************** ************
int i=1;
while (i<=numnode)
{
fprintf(fp2,"%d",atree[i].data);
i++;
}
//************************************************** ***************
i=getc(fp1);
int j=0,place=1;
unsigned char bytebuf=0;
while (i!=-1)
{
j=searchc(i);
int y=0;
while (coding[j].bcode[y]) {
if (coding[j].bcode[y]=='1')
bytebuf |= place;
if (place==128)
{
putc(bytebuf,fp2);
place=1;
bytebuf=0;
}
else
place<<=1;
y++;
}
i=getc(fp1);
}
if (place<=128 && place !=1) putc(bytebuf,fp2);
fclose(fp1);
fclose(fp2);
}
//********************searchcode******************** *******
int searchc(int i)
{
int j=0;
while (j<o)
if (coding[j].ch==i)
return j;
else
j++;
}
//**********************Encode********************** *******
void read()
{
FILE *fp1,*fp2;
fp1=fopen("Decode.txt","w+b");
fp2=fopen("Code.txt","r+b");
//************************************************
int i=1,a;
while (i<=numnode)
{
fscanf(fp2,"%d",&a);
i++;
}
//************************************************
i=getc(fp2);
int j=0,place=1;
class treenode *n;
unsigned char bytebuf=0;
while (i!=-1)
{
n=start;
while (n->data==-1)
{
int x=(place & i)?1:0;
if (x==1)
n=n->right;
else
n=n->left;
if (place==128)
{i=getc(fp2);
place=1; }
else
place<<=1;
}
if (j++<numchar)
putc(n->data,fp1);
}
fclose(fp1);
fclose(fp2);
}
//************************************************** *******
void tree(class treenode *n,int i)
{
atree[i].data=n->data;
atree[i].num=n->num;
numnode=i;
if (n->left!=NULL)
tree(n->left,2*i);
if (n->right!=NULL)
tree(n->right,2*i+1);
}