» دانلود سورس برنامه دیکشنری به زبان vb
چهارشنبه بیست و هشتم مرداد 1388 19:49
این برنامه دیکشنری به زبان ویژوال بیسیک نوشته شده است.
قابلیتها:
1-دیکشنری فارسی به انگلیسی و انگلیسی به فارسی
2- حذف و اضافه کردن لغت
3- ویرایش لغت
4-تلفظ و ....

» ارزش یابی عبارات ریاضی در ساختمان دادها (postfix)
دوشنبه سیزدهم خرداد 1387 23:54
ارزش یابی یک عبارت پست فیکس به صورت زیر می باشد
توضیحات :برای ارزشیابی یک عبارت به صورت postfix به صورت زیر عمل می کنیم :
ابتدا برای عملیاتمان یک ساختار داده ای پشته را تعریف می کنیم . و سپس برنامه کاراکتر به کاراکتر عبارت ورودی را میخواند اگر ورودی عملوند باشد آنرا به داخل پشته push می کنیم در غیر اینصورت یعنی در صورتی که ورودی عملگر باشد به تعداد صحیح عملوند برای عملگر مورد نظر از پشته حذف یا pop می کنیم و سپس نتیجه ی مورد نظر را به داخل پشته اضافه می کنیم .
کد زیر به زبان C++ نوشته شده است و یکی از تمرین های خودم در درس ساختمان داده ها بود. بدونه هیچ گونه تغییری براتون گذاشتمش امیدوارم به دردتون بخوره.
for Example : 23+6* ===> 2+3*6
برای درک مطلب بهتر میخواهیم برنامه ای بنویسیم که یک عبارت به صورت postfix را دریافت کند و نتیجه را برای ما محاسبه و نمایش دهدتوضیحات :برای ارزشیابی یک عبارت به صورت postfix به صورت زیر عمل می کنیم :
ابتدا برای عملیاتمان یک ساختار داده ای پشته را تعریف می کنیم . و سپس برنامه کاراکتر به کاراکتر عبارت ورودی را میخواند اگر ورودی عملوند باشد آنرا به داخل پشته push می کنیم در غیر اینصورت یعنی در صورتی که ورودی عملگر باشد به تعداد صحیح عملوند برای عملگر مورد نظر از پشته حذف یا pop می کنیم و سپس نتیجه ی مورد نظر را به داخل پشته اضافه می کنیم .
کد زیر به زبان C++ نوشته شده است و یکی از تمرین های خودم در درس ساختمان داده ها بود. بدونه هیچ گونه تغییری براتون گذاشتمش امیدوارم به دردتون بخوره.
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
this is sample of postfix expression Convert to infix in C++
For Example :Enter postfix: 234+*6* AND output: result =84
programmer : Ahmad Najafpoor
weblog :www.ahmadflasher.blogaf.com
email : ahmadflash_man@yahoo.com
Lecturer of this lesson :Mr.Vatani
Sari Technical Collage (Emam Mohammad Bagher holy)
Start programing: friday 9 May 2008 (20/2/1387) at 22:00 Pm
Finish time : saturday 10 May 2008 (21/2/1387) at 01:00 Am
/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
#include "dos.h"
#define MAX 100
/*************** Class of Stack ****************/
class stack {
public:
//****************
stack()
{
Top = -1;
}
//****************
void push(float);
float pop();
private:
int Top;
float stk[MAX];
};
//--------------- PUSH Function -------------------
void stack::push(float key)
{
stk[++Top] = key;
}
//------------ -POP function ------------------*
float stack::pop()
{
return stk[Top--];
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//------------------- list of function -----------------
int isDigit(char);
float convert(char []);
float operate(char, float, float);
//************************* MAIN ***************************
void main()
{
char postfix[MAX],Enter[100]="\n\t\t\tEnter a postfix expression:";
int i;
textbackground(1);
while(1){
clrscr();
cout<<"<--------------------------------------------------------------------------->\n";
cout<<"|\t\t Sample of Convert Postfix To Infix |\n";
cout<<"|\t\t |\n";
cout<<"|\t\t Programing By Ahmad Najafpour |\n";
cout<<"|\t\t |\n";
cout<<"|\t\t Press Any character For Exit |\n";
cout<<"<--------------------------------------------------------------------------->\n";
for(i=0; i<=32; i++){
delay(100);
cout<
}
cin>>postfix;
cout<<"\n\n Step by step of Function : ";
cout << "\n\n\n\t\t\t\tFinal Result: " << convert(postfix);
gotoxy(27,20);
cout<<" Press Any Key To Continue";
getch();
}
}
//------------------ funtion Convert postfix to infix ------------------
float convert(char postfix[])
{
float result, operand1, operand2;
char input;
stack st;
for(int i = 0; postfix[i]; i++)
{
input = postfix[i]; // new var(name) of postfix[char]
if(isDigit(input))
st.push((float)(input - '0'));
else
{
operand2 = st.pop();
operand1 = st.pop();
result = operate(input, operand1, operand2);
st.push(result);
} // end if
} //end for
result = st.pop();
return result;
}
//*------------------- is digit function -------------------
int isDigit(char input)
{
return (input >= '0' && input <= '9');
}
//----------------------- operate function ------------------
float operate(char oprator, float operand1, float operand2)
{
switch(oprator)
{
case '+':
cout<<" => ";
cout<<<'+'<<<'='<
return operand1 + operand2;
break;
case '-':
cout<<" => ";
cout<<<'-'<<<'='<
return operand1 - operand2;
case '*':
cout<<" => ";
cout<<<'*'<<<'='<
return operand1 * operand2;
case '/':
cout<<" => ";
cout<<<'/'<<<'='<
return operand1 / operand2;
}
}
End Of Program -----------------//
this is sample of postfix expression Convert to infix in C++
For Example :Enter postfix: 234+*6* AND output: result =84
programmer : Ahmad Najafpoor
weblog :www.ahmadflasher.blogaf.com
email : ahmadflash_man@yahoo.com
Lecturer of this lesson :Mr.Vatani
Sari Technical Collage (Emam Mohammad Bagher holy)
Start programing: friday 9 May 2008 (20/2/1387) at 22:00 Pm
Finish time : saturday 10 May 2008 (21/2/1387) at 01:00 Am
/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
#include "iostream.h"
#include "conio.h"
#include "stdlib.h"
#include "dos.h"
#define MAX 100
/*************** Class of Stack ****************/
class stack {
public:
//****************
stack()
{
Top = -1;
}
//****************
void push(float);
float pop();
private:
int Top;
float stk[MAX];
};
//--------------- PUSH Function -------------------
void stack::push(float key)
{
stk[++Top] = key;
}
//------------ -POP function ------------------*
float stack::pop()
{
return stk[Top--];
}
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//------------------- list of function -----------------
int isDigit(char);
float convert(char []);
float operate(char, float, float);
//************************* MAIN ***************************
void main()
{
char postfix[MAX],Enter[100]="\n\t\t\tEnter a postfix expression:";
int i;
textbackground(1);
while(1){
clrscr();
cout<<"<--------------------------------------------------------------------------->\n";
cout<<"|\t\t Sample of Convert Postfix To Infix |\n";
cout<<"|\t\t |\n";
cout<<"|\t\t Programing By Ahmad Najafpour |\n";
cout<<"|\t\t |\n";
cout<<"|\t\t Press Any character For Exit |\n";
cout<<"<--------------------------------------------------------------------------->\n";
for(i=0; i<=32; i++){
delay(100);
cout<
}
cin>>postfix;
cout<<"\n\n Step by step of Function : ";
cout << "\n\n\n\t\t\t\tFinal Result: " << convert(postfix);
gotoxy(27,20);
cout<<" Press Any Key To Continue";
getch();
}
}
//------------------ funtion Convert postfix to infix ------------------
float convert(char postfix[])
{
float result, operand1, operand2;
char input;
stack st;
for(int i = 0; postfix[i]; i++)
{
input = postfix[i]; // new var(name) of postfix[char]
if(isDigit(input))
st.push((float)(input - '0'));
else
{
operand2 = st.pop();
operand1 = st.pop();
result = operate(input, operand1, operand2);
st.push(result);
} // end if
} //end for
result = st.pop();
return result;
}
//*------------------- is digit function -------------------
int isDigit(char input)
{
return (input >= '0' && input <= '9');
}
//----------------------- operate function ------------------
float operate(char oprator, float operand1, float operand2)
{
switch(oprator)
{
case '+':
cout<<" => ";
cout<
return operand1 + operand2;
break;
case '-':
cout<<" => ";
cout<
return operand1 - operand2;
case '*':
cout<<" => ";
cout<
return operand1 * operand2;
case '/':
cout<<" => ";
cout<
return operand1 / operand2;
}
}
End Of Program -----------------//
این برنامه تست شده است
نظراتون باعث خوشحالی بنده و بهتر شدن وبلاگ می شود
نظراتون باعث خوشحالی بنده و بهتر شدن وبلاگ می شود

