:: یک کامپایلر خوب برای C++
DevC++ For Windows
What is DevC++
DevC++ is a full-featured integrated development environment (IDE) that uses the MinGW version of C++. An IDE is a program that allows you to edit, compile, and debug your C++ programs without using the command-line. For those of you who prefer to use your own editor.
DevC++ comes with everything you need to compile and link both console-mode and GUI programs that will run on Windows 95/98/NT/2K/XP; your programs will not run on Windows 3.1 or on plain DOS machines however. You don't need to download and install anything else.
The rest of this page will walk you through the steps necessary to download, install, and run your C++ programs using DevC++ and the included version of the MinGW C++ compiler.
Step 1: Download DevC++
AClick the link below to download DevC++ 5 from www.download.com :
دانلود این برنامه (حجم دانلود ۱۲ مگابایت ) :
http://www.download.com/3001-2069_4-1683220.html
CWhen the download dialog (below) appears, click Save,rather than Open:
DSave the file in a download or temporary directory on your local machine. (Be sure to remember where you put it!).
The downloaded file is about 12.5 MB; on a DSL connection it takes under 5 minutes to download. On a dial-up connection, though, downloading may take a while. In that case, you may want to copy the installation files from the Q: drive in the Computing Center, on to a CD or to a USB thumb-drive.
Step 2: Install DevC++
AUsing Windows Explorer, locate the file you downloaded, check it's size to make sure that the download didn't stop prematurely, and then double-click it:
BClick OK when the Welcome dialog appears, as shown here:
CRead through the license and then click I Agree to install:
DevC++ is released under the GNU Public License, (GPL), which allows you to obtain and modify the source code to the compiler and IDE. If you do so, then the changes you make must also be released under the GPL. However, the programs you create with MinGW don't normally link with GPL libraries, so you are free to distribute the programs you write using DevC++ and MinGW in any way you wish.
DSelect a folder where you would like to install DevC++. It's best if you don't use a folder that contains spaces, (such as "Documents and Settings"). As you can see here, I've created a folder named bin, where I install all of the programs that I use. Click Install once you've selected a folder:
EHere's the dialog that is displayed while the files are decompressed and installed :
FOnce the files are copied, click Close to finalize the installation:
Step 3: Configure the IDE
The first time you use DevC++ you'll want to configure it to your use. (You'll need to do this the first time you use DevC++ in the Computing Center as well.)
ASelect the language and theme that you want to to use. Don't worry if you make a mistake, since you can modify your selection later:
BConfigure the Environmental Options:
Change to the Files & Dir tab, and then click the little button to the right of User's Default Directory text field. (You can't type directly in the field.)
Locate the folder where you want to store your files. In the example shown here, I've selected the C:\docs\CS250 folder on my local machine. If you are working in the lab, create a CS250 folder on the U: drive. This is the folder where you'll store your files:
CConfigure the Editor Options :
Feel free to change whatever items you like. The only one that I really want is to have line numbers displayed. To do this, select the Display tab, and click the Line NUmbers checkbox, as shown here:
DConfigure the Compiler Options :
On the Compiler tab, add the following switches when calling the compiler:
Note that the W in Wall is capitalized, but everything else is lowercase. Here's what this tab should look like:
On the Settings tab, choose Code Generation, and change Enable exception handling to Yes, as shown here:
While still on the Settings tab, choose Linker and change Generate debugging information to Yes as shown here:
Step 4 : Compile, Link, and Run
Here are the instructions to edit, compile, link, and run, a simple 3-file C++ project, based on a simple stock program from pages 416-419 in the C++ Primer Plus, 4th Edition.
ACreate a new project. You'll want to create a new project for every program, simply because it helps you to keep your files straight, and makes your life less confusing:
Choose Empty Project from the New Project dialog. Provide a name, (HW01 in the shot shown here), and click OK:
DevC++ will drop you in the folder you specified when you configured the Environmental Options in Step 3. Unlike Microsoft's Visual Studio, DevC++ doesn't automatically create a new folder for every project. Since you don't want all of your files in the same folder--especially in this class, where you'll create several different versions of the same files--you should Create a New Folder to store your project, as shown here:
Navigate to the new folder, and save the project file (HW01.dev in the screenshot shown here:
BCreate your source code files. Start by right-clicking the project in the Project tab, and then choosing New File as shown here:
This creates an Untitled file. Click Save, (or press Control+S), and provide a name, as shown here:
Repeat the project with each file in your project. Once you've created all of the files, you can type in the source code using the editor. The screenshot here shows the three source files in the project, after all of the code has been entered:
CBuild the Project. DevC++ doesn't have separate Compile and Build settings, like some development environments. When you click the Compile button, (or press Control+F9), all of the C++ files in the project are compiled (if necessary), and the linker creates the executable program:
As your program is being compiled, you'll see a progress dialog showing the individual steps:
At the bottom of the screen, you'll also see a set of tabs that allow you to see the actual commands sent to the MinGW compiler, just as if you typed them from the command line:
DRun the Program. To run the program, you can select the Run toolbar button, as shown here, or press Control+F10.
Unfortunately, when you do that, the program opens a Command Prompt window, runs your program, and then immediately closes the window before you can examine the output.
To get the window to "stick around", you can add a command:
at the end of your main() function. If you do this, remember to remove the line before you submit your code, otherwise it won't run correctly.
A better solution, though, is to set a breakpoint at the end of your main() function, and then Debug the program instead of Running it. Simply click in the margin as shown here:
Start the program by clicking the Debug toolbar button (shown here), or by pressing F10:
A Command Prompt window will display the output of your program, and then stop on the breakpoint, leaving the command window open like this:
To close the output window, choose the Debug tab at the bottom of the DevC++ IDE, and click on Continue. This will close the console window.
سلام دوباره به همه ی شما عزیزان
برنامه ای که در زیر کد آنرا مشاهده می کنید بسیار ساده و تا حدی کاربردی هست . این برنامه بصورت داینامیک زمان و تاریخ را نمایش می دهد که می تواند در اکثر پروژهای دانشگاهی از آن استفاده کرد .
در آینده نزدیک چگونگی برنامه نویسی لیست های پیوندی(
Linked List) , (Stack ), صف (Queue) را برایتان خواهم گفت . اگر پیشنهادی هم داشتید ایمیل بزنید ./*
Name: Dynamic Time and Date
Copyright: Free
WebSite : http://cpp.blogfa.com
Mail : cpp.blogfa@gmail.com
Author: Pezhman Roudkhaneei
Date: 29/10/05 11:56 PM
Description: This Program show Dynamic Current Time
*/
#include
#include
#include
#include
{
textmode(C80);
time_t curtime; // Define a Varible of type time_t.
clrscr(); // for Clear Screen.
textcolor(10); // Change Text Color into Green .
while (!kbhit()){ /* This Loop will Continue until
when press a key of Keyboard. */
time(&curtime); // For Geting Current Date & Time .
gotoxy(1,1); // For Change location of the cursor .
cprintf("Currnet Date and Time is : %s\n",ctime(&curtime));
delay(1000); // Delay about 1 second.
}
return 0;
}
شرمنده از اينکه دير وبلاگ رو آپديت مي کنم . الان هم که يه مدت گرفتار شدم , کلي از اطلاعات هاردمو از دست دادم فعلاً در حال بر گردوندن اطلاعات هستم.
در ضمن مي خوام از اين به بعد وبلاگ رو زوودتر آپديت کنم , فعلا هم يه برنامه واستون گذاشتم تا دانلود کنيد . اين برنامه تمام اعمال مربوط به ايجاد درخت (Tree) , پیمایش درخت بصورت inorder , preorder postorder و جستجوی باینری با استفاده از ليست پيوندي مي باشد که من ترم پيش واسه درس ساختمان داده نوشتم اين برنامه اعمال زير را که در عکس مشخص است انجام مي دهد.

برای دانلود این برنامه اینجا کلیک کنید
با سلام , امروز می خواهم چند تابع جدید را به شما معرفی کنم :
1. clreol : این تابع تمام کاراکترها که بعد از مکان نما قرار دارد را تا آخر آن خط پاک میکند بدون آنکه موقعیت مکان نما تغییر کند . علت اینکه من از تابع cptintf در مثال زیر استفاده کردم این است که توابع clreol - clrscr و getch هر سه در کتابخانه Conio.H هستند و تابع cprintf هم در این کتابخانه است و دیگر از printf استفاده نکردم همچنین یکی دیگر از مزیت های cprintf این است که برای چاپ text های رنگی در خروجی از این تابع استفاده می شود , در حالیکه printf چنین امکانی را در اختیارمان قرار نمی دهد . در زیر مثالی ارائه شده تا مفهوم تابع clreol را بهتر متوجه شوید :
#include
{
clrscr();
textcolor(10);
cprintf("The function CLREOL clears all characters from the\r\n");
cprintf("cursor position to the end of the line within the\r\n");
cprintf("current text window, without moving the cursor.\r\n");
cprintf("Press any key to continue . . .");
gotoxy(14,4);
getch();
clreol();
getch();
return 0;
}
2 . delline : این تابع سبب می شود که خطی که مکان نما (Cursor) در آن قرار دارد حذف شود . برای تفهیم بیشتر به مثال زیر توجه کنید :
#include
int main(void)
{
clrscr();
textcolor(12);
cprintf("The function DELLINE deletes the line containing the\r\n");
cprintf("cursor and moves all lines below it one line up.\r\n");
cprintf("DELLINE operates within the currently active text\r\n");
cprintf("window. Press any key to continue . . .");
gotoxy(1,2); /* Move the cursor to the second line and first column */
getch();
delline();
getch();
return 0;
}
3 . insline : با استفاده از این تابع می توان یک خط خالی در بالای مکانی که مکان نما قرار دارد ایجاد کرد . به مثال زیر توجه کنید :
{
clrscr();
textcolor(12);
cprintf("The function DELLINE deletes line containing the\r\n");
cprintf("cursor and moves all lines below it one line up.\r\n");
cprintf("DELLINE operates within the currently active text\r\n");
cprintf("window. Press any key to continue . . .");
gotoxy(1,2); /* Move the cursor to the second line and first column */
getch();
delline();
getch();
return 0;
}
(*) Header هر سه تابع بالا
4 . textmode : این تابع نوع نمایش text در صفحه نمایش را کنترل می کند . مقادیر قابل پذیرش این تابع را در جدول زیر مشاهده می کنید .
|
ثابت |
مقدار عددی |
نوع حالت | |
|
LASTMODE |
-1 |
Previous text mode |
40 columns |
|
BW40 |
0 |
Black and white |
40 columns |
|
C40 |
1 |
Color |
80 columns |
|
BW80 |
2 |
Black and white |
80 columns |
|
C80 |
3 |
Color |
80 columns |
|
MONO |
7 |
Monochrome |
43 columns |
|
C4350 |
64 |
EGA and VGA |
50 columns |
:: چگونگی عملکرد این تابع را میتوانید در مثال زیر ببینید :
#include
{
clrscr();
textmode(BW40);
textcolor(12);
cprintf("Textmode >>>> (BW40)");
getch();
textmode(BW80);
textcolor(10);
cprintf("Textmode >>>> (BW80)");
getch();
textmode(C40);
textcolor(11);
cprintf("Textmode >>>> (C40)");
getch();
textmode(MONO);
textcolor(14);
cprintf("Textmode >>>> (MONO)");
getch();
return 0;
}
:: معرفی چند تابع برای تبدیل انواع داده ها :
|
نام تابع |
شرح وظیفه |
Header مورد نیاز |
| atof |
برای تبدیل یک رشته به عدد اعشاری |
|
| Atoi |
تبدیل رشته به عددی از نوع Integer |
|
| Atol |
تبدیل رشته به عددی از نوع Long |
|
| ecvt and fcvt |
تبدیل عدد اعشاری به رشته |
|
| gcvt |
تبدیل عدد اعشاری به رشته |
|
| strtod |
تبدیل رشته به عدد اعشاری از نوع Double |
|
| strtol |
تبدیل رشته به عددی از نوع Long |
|
| _strtold |
تبدیل رشته به long double |
|
| strtoul |
تبدیل رشته به unsigned long |
|
شاید برای خیلی از شما دوستان پیش آمده باشد که بخواهید در برنامه هایی که با زبانهایی مثل Q-Basic یا ++C / C و یا Pascal می نویسید پیام ها و یا منوها فارسی باشند خوب این کار , کار مشکلی نیست فقط کافیست مراحل زیر را به درستی انجام دهید . خوب ابتدا چند برنامه ی فارسی ساز DOS را به شما معرفی میکنم 1. Vegaf.com : که این برنامه فقط محیط داس را آماده نمایش برنامه هایی میکند که زبان فارسی نوشته شده اند 2. ُSepand : توسط این برنامه می توانید مستقیماً در محیط برنامه نویسی فارسی تایپ کنید (مثلا هر وقت می خواهید که فارسی بنویسید کافیست که کلید Scroll Lock از کیبرد را فعال کنید) 3. برنامه F.com : این برنامه هم تمام کارهای Sepand را انجام می ده ( خوب جالب بدانید که نویسنده دو برنامه اخیر یعنی Sepand و F.com یک نفر است یعنی وحید علیمردانی ) خوب لینک دانلود این برنامه ها رو هم براتون گذاشتم برای در یافت اینجا کلیک کنید.
در ضمن در اینجا هم یه روشی رو بهتون مگم تا هر وقتی که ویندوز بالا میاد محیط داس فارسی باشه یعنی قابلیت نمایش متن های فارسی رو داشته باشه و به اصطلاح فونتها خرچنگ قورباغه نباشه برای این کار از منوی Start روی Run کلیک کنید و در کادر ورودی cmd را تایپ کرده و Ok کنید ( منظورم این است که وارد Dos Prompt شوید ) حالا فرمان های زیر را در خط فرمان بنویسید :
Drive:\ ......\ .....>cd\
drive:\>c:
c:\>edit c:\Autoexec.bat
در این حالت محیط ویرایش DOS ظاهر می شود خوب در آخرین خط رفته و در یک خط خالی مسیر ی را که فایل Vegaf.com در آن قرار دارد را در آن تایپ کنید( مانند زیر ) , بهتر است که آن فایل را در درایو C کپی کنید اکنون تغییرات اعمال شده را ذخیره کرده و خارج شوید .
c:\vegaf.com
خوب در اینجا یک بار سیستم را Restart کنید . بعد از بالا آمدن سیستم Dos فارسی شده است ( همانطور که میدانیم محتویات فایل Autoexec.bat در هر بار بالا آمدن سیستم اجرا می شود )
خوب حالا می رسیم که چطور تو محیط برنامه نویسی مورد نظر فارسی بنویسیم : باید قبل از اینکه وارد زبان برنامه نویسی مورد نظر شوید یکی از فارسی نویسهای Sepand و F.com را اجرا کنید و بدون اینکه از Dos خارج شوید پاسکال,سی و یا هر و یا هر زبان دیگر را اجرا کنید ( برای اینکه در Dos راحتر کار کنید از برنامه معروف NC استفاده کنید )
با همین چند خط کد کوتاه اشکال زیبایی در محیط گرافیکی ایجاد می شود
Program 1 :
/*
########################################
# WWW : cpp.blogfa.com #
# Released on July 2005 #
########################################
*/
//Essential Library
#include
#include
#include
#include
{
int gdriver = DETECT;
int gmode,errorcode,a,b,s;
float k,x,y,i,j;
float pi = 3.14159;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
errorcode = graphresult();
if ( errorcode != grOk)
{
exit(1);
}
s = 0;
setcolor(12);
do {
i = 38+100*cos(pi*s/190);
j = 175+100*sin(pi*s/190);
x = (int)i;
y = (int)j;
circle(x+s,y,(int)y/6);
s=s+3;
} while (s<550);
getch();
closegraph();// Return into text mode
return 0;
}//End of program
Program 2 :
/*
########################################
# WWW : cpp.blogfa.com #
# Released on July 2005 #
########################################
*/
//Essential Library
#include
#include
#include
#include
{
int gdriver = DETECT;
int gmode,errorcode,i;
initgraph( &gdriver, &gmode,"c:\\tc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
{
exit(1);
}
setcolor(10);
i=0;
do{
i=i+1+(int)i/10;
line(120+i,i,520-i,i);
line(120+i,400-i,520-i,400-i);
line(520-i,400-i,520-i,i);
line(120+i,i,120+i,400-i);
} while (i<200);
getch();
closegraph(); //Return into text mode
return 0;//End of Programm
این برنامه یک نوع منو را در محیط گرافیک
C++ ارائه می کند که توسط آقای Vivek Patel نوشته شده . کد این برنامه بسیار روان است و در اغلب موارد همراه با توضیح می باشد :
/*########################################
# Programmer : Vivek Patel #
# Release at Site : cpp.blogfa.com #
# mail : cpp.blogfa@gmail.com #
########################################*/
#include
#include
#include
#include
#define pixTOrc(x) (8*(x-1)) //convert pixel into row and col format
#define INC 5 //Increment Distance Between Menu Items
#define ROW 15 //Row Value for Menu Item
#define COL 8 //Column Value for Menu Item
#define MAXITEM 5 //Total menu items
// To display the Inventory Main menu options
typedef char option[15];
option mainMenu[]= {
"NEW",
"OPEN",
"SAVE",
"ABOUT ME",
"CLOSE"
};
// Function to displays all the menu prompt messages from the pointer array of option a[]
void normalvideo(int x,int y,char *str)
{
x=pixTOrc(x);
y=pixTOrc(y);
outtextxy(x,y,str);
}
// Function to move the cursor on the menu prompt with a reverse video color
void reversevideo(int x,int y,char *str)
{
x=pixTOrc(x);
y=pixTOrc(y);
setcolor(YELLOW); //Selected Item
sound(400);
delay(100);
nosound();
outtextxy(x,y,str);
setcolor(WHITE); //Unselected Item
sound(500);
delay(100);
nosound();
}
//Keep Track of which arrow key is pressed
char menu()
{
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
setcolor(WHITE); //Initial Menu Item Color
int i,done;
for(i = 1; i < MAXITEM; i++)
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
reversevideo(COL,ROW, mainMenu[0]);
i = done = 0;
do
{
/**Status Bar Logic**/
//Message will be displayed as status bar guide-line
setfillstyle(SOLID_FILL,BLUE);
settextstyle(SMALL_FONT,HORIZ_DIR,5);
bar(pixTOrc(2),pixTOrc(52.5),pixTOrc(75),pixTOrc(55));
setcolor(LIGHTCYAN);
switch(i){
case 0 : outtextxy(pixTOrc(5),pixTOrc(52.75),"New --> Create New file");
break;
case 1 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Open --> Open Existing file");
break;
case 2 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Save --> Save file");
break;
case 3 : outtextxy(pixTOrc(5),pixTOrc(52.75),"About Me --> Programmer : Vivek Patel");
break;
case 4 : outtextxy(pixTOrc(5),pixTOrc(52.75),"Close the Program --> BYE C U");
break;
}
/**status Bar ends**/
//Restore Orignal Color and Font Setting
setcolor(WHITE);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
ssss int key = getch();
switch (key)
{
case 00:
key = getch();
switch (key)
{
case 72:
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
i--;
if (i == -1)
i = MAXITEM-1;
reversevideo(COL,(i*INC)+ROW,mainMenu[i]);
break;
case 80:
normalvideo(COL, (i*INC)+ROW, mainMenu[i]);
i++;
if (i == MAXITEM)
i = 0;
reversevideo(COL, (i*INC)+ROW, mainMenu[i]);
break;
}
break;
case 13:
done = 1;
}
}
while (!done);
return(i+49);
}
//Advertise Screen will displayed to utilize empty screen area
//It can be utilize for some effective...work
void advertise(){
setcolor(BLUE);
outtextxy(pixTOrc(30),pixTOrc(20),"URL : cpp.blogfa.com");
outtextxy(pixTOrc(30),pixTOrc(26),"Mail : cpp.myblog@gmail.com");
setcolor(YELLOW);
}
/* The function is used to display the main menu*/
//Actual code for all the menu utility resides in this
//Function...
void control_menu()
{
char choice;
do
{
choice = menu();
switch (choice)
{
case '1': //New
setcolor(BLUE);
outtextxy(pixTOrc(40),pixTOrc(15),"New");
advertise();
getch();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
advertise();
break;
case '2': //Open
setcolor(BLUE);
outtextxy(pixTOrc(40),pixTOrc(15),"Open");
advertise();
getch();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
advertise();
break;
case '3': //Save
setcolor(BLUE);
outtextxy(pixTOrc(40),pixTOrc(15),"Save");
advertise();
getch();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
advertise();
break;
case '4': //Modify the status of item in inventory
setcolor(BLUE);
outtextxy(pixTOrc(40),pixTOrc(15),"About Me");
advertise();
getch();
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
advertise();
break;
case '5': //Close the program
setcolor(BLUE);
outtextxy(pixTOrc(40),pixTOrc(15),"CLOSE");
advertise();
delay(1000);
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(pixTOrc(28),pixTOrc(14),pixTOrc(75),pixTOrc(50));
advertise();
goto out;
}
} while (choice != MAXITEM);
out:
}
void main()
{
int i,j;
int gd=DETECT,gm=0;
initgraph(&gd,&gm,"c:\\tc\\bgi\\");
///code as space holder\\\\\
setfillstyle(SOLID_FILL,LIGHTGRAY);
bar(0,0,640,480);
setcolor(DARKGRAY);
rectangle(0,0,639,480);
rectangle(1,1,638,479);
setcolor(BLACK);
rectangle(2,1,637,478);
rectangle(3,1,636,477);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,4);
setcolor(BLUE);
outtextxy(pixTOrc(8),pixTOrc(2)," MENU -->> (Simple Style) ");
setfillstyle(HATCH_FILL,DARKGRAY);
for(i=15,j=70;i<40||j>40;i++,j--){
bar(pixTOrc(8),pixTOrc(7),pixTOrc(i),pixTOrc(7.5));
delay(10);
bar(pixTOrc(j),pixTOrc(7),pixTOrc(70),pixTOrc(7.5));
delay(20);
}
bar(pixTOrc(7),pixTOrc(14),pixTOrc(25),pixTOrc(50));
///code as space holder\\\\\
//Calling Menu
control_menu();
closegraph();
}
سلام دوستان گرامی
در اینجا می خوام به دو سوال که برام Mail زده بودید جواب بدم :
1. چگونه می توان زمان جاری سیستم را نشان داد :
این کد زمان جاری سیستم را در خروجی چاپ می کند
/*########################################
# WWW : cpp.blogfa.com #
# mail : mail: cpp.blogfa@gmail.com #
########################################*/
#include
#include
#include
{
clrscr();
struct tm * Current_Time ;
time_t lt;
lt = time (NULL);
Current_Time = localtime(<);
textcolor(13);
cprintf(asctime(Current_Time));
getch();
return 0;
}
2. چگونه می توان از وقف ها در زبان C++ استفاده کرد ؟
خوب بد نیست اینجا کمی هم درباره وقفه ها صحبت کنیم . وقفه ها سیگنال هایی هستند که از برنامه های در حال اجرا و یا دستگاه های جانبی کامپیوتر (چاپگر و مونیتور و موس و . . .) در خواست می شود , وقتی وقفه ای اتفاق می افتد اجرای برنامه به تعویق افتاده محتویات ثباتهای CS و IP در پشته نگهداری شده و کنترل روال پاسخگو یی به این وقفه منتقل می شود . پس از پاسخگو یی به وقفه مورد نظر محتویات CS و IP از پشته ها بازیابی می شود. تعداد 256 وقفه وجود دارد که هر یک دارای زیر برنامه و توابع مخصوص به خود می باشند که می تواند اعمال مختلفی را انجام دهند . لیست وقفه ها را می توانید در مراجع اصلی زبان اسمبلی و با جستجو در اینترنت پیدا کنید .
خوب در زبان C/C++ برای اجرای وقفه ها ابتدا ثباتهای مورد نیاز مقدار دهی شده و بع با استفاده از تابع زیر اجرا می شود
int (
int intnum , union REGS *in , union REGS *out )union
: یونیونها یک قالب داده می باشد که می تواند انواع مختلفی از داده ها را در خود نگهداری کند و فقط یک نوع داده را می تواند در یک زمان نگهداری کند و این همان تفاوت union با struct ها می باشد , struct ها می تواند در یک زمان چند نوع داده مختلف را نگهداری کند (int , long , double , char)خوب برای تفهیم بهتر مثالی در زیر آورده شده که که با استفاده از وقفه صفحه نمایش را پاک کره و مکان نما را به مکان (0و0) انتال می دهد :
/*########################################
# WWW : cpp.blogfa.com #
########################################*/
#include
#include
#include
void clear_screen(void);//define function
void move_xy(int x,int y);//define function
int main()
{
int x,y;
printf(" This is a test \n");
getch();
clear_screen();// Call Function
move_xy(0,0);//call move_xy function
getch();
return 0;
}
/* Body of clear screen function */
void clear_screen(void)
{
union REGS r ;
r.h.ah = 6;
r.h.al = 0;
r.h.ch = 0;
r.h.cl = 0;
r.h.dh = 23;
r.h.dl = 79;
r.h.bh = 7;
int86(0x10, &r, &r);
}
/* Body of move_xy function */
void move_xy(int x,int y)
{
union REGS r;
r.h.ah = 2;
r.h.bh = 0;
r.h.dh = x;
r.h.dl = y;
int86(0x10, &r, &r);
}
3. چگونه یک
Progress Bar را در محیط Text پیاده سازی کنیم ؟
for (i = 0;i < 80;i ++)
{
gotoxy (wherex(),21);
cprintf ("کاراکتر مورد نظر");
delay (50);
}
برج هانوی , معمایی است که از سه میله و N دیسک با اندازه های متفاوت . فرض شود که اگر دیسکی روی یک میله باشد , فقط دیسکی که قطر آن کوچکتر است می تواند بالای آن قرار گیرد مسئله چنین است که هر بار فقط یک دیسک انتقال یابد .
را حل : این مسئله با استفاده از یک الگوریتم باز گشتی حل می شود .
-اگر فقط یک دیسک باشد آنگاه آن را به میله مورد نظر انتقال می دهیم .
-اگر n > 1 باشد ; برای این کار n-1 دیسک بالای میله 1 را به میله 2 انتقال می دهیم . حالا دیسک پایینی میله 1 را ثابت باقی می ماند . حال دیسک باقیمانده در در میله 1 را به میله 3 منتقل میکنیم . سرانجام بار دیگر بصورت بازگشتی الگوریتم را فرا خانده تا n - 1 دیسک میله دو را به 3 منتقل کند .
اکنون موفق شدیم n دیسک را از میله 1 به 3 منقل کنیم .
این مسئله در درسهایی مانند ساختمان گسسته و ساختمان داده مورد بحث وبررسی قرار می گیرد .
/*
Algorithmic solution is as follows
1) if TopN==1, move the single disc from A to C and stop.
2) Move the top n-1 discs from A to B, using C as Inter.
3) Move the remaining disc from A to C.
4) Move the n-1 discs from B to C, using A as destination(dest).
*/
#include
#include void tower(int,char,char,char); /*prototype*/
int main()
{
int ndisk;
clrscr();
printf("\n Enter number of disks <<<::: ");
scanf("%d",&ndisk);
tower(ndisk,'A','B','C'); /*Calling Function*/
getch();
return 0;
} /* End of program */
/********************************************/
// src = Source | aux = Auxiliry | dest = Destination
void tower(int topN, char src,char aux,char dest)
{
if(topN == 1)
{
printf("\n Disk 1 from %c to %c ",src,dest);
}
else
{
tower(topN-1,src,dest,aux); //src to aux
printf("\n Disk %d from %c to %c ",topN,src,dest);
tower(topN-1,aux,src,dest); //aux to dest
}
}

