<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>turbo-pascal &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/turbo-pascal/</link>
	<description>Feed of posts on WordPress.com tagged "turbo-pascal"</description>
	<pubDate>Tue, 01 Dec 2009 19:56:42 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Structuring my Thinking]]></title>
<link>http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/</link>
<pubDate>Mon, 30 Nov 2009 16:50:50 +0000</pubDate>
<dc:creator>Jim Lawless</dc:creator>
<guid>http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/</guid>
<description><![CDATA[In my post Learning Z-80 Assembly Language on the TRS-80, I describe my acquisition of the assembly ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In my post <a href="http://jimlawless.wordpress.com/2009/11/07/learning-z-80-assembly-language-on-the-trs-80/">Learning Z-80 Assembly Language on the TRS-80</a>, I describe my acquisition of the assembly language programming skills that <em>could have</em> led to a career as a game-developer.  I emphasized the phrase &#8220;could have&#8221;, because I had mentioned in that post that I really knew nothing about good software design practices.</p>
<p>Like many of my generation, I started out coding in 8-bit BASIC dialects and later began to code in assembly language.  What I often did when writing assembly was picture the program in BASIC.  That&#8217;s the sort of mental modeling I was doing at the time because it was the only programming environment I had known.  My early coding style for writing assembly programs was just to start and interactively try to shape the program as I went along, without a clear high-level mental picture of what I wanted to accomplish.</p>
<p>At this time, the trade press was starting to warm up to the Pascal programming language as a means by which good programming habits could be taught.  Many add-on packages for BASIC supplemented the interpreters with some Pascal-like constructs ( named procedures and functions, structured loops, block-structured if/else/endif, &#8230;etc. ) One such extended BASIC was a language called COMAL from Denmark.  A free version was available at the time for the Commodore 64 home computer, so I tinkered with it a bit.  ( You can try out COMAL on modern OS&#8217;s via the OpenCOMAL project: <a href="http://www.josvisser.nl/opencomal/">http://www.josvisser.nl/opencomal/ </a> ).</p>
<p>COMAL was a powerful BASIC with extended flow-control and instant feedback on errors as you entered lines of text.  I really didn&#8217;t understand the value of these named FUNC&#8217;s and PROC&#8217;s that it would encourage the developer to use, although I had seen similar constructs in the language <em>Simons&#8217; BASIC</em> &#8230; another extended BASIC available in cartridge form for the C-64.</p>
<p>I had purchased a couple of Commodore 64 Pascal compilers at the time.  They were very cumbersome to use due to the limited amount of memory plaguing 8-bit computers of that time, and also due to the slow disk speeds of the serial protocol used to talk to the 1541 disk-drives.  Often, you had to unload the editor while the compiler pored over your program.  When a mistake was found, you had to re-load the editor &#8230; which took a lot of time.  Development with most of these compilers was a very slow process.</p>
<p>I wasn&#8217;t making very much headway learning Pascal on my own, so I took a Pascal course as an elective in college.   I learned much more quickly in a formal curriculum.  It&#8217;s not that the assignments were all that enlightening; I just needed a bit of a nudge in the right direction. I worked a little with the small Pascal compilers I had, but they were very frustrating to use.</p>
<p>Just after I had completed my introductory Pascal class, Commodore released the Commdore 128 home computer.  I bought one as soon as the department stores started to carry them.  The C-128 had a C-64 emulation mode and a CP/M mode.  I had an interest in CP/M as I had a desire to work with a &#8220;real&#8221; operating system, but the Z-80 cartridge I&#8217;d bought for my C-64 and the CP/M software for the cartridge were just too slow.</p>
<p>CP/M on the C-128 was much better.  I bought a composite Apple monitor and cobbled together a video cable that allowed me to use the 80-column text mode on the C-128.  I began to frequent a local BBS with a CP/M software repository.  Some local people were writing CP/M utilities in Turbo Pascal.  I really enjoyed downloading the source code and looking through each program.  Tech magazines of this time period were providing coverage of Turbo Pascal.</p>
<p>I ended up getting Turbo Pascal 3.0 for CP/M-80 for my C-128.  I was amazed at how quickly TP would compie my code.  It was an incredible experience after putting up with all of those slow compilers for such a long time.  I spent a lot of time toying with TP and bought a book on the MS-DOS version of TP from Compute! publications.</p>
<p>I was beginning to model programs mentally using a more structured, top-down approach.  I would start by envisioning some high-level functions / procedures and would flesh each one of those out as I thought about them in detail.</p>
<p>A friend of mine who was attending a reputable university advised me to buy the venerable book <em>The C Programming Language</em> by Kernighan and Ritchie.  So, I did.  I loved reading that book. Learning Pascal helped ease me into similar concepts in C. Unfortunately, I didn&#8217;t have a C compiler to toy with.  I went to a computer store in a neighboring city and bought the C-64 version of Abacus&#8217; ( Data Becker&#8217;s ) Super-C compiler.  It was really cumbersome to use like the Pascal compilers I had tried to use earlier.  I had realized that I was just going to need to go with a computer that had better compilers available.</p>
<p>By this time, I was out of school and was working writing mainframe code.  I sold all of my 8-bit Commodore gear and bought an Amiga 500.  I tried to learn C using this new computer as that seemed to be the most popular development language available for it.  I didn&#8217;t have a hard-disk drive, so the compiler required some diskette shuffling.  I would compile with one floppy to a ramdisk, then I&#8217;d link with a separate floppy.  I still had a long way to go, but this process wasn&#8217;t really that bad.  Even with the floppy swaps, I was able to edit, compile, and test pretty quickly.</p>
<p>I used to read the code listings in Dr. Dobbs Journal ( I loved Allen Holub&#8217;s <em>C Chest</em> column ) and in Byte magazine each month and would try to understand what the author was trying to accomplish, line by line.  I checked out a copy of the Waite Group&#8217;s <em>Advanced C Primer Plus</em> text, which helped de-mystify pointers and C&#8217;s pointer notation.</p>
<p>My next planned purchase was an MS-DOS machine as the prices for the rising clone market were dropping.  I bought a book on 8086 assembly language in MS-DOS to be certain that I understood the OS at a very low level.</p>
<p><strong><em>&#8220;Chance favors the prepared mind.&#8221; &#8211; Louis Pasteur</em></strong></p>
<p>An opportunity arose to be a founding member of an MS-DOS C development team at work.  Although I had no MS-DOS machine at home, the rigor that I had put forth studying C and low-level MS-DOS had paid off.  Although, my team and I all started out as novice C programmers, our prowess grew in leaps and bounds as we went on to build some very respectable, long-lived software.</p>
<p>I continued on the C path, first using C++ and later Java as well as a myriad of diverse languages along the way.  Often, these languages cater to specific programming idioms and/or philosophies.  By learning a little about each of these languages I&#8217;ve learned more about programming in general.</p>
<p>While I have only used Pascal a few times professionally ( most recently Object Pascal in Delphi), I consider it to be the language that kick-started my software design skills.</p>
<p><a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank"><img title="del_icio_us" src="http://www.mailsend-online.com/wp/del_icio_us.png" alt="del_icio_us" /></a> <a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank">Save to del.icio.us</a><br /><a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank"><img title="digg" src="http://www.mailsend-online.com/wp/digg.png" alt="digg" /></a> <a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank">Digg it</a><br /><a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank"><img title="reddit" src="http://www.mailsend-online.com/wp/reddit.png" alt="reddit" /></a> <a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/&#38;title=Structuring+my+Thinking" target="_blank">Save to Reddit</a><br /><a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/" target="_blank"><img title="facebook" src="http://www.mailsend-online.com/wp/facebook.png" alt="facebook" /></a> <a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/" target="_blank">Share on Facebook</a><br /><a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/"><img title="twitter" src="http://www.mailsend-online.com/wp/twitter.gif" alt="twitter" /></a> <a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/" target="_blank">Share on Twitter</a><br /><a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/;title=Structuring+my+Thinking" target="_blank"><img title="aolfav" src="http://www.mailsend-online.com/wp/aolfav.gif" alt="aolfav" /></a> <a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/11/30/structuring-my-thinking/;title=Structuring+my+Thinking" target="_blank">More bookmarks</a>
<p><img src="http://www.mailsend-online.com/cgi-bin/wphit.pl" /><br />
<em>Unless otherwise noted, all code and text entries are Copyright © 2009 by James K. Lawless</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Pisanie programów na zamówienie.]]></title>
<link>http://dawidpolakowski.wordpress.com/2009/11/07/pisanie-programow-na-zlecenie/</link>
<pubDate>Sat, 07 Nov 2009 14:59:41 +0000</pubDate>
<dc:creator>Dawid Polakowski</dc:creator>
<guid>http://dawidpolakowski.wordpress.com/2009/11/07/pisanie-programow-na-zlecenie/</guid>
<description><![CDATA[Na mojej stronie domowej dodałem dział programowanie (katalog i podstronę). Od roku nie przyjmowałem]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Na mojej stronie domowej dodałem dział programowanie (katalog i podstronę).</p>
<p>Od roku nie przyjmowałem zleceń,  jednak teraz postanowiłem wrócić do praktyki programistycznej.</p>
<p>Oferta jest kierowana głównie do studentów uczelni informatycznych i osób prywatnych. W wypadku dużych zleceń mogę nie zdołać wyeksponować wystarczającej ilości czasu.</p>
<p>Zajmuję się pisaniem programów na zlecenie w językach Java,  C++, Turbo Pascal, SQL, PHP, BASH, FLASH,  HTML , CSS (oczywiście w css, czy html &#8220;nie piszemy programów&#8221;).</p>
<p><a title="cieplice pisanie programów na zamówienie" href="http://dawid-polakowski.jgora.pl/programowanie/">Pisanie programów na zamówienie</a> to dobry sposób, aby się nie rozleniwić, sam orgaizując sobie projekty popadam często w wygodnictwo. Zamiast coś napisać szukam gotowca. Takie podejście działa, ale nie daje wystarczającej satysfakcji.</p>
<p>Więcej dowiesz się na mojej stronie domowej.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[My Foray into Shareware]]></title>
<link>http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/</link>
<pubDate>Wed, 28 Oct 2009 02:18:20 +0000</pubDate>
<dc:creator>Jim Lawless</dc:creator>
<guid>http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/</guid>
<description><![CDATA[In the early 90&#8217;s, I wanted to be an independent software developer. Heck, I wanted to be an i]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>In the early 90&#8217;s, I wanted to be an independent software developer.  Heck, I wanted to be an indie in the 80&#8217;s, too.  I just didn&#8217;t ever seem to be able to harmonize software I&#8217;d written with any kind of a need in the marketplace.</p>
<p>At this time, I was still in the habit of frequenting electronic bulletin-board systems (BBS&#8217;s).  Although I had picked up this hobby while the venerable Commodore 64 was my computer of choice back in 1984, I primarily frequented bulletin-board systems running on MS-DOS ( often supplemented with Quarterdeck&#8217;s DesqView to support multiple incoming calls. )</p>
<p>A few of the BBS&#8217;s I was particularly drawn to were running on a nice little system called the Spitfire BBS written in Turbo Pascal by fellow Iowan Mike Woltz under the company name Buffalo Creek Software.  Mike was selling this software independently.  The sysops loved it.  The users loved it. I was very impressed that someone who probably lived just a couple hours away from me was actually selling his own software independently and was obviously picking up some sales in my neck of the woods.</p>
<p>In addition to the BBS software itself, Spitfire was able to host third-party plug-ins called <em>&#8220;doors&#8221;</em>.  Doors were simply external programs that observed a predefined parameter file format which contained information about the current user and such.  The door program could then take over the online experience as an extension to the BBS itself.</p>
<p>One of the non-game-oriented doors available for Spitfire was a message-board add-on called CircuitNet.  This was a networking plug-in that provided a series of nationwide, special-interest, moderated forums not unlike FidoNet.</p>
<p>Later, Woltz wrote his own add-on for Spitfire called SFNet which ultimately replaced SFNet on the BBS&#8217;s I used to frequent.</p>
<p>One of the SFNet nationwide forums was specifically for door program discussion.  A number of doors were discussed.  Game doors were quite popular.  One door author would show up from time to time on the forum and would release some pretty good games as try-before-you-buy shareware.  He made what I assume to be a small but nice enough amount of money at it, so I decided to try my hand at writing some software that I felt would be of interest to the Spitfire community.</p>
<p>My first attempt to write and sell my own software using the shareware marketing concept was a program called <strong>keymac</strong>.  Keymac was an MS-DOS TSR ( terminate but stay-resident ) utility that I wrote in assembly language.  It ran in the background, intercepting all keystrokes that were gathered via the standard BIOS and DOS API routines and would check for keys that had been defined in a macro file.</p>
<p>The macro file allowed one to cause a single key ( with CTRL, ALT, and SHIFT as modifiers ) to generate multiple virtual keystrokes. One could configure the macro text file so that by pressing F8, the characters for a string such as &#8220;Hi, there, friend!&#8221; would appear to have been typed at the keyboard.</p>
<p>I wrote this utility because a sysop on one of the Spitfire forums was hoping for some kind of macro facility in the Sysop <em>chat</em> mode so that frequently asked questions and such could be answered with the touch of a single key.</p>
<p>I wrote and tested the program and decided to sell it for three dollars.  I thought that I&#8217;d be able to sell a couple dozen copies of the software over one of these forums and that really would have been enough sales for me.</p>
<p>I released the utility with no nag-screen nor expiration time-outs nor any limiting features on one of the sysops&#8217; BBS&#8217;s and gave them a free copy for hosting it.  Then, I announced it on one of the forums.</p>
<p>Another sysop &#8230; the one who had wished out loud for a macro feature &#8230; tried keymac and thanked me for it &#8230; but no payment ever came my way.  I was dumbfounded.  I had written this utility in some very tricky, very tight code and had gone through some considerable testing to make sure that it worked properly.  People were using it but I wasn&#8217;t getting rich.  I wasn&#8217;t getting anything.</p>
<p>One day, I had gotten home from work and was opening my mail when I noticed a personal letter from someone in a distant city that I didn&#8217;t know.  Sure enough, a check for three dollars and a letter thanking me for the utility were in the envelope.</p>
<p>I ended up calling the guy to thank him and asked him how he used the software.  He was just ecstatic about the program.  He was a sysop, but he used the software on other computers for his own BBS&#8217;ing as a client.  He said that he&#8217;d found many uses for it outside the realm of telecommunications altogether.</p>
<p>I was very happy.  The money wasn&#8217;t really the issue.  By sending a check, the gentleman had sent me an affirmation that I had written something that he found useful enough to pay me for it.  That really made my day.</p>
<p>Inspired by my first sale, I ventured out to write another program for the same community. This time, I decided to write a door program as I thought that by targeting something that the BBS users would want instead of the sysops, I might make more sales.</p>
<p>My door was actually a door utility that ran as part of Spitfire&#8217;s scheduled maintenance activities.  ( I can&#8217;t remember exactly how this worked, but I believe there were batch files that ran nightly that could be customized by the sysops ).</p>
<p>I wrote a little utility that would read the users scores from another door game and would post a message to a specified forum containing the high-score list or something like that.  Again, I gave a copy to the sysop for the BBS I visited most often and made an announcement on one of the forums.</p>
<p>This time, I actually think I sold two copies of this utility, again at three dollars each.  I was quite happy with that.  I didn&#8217;t take long to write, except for some work with the sysop to ensure that I was posting the message according to the published data-structures.  It took me a bit longer that it might have others because I was writing this utility in C and had to deal with data types specific to Turbo Pascal such as counted-strings/packed-arrays-of-characters; strings with a length byte at the beginning instead of a C-style zero-byte terminator.</p>
<p>I was just happy enough that a couple more people registered in a rather timely manner.  However, one of the two had a problem with the program.  I ended up spending enough time on a long-distance call to correct the program, that my gross sales for the two copies were eaten.</p>
<p>At that point, I ran out of enthusiasm for publishing much more in this particular genre of software.  Soon enough, the Internet became readily available to the public and the BBS&#8217;s started to disappear.</p>
<p>From these early experiences, I had found that I needed to strongly consider how to price my products in future attempts at marketing software and also needed to ensure that I had some way to keep my support costs down.</p>
<p>Something that wasn&#8217;t quite obvious to me yet was that I was going to have to find a way to ensure that people who had planned to pay but were procrastinating could be nudged into paying in a timely manner.</p>
<p>My next steps into becoming an indie software developer were much more fruitful.  I&#8217;ll tell you more about those in this <strong>Tale Recursion</strong> section of my blog soon.</p>
<p><a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank"><img title="del_icio_us" src="http://www.mailsend-online.com/wp/del_icio_us.png" alt="del_icio_us" /></a> <a href="http://del.icio.us/post?url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank">Save to del.icio.us</a><br /><a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank"><img title="digg" src="http://www.mailsend-online.com/wp/digg.png" alt="digg" /></a> <a href="http://digg.com/submit?phase=2&#38;url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank">Digg it</a><br /><a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank"><img title="reddit" src="http://www.mailsend-online.com/wp/reddit.png" alt="reddit" /></a> <a href="http://reddit.com/submit?url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/&#38;title=My+Foray+into+Shareware" target="_blank">Save to Reddit</a><br /><a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/" target="_blank"><img title="facebook" src="http://www.mailsend-online.com/wp/facebook.png" alt="facebook" /></a> <a href="http://www.facebook.com/share.php?u=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/" target="_blank">Share on Facebook</a><br /><a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/"><img title="twitter" src="http://www.mailsend-online.com/wp/twitter.gif" alt="twitter" /></a> <a href="http://twitter.com/home?status=Check+out+http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/" target="_blank">Share on Twitter</a><br /><a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/;title=My+Foray+into+Shareware" target="_blank"><img title="aolfav" src="http://www.mailsend-online.com/wp/aolfav.gif" alt="aolfav" /></a> <a href="http://www.addthis.com/bookmark.php?pub=dvd&#38;url=http://jimlawless.wordpress.com/2009/10/27/my-foray-into-shareware/;title=My+Foray+into+Shareware" target="_blank">More bookmarks</a>
<p><img src="http://www.mailsend-online.com/cgi-bin/wphit.pl" /><br />
<em>Unless otherwise noted, all code and text entries are Copyright © 2009 by James K. Lawless</em></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Pascal: vẽ đồng hồ, chùm pháo hoa]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/pascal-dong-ho-phao-hoa/</link>
<pubDate>Mon, 19 Oct 2009 02:29:28 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/pascal-dong-ho-phao-hoa/</guid>
<description><![CDATA[1. Chương trình tạo một chiếc đồng hồ Gimico trên màn hình máy tính dùng Pascal. uses crt,graph,dos;]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><span style="font-weight:bold;">1. Chương trình tạo một chiếc đồng hồ Gimico trên màn hình máy tính dùng Pascal.</span><br />
uses crt,graph,dos;<br />
var x,y,x1,y1,x2,y2,goc: integer;  goc1,goc2,goc3,old,gd,gm:integer;<br />
gio,phut,giay,mili:word;  so,gio1,phut1,giay1:string;  rad:real;<br />
procedure kim_giay(goc:integer);<br />
begin rad:=goc*pi/180; x1:=round(x+150*sin(rad));<br />
y1:=round(y-150*cos(rad)); setlinestyle(0,0,1); line(x,y,x1,y1);<!--more--><br />
if (goc mod 6=0) then<br />
begin sound(3000);delay(10);nosound; end;<br />
end;<br />
procedure kim_phut(goc1:integer);<br />
begin rad:=goc1*pi/180; x1:=round(x+150*sin(rad));<br />
y1:=round(y-150*cos(rad)); setlinestyle(0,0,3); line(x,y,x1,y1);<br />
end;<br />
procedure kim_gio(goc2:integer);<br />
begin rad:=goc2*pi/180;<br />
x1:=round(x+100*sin(rad)); y1:=round(y-100*cos(rad));<br />
setlinestyle(1,1,10); line(x,y,x1,y1);<br />
end;<br />
Begin gd:=detect; initgraph(gd,gm,&#8221;);<br />
(* &#8212;&#8212;&#8211; Ve 3 vong tron &#8212;&#8212;- *)<br />
setcolor(10); setbkcolor(white); x:=getmaxx div 2; y:=getmaxy div 2;<br />
setfillstyle(1,10); setcolor(4);<br />
circle(x,y,210); circle(x,y,170); circle(x,y,5); floodfill(x,y,4);<br />
setfillstyle(2,14); floodfill(x+11,y+11,4);<br />
setfillstyle(1,blue); floodfill(x+88,y+158,4);<br />
(* &#8212;&#8212;- Ve so tren mat dong ho &#8212;&#8212;&#8212; *)<br />
setcolor(12); settextstyle(0,0,2);<br />
outtextxy(x-18,y-197,&#8217;12&#8242;); outtextxy(x+183,y-5,&#8217;3&#8242;);<br />
outtextxy(x-196,y-5,&#8217;9&#8242;);   outtextxy(x-10,y+183,&#8217;6&#8242;);<br />
outtextxy(x+160,y-98,&#8217;2&#8242;);  outtextxy(x-180,y-98,&#8217;10&#8242;);<br />
outtextxy(x+89,y-170,&#8217;1&#8242;);  outtextxy(x-114,y-170,&#8217;11&#8242;);<br />
outtextxy(x+160,y+88,&#8217;4&#8242;);  outtextxy(x-172,y+88,&#8217;8&#8242;);<br />
outtextxy(x+88,y+158,&#8217;5&#8242;);  outtextxy(x-110,y+154,&#8217;7&#8242;);<br />
(* &#8212;&#8212;&#8211; Ke mac dong ho &#8212;&#8212;&#8211; *)<br />
setcolor(12); settextstyle(0,0,1); outtextxy(x-20,y+120,&#8217;VIETNAM&#8217;);<br />
(* &#8212;&#8211; Ve 3 kim dong ho &#8212;&#8212;- *)<br />
setwritemode(xorput); goc:=0; goc1:=0; goc2:=0;<br />
gettime(gio,phut,giay,mili); goc:=giay*6; old:=giay;<br />
kim_giay(goc); goc1:=phut*6+ giay div 10; kim_phut(goc1);<br />
goc2:=gio*30+phut div 2; kim_gio(goc2);<br />
(* &#8212;&#8212;&#8211; Cho dong ho chay &#8212;&#8212;&#8212;&#8211; *)<br />
repeat gettime(gio,phut,giay,mili);<br />
if giay&#60;&#62;old then<br />
begin  kim_giay(goc); goc:=giay*6; kim_giay(goc); old:=giay;<br />
if phut*6+giay div 10 &#60;&#62;phut then<br />
begin kim_phut(goc1); goc1:=phut*6+giay div 10;<br />
kim_phut(goc1); kim_gio(goc2);<br />
goc2:=gio*30+phut div 2; kim_gio(goc2);<br />
end;<br />
end;<br />
until keypressed;<br />
closegraph;<br />
end.<br />
<span style="font-weight:bold;"> 2. Chương trình viết bằng Pascal tạo các chùm pháo hoa nhân dịp năm mới</span>.<br />
uses crt,graph;<br />
var gd,gm,i,j:integer;s,r,s1,r1,l:real;<br />
h,t,x,y:array[1..40] of integer;<br />
x0,y0,mau:array[1..8] of integer;</p>
<p>procedure sao(mau:word;x1,y1:integer;s:real);<br />
var i:integer;d:real;<br />
begin<br />
d:=s*cos(2*pi/5)/cos(pi/5);<br />
for i:=1 to 5 do<br />
begin<br />
x[i]:=x1+round(s*sin((i-1)*2*pi/5));<br />
y[i]:=y1-round(s*cos((i-1)*2*pi/5));<br />
end;<br />
for i:=1 to 5 do<br />
begin<br />
x[i+5]:=x1+round(d*sin(pi/5+(i-1)*2*pi/5));<br />
y[i+5]:=y1-round(d*cos(pi/5+(i-1)*2*pi/5));<br />
end;<br />
setcolor(mau);<br />
for i:=1 to 5 do line(x[i],y[i],x[i+5],y[i+5]);<br />
for i:=2 to 5 do line(x[i],y[i],x[i+4],y[i+4]);<br />
line(x[10],y[10],x[1],y[1]);<br />
setfillstyle(1,mau);<br />
floodfill(x1,y1,mau);<br />
end;<br />
procedure phaohoa1(mau:word;x0,y0:integer);<br />
var n:integer;<br />
begin<br />
r:=0;s:=2;l:=0;<br />
repeat<br />
for i:=1 to 40 do<br />
begin<br />
h[i]:=round(r*sin(i*pi/20));<br />
t[i]:=round(r*cos(i*pi/20));<br />
x[i]:=x0+h[i];<br />
y[i]:=y0-t[i];<br />
sao(mau,x[i],y[i],s);<br />
end;<br />
setcolor(red);<br />
settextstyle(0,0,5);<br />
outtextxy(50,460,&#8217;Happy New Year&#8217;);<br />
settextjustify(0,0);<br />
delay(5);<br />
r:=r+4+l;<br />
l:=l+0.1;<br />
s:=s+0.05;<br />
until r= 246;<br />
delay(1000);  n:=0;<br />
repeat<br />
r1:=246-r;s1:=4-s;<br />
for i:=1 to 40 do<br />
begin<br />
h[i]:=round(r1*sin(i*pi/20));<br />
t[i]:=round(r1*cos(i*pi/20));<br />
x[i]:=x0+200+h[i];<br />
y[i]:=y0+100-t[i];<br />
sao(mau+1,x[i],y[i],s1);</p>
<p>h[i]:=round(r*sin(i*pi/20));<br />
t[i]:=round(r*cos(i*pi/20));<br />
x[i]:=x0+h[i];<br />
y[i]:=y0-t[i];<br />
sao(black,x[i],y[i],s);</p>
<p>end;</p>
<p>inc(n);<br />
setcolor(red);<br />
settextstyle(0,0,5);<br />
outtextxy(50,460,&#8217;Happy New Year&#8217;);<br />
settextjustify(0,0);<br />
delay(50);<br />
l:=l-0.1;<br />
r:=r-4-l;<br />
s:=s-0.05;<br />
until n=42;<br />
end;</p>
<p>begin<br />
randomize;<br />
gd:=detect;initgraph(gd,gm,&#8221;);<br />
for j:=1 to 8 do<br />
begin<br />
mau[j]:=random(15)+1;<br />
x0[j]:=random(540);<br />
y0[j]:=random(480);<br />
phaohoa1(mau[j],x0[j],y0[j]);<br />
end;</p>
<p>readln;<br />
closegraph;<br />
end.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Pascal: đề thi 1-2-3]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/pascal-dethi-1-2-3/</link>
<pubDate>Mon, 19 Oct 2009 02:26:31 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/pascal-dethi-1-2-3/</guid>
<description><![CDATA[Đề thi Môn Ngôn ngữ Lập trình Pascal (đề 1) Thời gian : 10 phút đọc đầu đề, 90 phút làm bài. Không s]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p align="center"><strong><span style="font-family:Arial;">Đề thi Môn Ngôn ngữ Lập trình Pascal (đề 1)</span></strong></p>
<p align="center"><span style="font-family:Arial;">Thời gian : 10 phút đọc đầu đề, 90 phút làm bài. Không sử dụng tài liệu</span></p>
<p>Họ tên thí sinh : . . . . . . . . . . . . . . . . . . . . . . . . . . .  Ngày sinh: . . . . . . . . . . . .</p>
<p>Lớp : . . . . . . . . . . Số báo danh : . . . . . . . . . . . . .  Số máy tính : . . . . . . . . . . .</p>
<p><strong>Hướng dẫn đặt các tên tệp bài làm và nơi lưu trữ</strong> . Đề thi có 3 câu, mỗi câu cần làm một tệp chương trình. Tên tệp chương trình ứng với câu i là Ci_xxx.PAS, giải thích: C là viết tắt của từ &#8220;câu&#8221;, i là câu thứ i, gạch chân, xxx là số báo danh của thí sinh. Giả sử thí sinh có số báo danh là 248 thì 3 tệp chương trình có tên là C1_248.PAS, C2_248.PAS, C3_248.PAS. Cả 3 tệp chương trình đều đặt trong thư mục có chứa tệp TURBO.EXE.<!--more--></p>
<p><strong>CÂU 1</strong> (4 điểm). Lập trình nhập vào từ bàn phím một mảng hai chiều m hàng n cột gồm các xâu ký tự có độ dài tối đa 25 ký tự biểu thị tên học sinh các n tổ. In ra màn hình xâu ký tự dài nhất trong mảng và độ dài của nó. Mẫu màn hình nhập dữ liệu, in kết quả và ví dụ để kiểm tra chương trình:</p>
<p>m , n = 2  2</p>
<p>Xâu hàng 1 cột 1 = lan</p>
<p>Xâu hàng 1 cột  2 = thuyet</p>
<p>Xâu hàng 2 cột 1 = quynh</p>
<p>Xâu hàng 2 cột 2 = an</p>
<p>Xâu dài nhất = thuyet , độ dài = 6</p>
<p><strong>CÂU 2</strong> (3 điểm). Nhập một mảng A các điểm trung bình của n học sinh (n cũng nhập từ bàn phím).  Sắp xếp mảng A theo điểm trung bình giảm dần. In mảng đã sắp xếp ra màn hình.</p>
<p>Ví dụ kiểm tra chương trình:</p>
<p>A = (9.5, 8, 4.5, 5.5, 8, 7.5, 9)</p>
<p>Mảng A sau khi sắp xếp là: 4.5,  5.5,  7.5,  8,  8,  9,  9.5.</p>
<p><strong>CÂU 3</strong> (3 điểm).  Một người có số tiền là A đồng, lãi xuất có kỳ hạn của Ngân hàng ngoại thương là k phần trăm một năm. Hỏi sau t năm người gửi nhận được cả vốn và lãi là bao nhiêu, biết rằng cuối mỗi năm  tiền lãi lại gộp vào vốn. Lập trình nhập vào từ bàn phím 3 giá trị A, k, t. In ra tổng số tiền nhận được sau t năm.</p>
<p>Ví dụ để kiểm tra chương trình:</p>
<p>A, k , t = 10000000    9    3</p>
<p>Tổng số tiền : 12950290</p>
<p align="center"><span style="font-family:Arial;"><strong>Đề thi Môn Ngôn ngữ Lập trình Pascal (đề 2)</strong></span></p>
<p align="center"><span style="font-family:Arial;">Thời gian : 10 phút đọc đầu đề, 90 phút làm bài. Không sử dụng tài liệu</span></p>
<p>Họ tên thí sinh : . . . . . . . . . . . . . . . . . . . . . . . . . . .  Ngày sinh: . . . . . . . . . . . .</p>
<p>Lớp : . . . . . . . . . . Số báo danh : . . . . . . . . . . . . .  Số máy tính : . . . . . . . . . . .</p>
<p>Hướng dẫn đặt các tên tệp bài làm và nơi lưu trữ . Đề thi có 3 câu, mỗi câu cần làm một tệp chương trình. Tên tệp chương trình ứng với câu i là Ci_xxx.PAS, giải thích: C là viết tắt của từ &#8220;câu&#8221;, i là câu thứ i, gạch chân, xxx là số báo danh của thí sinh. Giả sử thí sinh có số báo danh là 248 thì 3 tệp chương trình có tên là C1_248.PAS, C2_248.PAS, C3_248.PAS. Cả 3 tệp chương trình đều đặt trong thư mục có chứa tệp TURBO.EXE.</p>
<p>CÂU 1 (4 điểm). Lập trình nhập vào từ bàn phím hai ma trận các số thực A và B đều có m hàng và n cột (m,n nhập từ bàn phím). Tính hiệu của hai ma trận theo công thức C[i,j ] = A[i,j] &#8211; B[i,j] với i = 1, . . . , m và j = 1, . . . , n. In ma trận hiệu C ra màn hình. Mẫu màn hình chạy chương trình và ví dụ để kiểm tra chương trình:</p>
<p>m , n = 2  2</p>
<p>A[1,1] = 5.5</p>
<p>A[1,2] = 5.5</p>
<p>A[2,1] = 5.5</p>
<p>A[2,2] = 10</p>
<p>B[1,1] = 2.5</p>
<p>B[1,2] = 2.5</p>
<p>B[2,1] = 2.5</p>
<p>B[2,2] = 5</p>
<p>Mảng C:</p>
<p>3.00000    3.00000</p>
<p>3.00000    5.00000</p>
<p>CÂU 2 (3 điểm). Một cửa hàng có N mặt hàng, mặt hàng i có giá là p[i] và số lượng là s[i]. Lập trình nhập vào từ bàn phím số lượng các mặt hàng N và hai mảng một chiều là P = (p[1], p[2], . . . , p[n]), S = (s[1], s[2], . . . , s[n]). In ra màn hình tổng giá trị hàng hoá có trong cửa hàng, tổng giá trị = p[1]* s[1] + p[2]* s[2] + . . . .  + p[n]* s[n].</p>
<p><span style="font-size:12pt;">Ví dụ kiểm tra chương trình: giá xe máy, tủ lạnh, máy tính P = (20000000, 7000000, 5000000), số lượng S = (10, 5, 20), tổng giá trị = 335 000 000.</span></p>
<p>CÂU 3 (3 điểm). Cho một tam giác ABC trên mặt phẳng với 3 đỉnh có toạ độ là (x1,y1), (x2,y2) và (x3,y3). Hãy tính chu vi và diện tích tam giác. Khoảng cách giữa hai đỉnh A và B là sqrt( sqr(x1-x2) + sqr(y1-y2) ). Mẫu màn hình chạy chương trình và ví dụ kiểm tra chương trình:</p>
<p><span style="font-size:12pt;"><strong>x1, y1, x2, y2. x3, y3 = 3   1   5   3   1   3</strong></span></p>
<p><strong><span style="font-size:12pt;">Chu</span><span style="font-size:12pt;"> vi = 9.65685     dien tich = 4.00000</span></strong></p>
<p><span style="font-size:12pt;"><br />
</span></p>
<p><span style="font-family:Arial;"><strong> Đề thi Môn Ngôn ngữ Lập trình Pascal  (đề 3)</strong></span></p>
<p align="center"><span style="font-family:Arial;">Thời gian : 10 phút đọc đầu đề, 90 phút làm bài. Không sử dụng tài liệu</span></p>
<p>Họ tên thí sinh : . . . . . . . . . . . . . . . . . . . . . . . . . . .  Ngày sinh: . . . . . . . . . . . .</p>
<p>Lớp : . . . . . . . . . . Số báo danh : . . . . . . . . . . . . .  Số máy tính : . . . . . . . . . . .</p>
<p>Hướng dẫn đặt các tên tệp bài làm và nơi lưu trữ . Đề thi có 3 câu, mỗi câu cần làm một tệp chương trình. Tên tệp chương trình ứng với câu i là Ci_xxx.PAS, giải thích: C là viết tắt của từ &#8220;câu&#8221;, i là câu thứ i, gạch chân, xxx là số báo danh của thí sinh. Giả sử thí sinh có số báo danh là 248 thì 3 tệp chương trình có tên là C1_248.PAS, C2_248.PAS, C3_248.PAS. Cả 3 tệp chương trình đều đặt trong thư mục có chứa tệp TURBO.EXE.</p>
<p>CÂU 1 (5 điểm). Nhập mảng A gồm m hàng n cột các số thực biểu thị n điểm các môn học của m học sinh. Tính điểm trung bình của mỗi học sinh, có bao nhiêu học sinh giỏi (có điểm trung bình &#62;= 8.0). Yêu cầu màn hình chạy chương trình và ví dụ kiểm tra:</p>
<p>m, n = 2   3</p>
<p>a[1,1] = 5</p>
<p>a[1,2] = 7</p>
<p>a[1,3] = 6.5</p>
<p>a[2,1] = 9</p>
<p>a[2,2] = 8</p>
<p>a[2,3] = 10</p>
<p>Điểm trung bình của học sinh thứ 1 = 6.17</p>
<p>Điểm trung bình của học sinh thứ 2 = 9.00</p>
<p>Số học sinh giỏi = 1</p>
<p>CÂU 2 (3 điểm). Nhập họ tên n sinh viên của một lớp học vào một mảng A. Sắp xếp mảng A tăng dần và in ra màn hình mảng đã sắp xếp. Yêu cầu trình bày màn hình và ví dụ kiểm tra chương trình:</p>
<p>n =  3</p>
<p>Họ tên sinh viên thứ 1 = le xuan minh</p>
<p>Họ tên sinh viên thứ 2 = tran van hieu</p>
<p>Họ tên sinh viên thứ 3 = bui van thanh</p>
<p>Mảng họ tên đã sắp xếp:</p>
<p>bui van thanh &#8211; le xuan minh &#8211; tran van hieu -</p>
<p>CÂU 3 (2 điểm). Trên quốc lộ 1A hai ô tô cùng khởi hành từ hai thành phố A và B chạy theo hướng AB. Ô tô xuất phát từ A có vận tốc là V1 km/h, ô tô xuất phát từ thành phố B có vận tốc là V2 km/h, V1 &#62; V2. Khoảng cách giữa hai thành phố là D km. Lập trình nhập vào từ bàn phím V1, V2, D, in ra màn hình sau bao nhiêu giờ thì hai ô tô đuổi kịp nhau. Yêu cầu trình bày màn hình và ví dụ để kiểm tra chương trình:</p>
<p>V1, V2, D = 120  80   300</p>
<p>Hai ô tô gặp nhau sau khoảng thời gian = 7.5 giờ</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal: Unit Graph]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/turbo-pascal-unit-graph/</link>
<pubDate>Mon, 19 Oct 2009 02:16:31 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/turbo-pascal-unit-graph/</guid>
<description><![CDATA[Màn hình máy tính có hai chế độ hiển thị thông tin: chế độ văn bản và chế độ đồ hoạ. Trong chế độ đồ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><div>
<p>Màn hình máy tính có hai chế độ hiển thị thông tin: chế độ văn bản và chế độ đồ hoạ. Trong chế độ đồ hoạ màn hình chia thành lưới vuông các điểm ảnh (pixel).      Màn hình thông dụng hiện nay (VGA) trong chế độ đồ hoạ với độ phân giải cao có 640 cột điểm ảnh đánh số từ 0 đến 639 (ứng với trục X hướng sang phải) và 480 hàng điểm ảnh đánh số từ 0 đến 479 (ứng với trục Y hướng từ trên xuống dưới). Ta có thể vẽ (cho điểm sáng) và tô màu từng điểm ảnh để tạo một hình bất kỳ trên màn hình. Trong chế độ đồ hoạ màn hình cũng có con trỏ vẽ nhưng nó không hiện.<!--more--></p>
<p>Để làm việc trong chế độ đồ hoạ trên đĩa phải có tệp <strong><span style="font-size:11pt;">Graph.tpu</span></strong> (chứa các hàm và thủ tục về đồ hoạ thuộc Unit Graph), tệp <strong><span style="font-size:11pt;">EgaVga.bgi</span> </strong>(trình điều khiển màn hình VGA) và 10 tệp <strong><span style="font-size:11pt;">chr</span></strong> chứa các phông chữ véc tơ (Trip.chr, Litt.chr, Sans.chr, Goth.chr, Scri.chr, Simp.chr, Tscr.chr, Lcom.chr, Euro.chr, Bold.chr). Bắt đầu một chương trình đồ hoạ bao giờ cũng phải có lệnh:  <strong><span style="font-size:11pt;">uses graph;</span></strong></p>
<p><strong><span style="font-size:14pt;font-family:Arial;">1. Khởi động chế độ đồ hoạ, màu sắc</span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục InitGraph(var gd, gm: integer; path: string)</strong>: khởi động chế độ đồ hoạ (khai báo loại màn hình và độ phân giải). Tham số <strong><span style="font-size:11pt;">path</span></strong> chứa đường dẫn tới thư mục lưu tệp BGI, nếu tệp BGI để ở thư mục hiện hành thì path là xâu rỗng. Với màn hình thông dụng VGA hiện nay tham số <strong><span style="font-size:11pt;">gd</span></strong> (graphic driver, trình điều khiển màn hình) lấy bằng hằng số VGA=9. Với màn hình VGA tham số về độ phân giải màn hình <strong><span style="font-size:11pt;">gm</span></strong> (graphic mode, mode màn hình) có thể nhận các hằng số: VgaLo= 0 (200&#215;640 điểm ảnh), VgaMed= 1 (350&#215;640 điểm), VgaHi = 2 (480&#215;640 điểm). Các tham số trong lời gọi thủ tục có thể viết ở dạng tên hằng hoặc giá trị số. Nếu trước khi gọi thủ tục này ta gán biến gd bằng hằng số Detect (<strong><span style="font-size:11pt;">gd:=Detect;</span></strong>) thì máy sẽ tự động tìm chương trình điều khiển thích hợp với loại màn hình đang sử dụng và cho gm nhận giá trị ứng với độ phân giải cao nhất.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm GraphResult: integer</strong> cho mã lỗi của lời gọi đồ hoạ cuối cùng. Nếu không có lỗi hàm trả về giá trị 0 (hay hằng GrOK), trái lại cho giá trị khác 0.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Hàm GetMaxX</strong> cho toạ độ trục X lớn nhất, <strong>hàm GetMaxY</strong> cho toạ độ trục Y lớn nhất. Điểm giữa màn hình có toạ độ là (getmaxx div 2, getmaxy div 2).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục ClearDevice</strong>: xoá màn hình đồ hoạ và đưa con trỏ vẽ về vị trí (0,0).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Hàm GetX</strong> cho biết toạ độ cột hiện tại của con trỏ vẽ, <strong>Hàm GetY</strong> cho toạ độ dòng hiện tại của con trỏ.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục</strong> <strong>MoveToXY</strong>(x,y: Integer) : di chuyển con trỏ vẽ đến toạ độ (x,y).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục</strong> <strong>CloseGraph</strong> : đóng chế độ đồ hoạ, trở về chế độ văn bản.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục SetBkColor(N: word)</strong>: lấy màu thứ N trong bảng màu làm màu nền mới , N có thể nhận giá trị từ 0 đến 15. Trong bảng màu, màu thứ 0 quy định là màu nền, như vậy lời gọi SetBkColor(Red) tương đương với lời gọi SetPalette(0,Red). Sau khi khởi động đồ hoạ màu nền ngầm định là Black = 0. Màu nền có hiệu lực cho đến khi gặp lệnh SetBkColor mới.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục SetColor(N : word)</strong>: lấy màu thứ N trong bảng màu làm màu vẽ mới, N có thể nhận giá trị từ 0 tới 15. Màu vẽ ngầm định là White. Màu vẽ có hiệu lực cho đến khi gặp lệnh SetColor mới. Chú ý lệnh SetColor không làm thay đổi bảng màu, còn lệnh SetBkColor làm thay đổi bảng màu.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">2. Vẽ điểm và đường</span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục</strong> <strong>PutPixel(x,y: integer; color: word)</strong>: vẽ một điểm ảnh theo màu đã xác định bởi color tại toạ độ (x,y).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Line(x1,y1,x2,y2: integer)</strong>: vẽ đoạn thẳng nối (x1,y1) với (x2,y2), con trỏ không thay đổi vị trí.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục LineTo(x,y: integer)</strong>: vẽ một đoạn thẳng từ vị trí hiện thời của con trỏ tới điểm có toạ độ (x,y), con trỏ về vị trí mới. Ví dụ về dùng lệnh Line và Lineto có thể xem chương trình KhoiDong.pas của Mục 1, SetPalet.pas và MauNen.pas của Mục 2.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục LineRel(dx,dy: integer)</strong>: vẽ đoạn thẳng từ vị trí hiện tại (x,y) của con trỏ tới vị trí (x+dx, y+dy) và di chuyển con trỏ tới vị trí mới</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Rectangle(x1,y1,x2,y2: integer)</strong>: vẽ một đường chữ nhật có các cạnh song song với các cạnh của màn hình, với toạ độ góc trên trái là (x1,y1) và góc dưới phải là (x2,y2). Điều kiện 0&#60;=x1&#60;=x2&#60;= GetMaxx, 0&#60;=y1&#60;=y2&#60;= GetMaxy.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục SetLineStyle(LineStyle, Pattern, Thickness : word)</strong> thiết lập kiểu vẽ các đường thẳng. Tham số LineStyle dùng để thiết lập kiểu đường và có thể nhận các giá trị: SolidLn = 0 (đường nét liền), DottedLn=1 (đường nét chấm chấm), CenterLn=2 (đường nét chấm gạch), DasheLn=3 (đường nét gạch), UserBitLn=4 (đường do người dùng tự định nghĩa). Tham số Thickness xác định độ lớn của đường, các giá trị có thể nhận: NormWidth=1 (nét bình thường, ngầm định), ThickWidth=3 (nét to).</p>
<p>Tham số Pattern xác định mẫu vẽ đường. Nếu LineStyle = 0, 1, 2 hay 3 thì cho Pattern=0 (ngầm định). Nếu dùng LineStyle=4 thì Pattern là một số gồm 16 bít chỉ kiểu mẫu của đường. Chẳng hạn, nếu mẫu 16 bít là 0001 0001 0001 0001 (hệ 2) = $1111 (hệ 16) thì Pattern = $1111, đường thẳng sẽ là đường chấm chấm thưa (vị trí bit bằng 1 sẽ có chấm điểm)</p>
<p>Chương trình <strong>SetLine.pas</strong> minh hoạ cách dùng thủ tục SetLineStyle:</p>
<p>uses graph;</p>
<p>var gd, gm: Integer; x1, y1, x2, y2: integer;</p>
<p>begin  gd := detect;  InitGraph(gd,gm, &#8216; &#8216;);</p>
<p>if GraphResult &#60;&#62; grOk then  Halt(1);</p>
<p>x1 := 10; y1 := 10; x2 := 600; y2 := 400;</p>
<p>SetLineStyle(DottedLn, 0, NormWidth);</p>
<p>Rectangle(x1,y1,x2,y2); readln; cleardevice;</p>
<p>SetLineStyle(UserBitLn,$C3,ThickWidth);{0000 0000 1100 0011}</p>
<p>Rectangle(Pred(x1),Pred(y1),Succ(x2),Succ(y2));</p>
<p>readln; CloseGraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục</strong> <strong>DrawPoly</strong>(N, A) vẽ một đường gấp khúc đi qua N điểm theo kiểu đường và màu vẽ hiện tại. A là mảng gồm N phần tử chứa toạ độ các điểm mút, mỗi phần tử có kiểu PointType được định nghĩa sẵn bởi unit Graph như sau:</p>
<p align="center">PointType = Record  X, Y : Integer   End;</p>
<p>trong đó X là toạ độ cột của điểm, Y là toạ độ hàng của điểm. Khi điểm cuối trùng với điểm đầu thì ta được một đường gấp khúc khép kín. Trong chương trình mảng các bản ghi A có thể nhập vào từ bàn phím, từ tệp văn bản (nếu nhiều điểm) hoặc gán trực tiếp.</p>
<p>Chương trình <strong>TamGiac.pas</strong>: vẽ một tam giác.</p>
<p>uses graph;</p>
<p>const  Triangle: array[1..4] of PointType =</p>
<p>((x:100;y:100),(x:600;y:150),(x:320;y:450),(x:100;y:100));</p>
<p>var gd, gm: integer;</p>
<p>begin  gd:=Detect; InitGraph(gd,gm,&#8221;);</p>
<p>if GraphResult &#60;&#62; grOk then Halt(1); SetLineStyle(0,0,3);</p>
<p>DrawPoly(SizeOf(Triangle) div SizeOf(PointType), Triangle);</p>
<p>readln; closegraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Circle(x, y: integer; r: word)</strong>: vẽ đường tròn tâm (x,y) và bán kính r.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Arc(x, y: integer;  gocdau, goccuoi, r: word)</strong> vẽ cung tròn có tâm là <em>(x,y)</em>, bán kính <em>r</em> từ góc xuất phát là <em>gocdau</em> đến góc kết thúc là <em>goccuoi</em> , các góc có giá trị từ 0 đến 360 độ.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Ellipse(x, y : integer ; gocdau, goccuoi, rx, ry : word)</strong> vẽ một cung ellip có tâm <em>(x, y)</em> với bán kính ngang là <em>rx</em>, bán kính dọc <em>ry</em> từ góc xuất phát <em>gocdau</em> đến góc kết thúc <em>goccuoi</em>.</p>
<p>Chương trình <strong>Circle.pas</strong> vẽ các đường tròn đồng tâm và các cung tròn nét to.</p>
<p>uses graph;</p>
<p>var gd, gm: integer; Radius: integer;</p>
<p>begin gd := Detect; InitGraph(gd, gm, &#8216; &#8216;);</p>
<p>if GraphResult &#60;&#62; grOk then  Halt(1);  setlinestyle(0,0,3);</p>
<p>for Radius:=1 to 23 do Circle(320,240,Radius*10);</p>
<p>readln; ClearDevice; SetColor(LightMagenta);</p>
<p>for Radius:=1 to 23 do Arc(320,240,0,280,Radius*10);</p>
<p>readln; closegraph;</p>
<p>end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">3. Vẽ và tô miền</span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục SetFillStyle(pattern: word ; color: word)</strong>: chọn mẫu tô (pattern) và màu tô (color) cho các hình đặc (các hình vẽ bởi FillPoly, Bar, Bar3D, PieSlice &#8230;.). Pattern có giá trị từ 0 đến 12: hằng số EmptyFill hay bằng 0 là tô bằng màu nền, SolidFill = 1 là tô bằng đường nét liền, SlashFill = 4 là tô bằng các đường ///// đậm, CloseDotFill = 11 là tô bằng các dấu chấm sát nhau&#8230; Nếu Pattern có giá trị bằng UserFill=12 thì mẫu và màu tô của người dùng đặt bởi lệnh SetFillPattern có tác dụng. Ngầm định Pattern = 1, Color = White.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục FloodFill(x,y: integer; border: word)</strong>: tô màu một miền kín giới hạn bởi một đường bao quanh, trong đó (x,y) là toạ độ một điểm bất kỳ thuộc phần trong của miền cần tô. Biến Border là màu của đường viền bao quanh miền.  Mẫu tô và màu tô xác định bởi lệnh SetFillStyle(). Nếu toạ độ (x,y) ở ngoài miền kín thì vùng ngoài miền kín được tô màu. Nếu trên màn hình không có miền kín mà đường viền bao quanh có màu Border hay miền định tô bị hở thì toàn màn hình được tô màu.</p>
<p>Chương trình <strong>FloodF.pas</strong>: vẽ đường chữ nhật và tô màu bên trong, tô màu miền ngoài một đường tròn.</p>
<p>uses Graph;</p>
<p>var gd, gm: integer;</p>
<p>begin gd:= Detect; InitGraph(gd,gm,&#8221;);</p>
<p>if GraphResult &#60;&#62; grOk then   Halt(1);</p>
<p>SetColor(Cyan); SetFillStyle(1,Red);</p>
<p>Rectangle(220,140,420,340); readln;</p>
<p>FloodFill(300,220,Cyan); Readln;</p>
<p>Cleardevice; SetColor(white); SetFillStyle(1,Lightblue);</p>
<p>Circle(320,240,200); readln;</p>
<p>FloodFill(30,20,white); readln;</p>
<p>CloseGraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Bar(x1,y1,x2,y2: integer)</strong>: vẽ và tô màu hình chữ nhật với mẫu tô và màu tô xác định bởi lệnh SetFillStyle.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Bar3D(x1,y1,x2,y2: integer; dept: word; top: boolean)</strong>: vẽ một khối hộp chữ nhật, mặt trước là hình chữ nhật được tô màu xác định bởi (x1,y1) và (x2,y2) như trong thủ tục Bar. Tham số Dept: độ sâu của khối hộp. Top bằng TopOn: hộp có nắp, Top=TopOff  là hộp không nắp.</p>
<p>Chương trình <strong>KhoiHop.pas</strong> : vẽ hình chữ nhật, khối hộp có tô màu các mặt.</p>
<p>uses graph;</p>
<p>var gd, gm: integer;</p>
<p>begin  gd:=Detect; InitGraph(gd,gm,&#8221;);</p>
<p>if GraphResult &#60;&#62; grOk then Halt(1);</p>
<p>Bar(1,1,100,100);</p>
<p>SetColor(Cyan); SetFillStyle(1,lightred);</p>
<p>Bar3D(150,130,440,470,150,topon);</p>
<p>setFillStyle(8,Blue); FloodFill(300,125,Cyan);</p>
<p>setFillStyle(11,LightGreen); FloodFill(450,165,Cyan);</p>
<p>readln; closegraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục FillPoly(N, A) </strong>vẽ và tô màu một đa giác có N đỉnh, mảng A chứa toạ độ các đỉnh như trong thủ tục DrawPoly.</p>
<p>Chương trình <strong>CoSao.pas</strong> vẽ lá cờ Việt nam.</p>
<p>uses graph;</p>
<p>const  Sao: array[1..10] of PointType =</p>
<p>((x:439;y:201),(x:352;y:196),(x:320;y:115),(x:288;y:196),</p>
<p>(x:201;y:201),(x:268;y:257),(x:247;y:341),(x:320;y:295),</p>
<p>(x:393;y:341),(x:372;y:257));</p>
<p>var gd, gm: integer;</p>
<p>begin  gd:=Detect; InitGraph(gd,gm,&#8221;);</p>
<p>SetBkColor(LightRed); SetColor(Yellow); SetFillStyle(1,Yellow);</p>
<p>FillPoly(10,Sao); readln; closegraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục PieSlice(x, y : integer;  gocdau, goccuoi, r : word)</strong> vẽ và tô màu một hình quạt có tâm là <em>(x,y)</em> với bán kính <em>r</em> từ góc xuất phát <em>gocdau</em> đến góc kết thúc <em>goccuoi</em>. Mẫu tô và màu tô xác định theo lệnh SetFillStyle.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục FillEllipse( x, y : integer ; rx , ry : word)</strong> vẽ và tô màu một ellipse có tâm <em>(x, y)</em> và các bán kính trục là <em>rx, ry</em>. Mẫu tô và màu tô xác định theo thủ tục SetFillStyle.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Sector( x, y: integer; gocdau , goccuoi, rx, ry : word)</strong> vẽ và tô màu một phần ellipse có tâm <em>(x, y)</em> với các bán kính trục <em>rx, ry</em> từ góc xuất phát <em>gocdau</em> đến góc kết thúc <em>goccuoi</em>. Mẫu tô và màu tô xác định theo lệnh SetFillStyle.</p>
<p>Chương trình <strong>MienTron.pas</strong> minh hoạ cách dùng 3 thủ tục trên.</p>
<p>uses Graph;</p>
<p>var gd, gm: integer;</p>
<p>begin gd:= Detect; InitGraph(gd,gm,&#8221;);</p>
<p>SetColor(Cyan); SetFillStyle(1,Red);</p>
<p>FillEllipse(320,240,250,150); readln; Cleardevice;</p>
<p>SetColor(LightGreen); SetFillStyle(1,LightGreen);</p>
<p>FillEllipse(320,240,200,200); readln; Cleardevice;</p>
<p>SetColor(White); SetFillStyle(1,LightMagenta);</p>
<p>PieSlice(320,240,15, 360-15,200); readln; Cleardevice;</p>
<p>SetColor(LightRed); SetFillStyle(1,LightBlue);</p>
<p>Sector(320,240,30,360-30,250,200); readln; CloseGraph;</p>
<p>end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">4. Cửa sổ trong chế độ đồ hoạ</span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục SetViewPort(x1,y1,x2,y2: Integer; Clip: Boolean)</strong>: định nghĩa một ViewPort (một vùng chữ nhật trên màn hình) giới hạn bởi góc trên trái là (x1,y1) và góc dưới phải là (x2,y2). Nếu Clip là hằng ClipON  thì cấm vẽ ở ngoài ViewPort, nếu Clip  bằng ClipOff thì có thể vẽ bên ngoài ViewPort. Sau khi gọi thủ tục này toạ độ (0,0) của tất cả các thủ tục vẽ là góc trên trái của Viewport chứ không phải là góc trên bên trái màn hình. Do đó nhờ viewport và cho phép vẽ ra ngoài ta có thể tạo được toạ độ âm dương trên màn hình.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục</strong> <strong>ClearViewPort</strong>: xoá vùng màn hình giới hạn bởi ViewPort.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục GraphDefaults</strong> thường được gọi ngay sau thủ tục ClearViewPort để khởi tạo lại tất cả các giá trị mặc định của ViewPort ngầm định (toàn màn hình).</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">5 Viết chữ trong chế độ đồ hoạ </span></strong></p>
<p>Trong chế độ đồ hoạ ta có thể viết lên màn hình các dòng chữ với các phông chữ và kích cỡ khác nhau, dòng chữ cũng có thể viết theo chiều dọc màn hình.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục SetTextStyle(Font, Direction, Size: word) </strong>đặt kiểu phông chữ, hướng viết, cỡ chữ. Tham số <strong>Font</strong> nhận các giá trị: DefaultFont = 0 (phông chữ ngầm định của hệ thống, không cần tệp chr), TriplexFont = 1 (cần tệp Trip.chr), SmallFont = 2 (Litt.chr), SansSerifFont = 3 (Sans.chr), GothicFont = 4 (Goth.chr), ScriptFont = 5 (Scri.chr), SimplexFont = 6 (Simp.chr), TriplexScriptFont = 7 (Tscr.chr), ComplexFont = 8 (Lcom.chr), EuropeanFont = 9 (Euro.chr), BoldFont = 10 (Bold.chr). Tham số <strong>Direction</strong> nhận các giá trị: HorizDir = 0 (viết theo hàng ngang, ngầm định), VertDir = 1 (viết dọc màn hình). <strong>Size</strong> nhận giá trị từ 1 đến 10 (độ phóng của phông chữ). Với font hệ thống cỡ chữ bình thường là 1.</p>
<p>Chương trình <strong>Font.pas</strong> in ra 11 loại phông chữ với tất cả các cỡ từ 1 đến 10. Mười tệp phông chữ CHR để ở thư mục C:\TP\BGI.</p>
<p>uses Graph;</p>
<p>var gd, gm, font,y, size: integer; s1,s2:string[4];</p>
<p>begin gd := detect; InitGraph(gd, gm, &#8216;c:\tp\bgi&#8217;);</p>
<p>if GraphResult &#60;&#62; grOk then   Halt(1); SetColor(Cyan);</p>
<p>for font:=0 to 10 do</p>
<p>begin  ClearDevice; y := 0;</p>
<p>for size := 1 to 10 do</p>
<p>begin str(font,s1);str(size,s2);SetTextStyle(font,HorizDir,Size);</p>
<p>OutTextXY(0,Y,&#8217;Font=&#8217;+s1+&#8217; size=&#8217;+s2); inc(y,TextHeight(&#8216;H&#8217;)+1);</p>
<p>end; Readln;</p>
<p>end; CloseGraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục OutTextXY(x, y: integer; St : string)</strong> hiện nội dung của xâu ký tự St theo vị trí (x,y).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục OutText(St: string)</strong> hiện xâu St theo vị trí hiện hành của con trỏ.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục SetTextJustify(Horiz, Vert: word)</strong> quy định nơi hiển thị xâu ký tự của OutText theo quan hệ với vị trí hiện tại của con trỏ (giả sử là điểm M=(x,y)), hay của OutTextXy theo quan hệ với toạ độ đã chỉ định M=(x,y). Tham số <strong>Horiz</strong> nhận các giá trị: LeftText=0 (điểm M nằm phía trái xâu, ngầm định), CenterText=1 (điểm M nằm giữa xâu theo chiều ngang), RightText=2 (điểm M nằm phía phải xâu). Tham số <strong>Vert</strong> nhận giá trị : BottomText=0 (điểm M nằm dưới xâu ký tự), CenterText=1 (điểm M nằm giữa xâu theo chiều dọc), TopText=2 (điểm M nằm phía trên xâu, ngầm định).</p>
<p>Chương trình <strong>Justify.pas</strong> biểu diễn tất cả các cách căn chỉnh xâu ký tự theo quan hệ với điểm (x,y). Trong chế độ đồ hoạ ta vẫn có thể dùng các lệnh Readln để nhập dữ liệu, Write và Writeln để in dữ liệu ra màn hình, để làm được điều này ở đầu chương trình phải có lệnh <strong><span style="font-size:11pt;">uses crt</span></strong> và biến <strong><span style="font-size:11pt;">DirectVideo</span></strong> của unit crt phải đặt lại bằng False (để bỏ quyền trực tiếp truy nhập của unit Crt vào vùng Video Ram). Chương trình in tất cả các thông số ngầm định về phông chữ sau khi khởi động đồ hoạ, vào chiều dài và chiều rộng hình chữ nhật từ bàn phím và in ra diện tích của nó.</p>
<p>uses crt,graph;</p>
<p>var gd, gm,x,y,n,d: integer; s1,s2: string[4];</p>
<p>ts: TextSettingsType;</p>
<p>begin gd:=Vga; gm:= VgaHi; InitGraph(Gd,Gm,&#8217;c:\tp\bgi&#8217;);</p>
<p>if GraphResult &#60;&#62; grOk then Halt(1);</p>
<p>GetTextSettings(ts); DirectVideo:= False;</p>
<p>write(&#8216;Font = &#8216;,ts.font); writeln(&#8216;  Direction = &#8216;,ts.direction);</p>
<p>writeln(&#8216;CharSize = &#8216;,ts.charsize);</p>
<p>writeln(&#8216;Horiz = &#8216;,ts.horiz,&#8217;  Vert = &#8216;,ts.vert);</p>
<p>write(&#8216;Vao chieu dai va chieu rong : &#8216;);  readln(n,d);</p>
<p>write(&#8216;Dien tich hinh chu nhat la : &#8216;,n*d); readln;</p>
<p>ClearDevice; SetTextStyle(0,0,5);</p>
<p>for n:=0 to 2 do for d:=0 to 2 do</p>
<p>begin SetTextJustify(n,d); Str(n,s1); Str(d,s2);</p>
<p>x:= 320 ; y:= 240;  SetColor(Cyan);</p>
<p>OutTextXY(x,y,&#8217;N=&#8217;+s1+&#8217; D=&#8217;+s2);  FillEllipse(x,y,3,3);</p>
<p>Readln; ClearDevice;</p>
<p>end; CloseGraph;</p>
<p>end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm TextHeight(St: string)</strong> trả về độ cao của xâu St tính bằng điểm.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm TextWidth(St: string)</strong> trả về chiều rộng của xâu St tính bằng điểm.</p>
<p>Chương trình <strong>TextH.pas</strong> : in xâu &#8216;VIET NAM &#8216; theo các cỡ lớn dần trên các dòng cho đến khi xâu rộng quá màn hình thì kết thúc.</p>
<p>uses graph;</p>
<p>var gd, gm: Integer;</p>
<p>y: integer; s: string; size: integer;</p>
<p>begin gd := detect; InitGraph(gd, gm,&#8221;);</p>
<p>if GraphResult &#60;&#62; grOk then   Halt(1);</p>
<p>y := 0; s := &#8216;VIET NAM &#8216;; size := 1;</p>
<p>while TextWidth(s) &#60; GetMaxX do</p>
<p>begin  OutTextXY(0, y, s);</p>
<p>inc(y, TextHeight(&#8216;H&#8217;)+3); inc(size);</p>
<p>SetTextStyle(DefaultFont, HorizDir, size);</p>
<p>end;</p>
<p>readln; CloseGraph;</p>
<p>end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">6 Tạo ảnh chuyển động</span></strong></p>
<p><strong><span style="font-size:13pt;font-family:Arial;">a) Các hàm và thủ tục tạo ảnh chuyển động</span></strong></p>
<p>Một ảnh được lưu trữ trong bộ nhớ bằng tập hợp các bit (gọi là ảnh bit, bit image), chẳng hạn với ảnh 16 màu thì mỗi pixel tương ứng với 4 bit (ứng với một màu từ 0, 1, 2, . . ., 15). Việc xử lý ảnh bit được tiến hành theo từng bit.</p>
<p>Các hàm và thủ tục sau dùng để tạo ảnh chuyển động:</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Hàm ImageSize(x1, y1, x2, y2: integer): word</strong> xác định  số byte cần thiết cho thủ tục GetImage lưu vùng chữ nhật trên màn hình  (x1, y1, x2, y2). Kích thước ảnh bao gồm thêm cả ba word: word đầu lưu độ rộng của vùng chữ nhật, word thứ hai lưu chiều cao vùng, word thứ ba dùng để dự trữ. Máy lưu các điểm ảnh theo hàng, mỗi điểm ảnh chiếm 4 bít, nếu số lượng [(số điểm ảnh một hàng * 4 bit) / 8 bit] byte không chia hết cho 4 thì máy sẽ thêm từ 1 đến 3 byte để số byte cần lưu một hàng chia hết cho 4. Ví dụ nếu vùng ảnh là (1,1,100,100) thì số byte cần thiết để lưu vùng ảnh là [(100 điểm * 4 bit / 8 bit + 2 byte] * 100 hàng + 6 byte = 5206 byte. Nếu bộ nhớ yêu cầu để lưu vùng lớn hơn 64 KB thì hàm trả về giá trị 0 và GraphResult = -11.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục GetImage(x1, y1, x2, y2: integer; var BitMap)</strong> chép ảnh bit nằm trong vùng chữ nhật (x1, y1, x2, y2) vào biến BitMap. BitMap là một tham số không định kiểu. Hai word đầu tiên của BitMap lưu trữ chiều rộng và chiều cao của vùng, word thứ ba dùng để dự trữ, phần còn lại của BitMap được dùng để ghi ảnh bit. Dùng hàm ImageSize để xác định yêu cầu về kích thước của BitMap.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục PutImage(x,y: integer; var BitMap ; BitBlt: word)</strong>: đặt ảnh bit lưu trong BitMap lên màn hình, góc trên bên trái của vùng ảnh có toạ độ là (x, y). BitMap là tham số không định kiểu chứa chiều cao và chiều rộng của vùng ảnh, và ảnh bit sẽ được đặt lên màn hình. Tham số BitBlt xác định phép toán thao tác bit nào sẽ được dùng để đặt ảnh bit lên màn hình. Mỗi một hằng số tương ứng với một phép toán thao tác bit:</p>
<p><span style="font-size:10pt;font-family:Arial;">Tên hằng                             Giá trị                      Phép toán bit</span></p>
<p>CopyPut, NormalPut           0                             MOV</p>
<p>XORPut                             1                             XOR</p>
<p>ORPut                                2                             OR</p>
<p>ANDPut                             3                             AND</p>
<p>NOTPut                             4                             NOT</p>
<p>Ý nghĩa các phép toán thao tác bit:</p>
<p><span style="font-size:10pt;font-family:Arial;">Bit A (ảnh)      Bit B (nền)   A and B       A or B       C=A xor B      A xor C      not A</span></p>
<p>1                   1                 1                 1               0                   1               0</p>
<p>1                   0                 0                 1               1                   0</p>
<p>0                   1                 0                 1               1                   1               1</p>
<p>0                   0                 0                 0               0                   0</p>
<p>Ví dụ, PutImage(x, y, BitMap, NormalPut) sẽ đặt ảnh lưu trong Bitmap tại (x,y) bằng cách dùng lệnh MOV của ngôn ngữ Assembler với từng byte trong ảnh (ảnh mới sẽ ghi đè lên ảnh cũ trên màn hình). Lệnh PutImage(x, y, BitMap, XorPut) sẽ đặt ảnh lưu trong BitMap tại (x,y) bằng cách dùng lệnh XOR của ngôn ngữ Assembler với từng byte trong ảnh, lệnh này thường dùng để tạo ảnh chuyển động trên màn hình có nền. Lệnh PutImage(x, y, Bitmap, NotPut): đảo các bit  trong BitMap, sau đó đặt ảnh lưu trong Bitmap lên màn hình tại (x,y) bằng cách dùng lệnh MOV với từng byte trong ảnh, như vậy ảnh sẽ bị đảo so với ảnh gốc.</p>
<p>Từ cột 5 và cột 6 của bảng trên ta có nhận xét: khi in hai lần một ảnh vào cùng một vị trí theo cách XorPut thì ảnh sẽ bị xoá và nền cũ hiện lại (cột 6 trùng với cột 2). Ta sẽ ứng dụng nhận xét này để tạo ảnh chuyển động mà vẫn giữ nguyên màn hình nền. Từ cột 5 ta thấy: dùng cách XorPut để in ảnh thì ảnh bị đổi màu (xem chương trình XorPut.pas ở dưới), nếu ảnh vẽ và ảnh nền cùng màu thì màu kết quả theo cách XorPut là màu nền.</p>
<p>Chương trình <strong>PutImag.pas</strong>: lưu vùng ảnh chữ nhật vào P^, 21 lần in ảnh lưu ra màn hình theo cách CopyPut.</p>
<p>uses Graph;</p>
<p>var Gd, Gm,i: Integer; P: Pointer; Size: Word;</p>
<p>begin Gd := Detect; InitGraph(Gd, Gm, &#8216; &#8216;);</p>
<p>if GraphResult &#60;&#62; grOk then   Halt(1);</p>
<p>Bar(0, 0, GetMaxX, GetMaxY);</p>
<p>Size := ImageSize(10, 20, 30, 40); GetMem(P, Size);</p>
<p>GetImage(10, 20, 30, 40, P^); Readln; ClearDevice;</p>
<p>for i:=0 to 20  do PutImage(10+i*22, 10+i*22, P^, CopyPut);</p>
<p>Readln; CloseGraph;</p>
<p>end.</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">b) Tạo ảnh chuyển động không có màn hình nền</span></strong>. Phương pháp này chỉ sử dụng trong trường hợp vật chuyển động qua vùng màn hình trơn (không có ảnh các vật thể khác, chỉ có màu nền). Các bước thực hiện: tạo ảnh bằng màu vẽ, xoá ảnh bằng màu nền, tạo lại ảnh bằng màu vẽ tại vị trí mới</p>
<p>Chương trình <strong>Bong.pas</strong>: vẽ một quả bóng màu đỏ trên nền Cyan, khi ấn một phím mũi tên quả bóng liên tục chuyển động theo hướng mũi tên cho đến biên màn hình, ấn phím ESC để dừng chương trình.</p>
<p>uses crt,graph;</p>
<p>const r=50; s=3;</p>
<p>var gd,gm,x,y,mx,my,nen: integer; c: char;</p>
<p>procedure Bong(x,y,mau: word);</p>
<p>begin setcolor(mau); setfillstyle(1,mau); fillellipse(x,y,r,r);</p>
<p>end;</p>
<p>begin gd:= detect; initgraph(gd,gm,&#8221;);</p>
<p>nen:=cyan; setbkcolor(nen); mx:= getmaxx; my:= getmaxy;</p>
<p>randomize; x:= random(mx-2*r)+r; y:=random(my-2*r)+r;</p>
<p>bong(x,y,red);</p>
<p>repeat  c := readkey;</p>
<p>if (c = #0) then</p>
<p>begin c := readkey;</p>
<p>case c of</p>
<p>#75: while (not keypressed) and (x&#62;r) do</p>
<p>begin bong(x,y,nen);x:=x-s;bong(x,y,red);delay(100) end;</p>
<p>#77: while (not keypressed) and (x</p>
<p>begin bong(x,y,nen);x:=x+s;bong(x,y,red);delay(100) end;</p>
<p>#72: while (not keypressed) and (y&#62;r) do</p>
<p>begin bong(x,y,nen);y:=y-s;bong(x,y,red);delay(100) end;</p>
<p>#80: while (not keypressed) and (y</p>
<p>begin bong(x,y,nen);y:=y+s;bong(x,y,red);delay(100) end;</p>
<p>end;</p>
<p>end;</p>
<p>until c=#27; closegraph;</p>
<p>end.</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">c) Tạo ảnh chuyển động trên một màn hình nền</span></strong></p>
<p>Thuật toán tạo ảnh chuyển động mà không xoá nền:</p>
<p>1. Vẽ ảnh trong vùng (x1, y1, x2, y2),</p>
<p>2. Tính số byte cần thiết để lưu ảnh thuộc vùng chữ nhật nhờ hàm ImageSize (giả sử là n), cấp phát vùng nhớ n byte và cho con trỏ P trỏ vào byte đầu tiên của vùng nhớ này bằng lệnh GetMem,</p>
<p>3. Dùng lệnh GetImage để chép ảnh từ vùng chữ nhật (x1, y1, x2, y2) vào vùng nhớ vừa cấp phát (ứng với biến động P^),</p>
<p>4. Xoá màn hình, tạo màn hình nền hoàn toàn mới,</p>
<p>5. Dùng lệnh PutImage in ảnh lưu trong P^ ra màn hình tại toạ độ (x,y) theo cách XorPut, dừng chương trình một lát, thay đổi các thành phần x,y để được điểm (x,y) mới, dùng PutImage in lại ảnh vẫn tại toạ độ (x,y) cũ theo cách XorPut để xoá ảnh và khôi phục nền cũ, dùng PutImage in ảnh ở điểm (x,y) mới . . . Thời gian giữa xoá ảnh cũ và in ảnh mới càng ngắn càng tốt.</p>
<p>Chương trình <strong>CDong.pas</strong>: vẽ một viên đạn nghiêng sang phải 45 độ, ghi ảnh vào biến con trỏ P, đặt nền màn hình màu Cyan, viết 2 dòng chữ màu Blue ở giữa màn hình, vẽ một mặt trăng màu trắng ở giữa nửa trên màn hình. Cho 4 viên đạn xuất phát ngẫu nhiên từ cạnh trái màn hình và từ cạnh đáy màn hình chuyển động từ phía trái sang phía phải  với góc nghiêng 45 độ.</p>
<p>uses graph,crt;</p>
<p>var gd,gm,x1,y1,x2,y2,x3,y3,x4,y4,u1,u2,u3,u4,v1,v2,v3,v4:integer;</p>
<p>p: pointer;</p>
<p>begin gd:=VGA; gm:=VgaHi; initgraph(gd,gm,&#8221;);</p>
<p>setcolor(red); setfillstyle(1,red);</p>
<p>line(0,12,8,20); line(8,20,18,10); line(18,10,20,0);</p>
<p>line(20,0,10,2); line(10,2,0,12);</p>
<p>floodfill(10,10,red); readln;</p>
<p>getmem(p,imagesize(0,0,20,20)); getimage(0,0,20,20,p^);</p>
<p>cleardevice;</p>
<p>setbkcolor(cyan); settextstyle(0,0,2); settextjustify(1,1);</p>
<p>setcolor(blue); outtextxy(320,240,&#8217;Bui The Tam, Lop 12 A&#8217;);</p>
<p>outtextxy(320,280,&#8217;Truong Trung hoc Pho thong Ly Bi&#8217;);</p>
<p>setcolor(white); ellipse(320,100,180,360,50,50);</p>
<p>ellipse(320,100,180,360,50,25); setfillstyle(1,white);</p>
<p>floodfill(320,130,white);</p>
<p>x1:=0; y1:=random(460); x2:=random(620); y2:=479;</p>
<p>x3:=0; y3:=random(460); x4:=random(620); y4:=479;</p>
<p>repeat  putimage(x1,y1,p^,1); putimage(x2,y2,p^,1);</p>
<p>putimage(x3,y3,p^,1); putimage(x4,y4,p^,1);</p>
<p>u1:=x1; v1:=y1;u2:=x2; v2:=y2;</p>
<p>u3:=x3; v3:=y3;u4:=x4; v4:=y4;</p>
<p>x1:=x1+5; y1:=y1-5; if y1&#60;0 then begin x1:=0; y1:=random(480) end;</p>
<p>x2:=x2+5; y2:=y2-5;</p>
<p>if (y2&#60;0) or(x2&#62;640-20) then begin x2:=random(620); y2:=479 end;</p>
<p>x3:=x3+5; y3:=y3-5; if y3&#60;0 then begin x3:=0; y3:=random(480) end;</p>
<p>x4:=x4+5; y4:=y4-5;</p>
<p>if (y4&#60;0) or(x4&#62;640-20) then begin x4:=random(620); y4:=479 end;</p>
<p>delay(20); putimage(u1,v1,p^,1); putimage(u2,v2,p^,1);</p>
<p>putimage(u3,v3,p^,1); putimage(u4,v4,p^,1);</p>
<p>until keypressed;</p>
<p>closegraph; dispose(p);</p>
<p>end.</p>
<p>Việc chép ảnh bằng lệnh PutImage theo cách XorPut có nhược điểm là ảnh bị đổi màu khi đi qua ảnh nền. Để khắc phục điều này ta có thể kết hợp việc vẽ ảnh với việc cất ảnh nền ở vị trí định vẽ để sau đó có thể khôi phục ảnh nền cũ bằng CopyPut. Chương trình <strong>LuuNen.pas </strong>minh hoạ cách làm này: tạo 500 hình tròn có màu ngẫu nhiên làm ảnh nền, cho quả bóng màu đỏ chuyển động ngang màn hình mà không xoá nền.</p>
<p>uses graph,crt;</p>
<p>var i,k,gd,gm,x1,y1,u1,v1,r:integer; n: word; p: pointer;</p>
<p>begin</p>
<p>gd:=VGA; gm:=VgaHi; initgraph(gd,gm,&#8221;); randomize; r:=50;</p>
<p>for i:=1 to 500 do</p>
<p>begin k:= random(15)+1; setcolor(k); setfillstyle(1,k);</p>
<p>Fillellipse(random(640-40)+20,random(480-40)+20,20,20);</p>
<p>end;</p>
<p>x1:=r; y1:=240;</p>
<p>n:=imagesize(x1-r,y1-r,x1+r,y1+r); getmem(p,n);</p>
<p>repeat</p>
<p>GetImage(x1-r,y1-r,x1+r,y1+r,p^);</p>
<p>setcolor(LightRed); setfillstyle(1,LightRed); FillEllipse(x1,y1,r,r);</p>
<p>u1:=x1; v1:=y1; x1:=x1+5;</p>
<p>if x1&#62;639-r then</p>
<p>begin delay(500); x1:=r; putimage(u1-r,v1-r,p^,0) end</p>
<p>else  begin delay(500); putimage(u1-r,v1-r,p^,0); end;</p>
<p>until keypressed;</p>
<p>dispose(p); closegraph;</p>
<p>end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">7 Vẽ đồ thị các hàm số</span></strong></p>
<p><strong><span style="font-size:13pt;font-family:Arial;">a) Chuyển một hình vẽ trong toạ độ Đề các lên màn hình</span></strong></p>
<p>Trong toán học ta vẽ đồ thị của hàm số y = F(x) trong toạ độ Đề các với trục X hướng sang phải, trục Y hướng lên trên, thang chia các trục do ta tự chọn. Hệ toạ độ (U,V) trên màn hình lại có gốc toạ độ ở góc trên trái màn hình, trục U hướng sang phải và có giá trị cố định từ 0 đến 639, trục V hướng xuống dưới và có giá trị từ 0 đến 479.</p>
<p><img src="http://a367.yahoofs.com/lifestory/Pm__DOT__vyqiGERqqXwRhL3TecFk-_1/blog/ap_20090630104747311.jpg?lb_____D48hCuxA6" alt="" /></p>
<p>Do mặt phẳng vẽ của hệ toạ độ (x,y) là vô hạn và mặt phẳng vẽ của hệ toạ độ (u,v) là hữu hạn nên tại một thời điểm ta chỉ có thể giới hạn xem đuợc một vùng chữ nhật ABCD trên hệ toạ độ (x,y), toạ độ của điểm A là (x1,y1) và của điểm C là (x2,y2). Vấn đề là ta cần phải ánh xạ các điểm vẽ trong hình chữ nhật ABCD vào một vùng chữ nhật A&#8217;B'C&#8217;D&#8217; trên màn hình, toạ độ của điểm A&#8217; là (u1,v1) và của điểm C&#8217; là (u2,v2). Phép ánh xạ này phải đảm bảo chuyển các điểm A, B, C, D thành các điểm A&#8217;, B&#8217;, C&#8217;, D&#8217; tương ứng, hình ảnh trong hệ toạ độ (x,y) khi chuyển sang hệ toạ độ (u,v) có thể bị co dãn..</p>
<p>Giả sử điểm vẽ M có toạ độ (x,y), qua phép ánh xạ chuyển thành điểm M&#8217; có toạ độ (u,v). Các giá trị u và v được tính theo công thức:</p>
<p>Tlx = (u2-u1) / (x2-x1); Tly = (v1-v2) / (y2-y1)</p>
<p>u = u1 + Round((x-x1)*Tlx); v = v1 &#8211; Round((y-y1)*Tly)</p>
<p>Tlx, Tly là tỷ lệ co dãn theo trục X và Y tương ứng. Hàm Round(z: real) làm tròn số thực x thành số nguyên gần nhất.</p>
<p>Thuật toán để vẽ đồ thị hàm số y = F(x) bất kỳ: vẽ đồ thị hàm số trong hệ toạ độ (x,y), giới hạn vùng nhìn ABCD, giới hạn vùng ảnh trên màn hình A&#8217;B'C&#8217;D', dùng ánh xạ trên để chuyển các điểm trên đồ thị (x,y) thành các điểm ảnh (u,v) trên màn hình.</p>
<p>Chương trình <strong>DoThi.pas</strong>:  vẽ đồ thị hàm số Y = 0.5 * x * Sin(x) với vùng vẽ là x1= -50,  y1= -20,  x2= 50,  y2= 20 và vùng hiển thị trên màn hình là  u1= 50, v1= 429, u2= 625, v2= 10.</p>
<p>uses crt, graph;</p>
<p>var gd,gm,u,v,u1,u2,v1,v2: integer;</p>
<p>x,y,x1,y1,x2,y2,tlx,tly: real; s1,s2,s3,s4: string[5];</p>
<p>function F(x:real): real;</p>
<p>begin  f:=0.5*x*sin(x);  end;</p>
<p>procedure Doi(x,y: real; var u,v: integer);</p>
<p>begin  u:=u1+round((x-x1)*tlx); v:=v1-round((y-y1)*tly) end;</p>
<p>begin clrscr; x1:= -50; y1:= -20; x2:= 50; y2:= 20;</p>
<p>u1:= 50; v1:= 429; u2:= 625; v2:= 10;</p>
<p>tlx:=(u2-u1)/(x2-x1); tly:=(v1-v2)/(y2-y1);</p>
<p>gd:=detect; initgraph(gd,gm,&#8221;);</p>
<p>setcolor(red); rectangle(u1,v2,u2,v1);</p>
<p>setcolor(cyan); settextstyle(0,0,1);</p>
<p>settextjustify(1,2); str(x1:3:0,s1); outtextxy(u1,v1+8,s1);</p>
<p>str(x2:3:0,s2);outtextxy(u2,v1+8,s2);</p>
<p>settextjustify(2,1); str(y1:3:0,s3); outtextxy(u1-5,v1,s3);</p>
<p>str(y2:3:0,s4);outtextxy(u1-5,v2,s4);</p>
<p>settextjustify(1,1);  setcolor(lightmagenta);</p>
<p>outtextxy(320,470,&#8217;Bui The Tam, lop 11A, Truong THPT Ly Nam De&#8217;);</p>
<p>x:=x1;</p>
<p>repeat y:=f(x); Doi(x,y,u,v);</p>
<p>if (v&#62;=v2) and(v&#60;=v1) then Putpixel(u,v,white); x:=x+0.005;</p>
<p>until (x&#62;x2);   readln;</p>
<p>end.</p>
<p>Phương pháp trên có thể áp dụng để vẽ các đường cong cho dưới dạng tham số: x= f(t), y = h(t) với t biến thiên trong khoảng a&#60;=t&#60;=b. Đầu tiên cho t<sub>1</sub>=a, với mỗi t<sub>i</sub> ta tính (x<sub>i</sub>, y<sub>i</sub>) và chuyển sang toạ độ màn hình để vẽ điểm này, tiếp theo t<sub>i+1</sub>=t<sub>i</sub>+<span style="font-size:13pt;font-family:Symbol;">e</span> và vẽ điểm i+1. . . Ví dụ đường xoắn dạng lò xo có phương trình x = t + cos(3t), y = t + sin(3t).</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">b) Hệ toạ độ cực</span></strong></p>
<p><img src="http://a367.yahoofs.com/lifestory/Pm__DOT__vyqiGERqqXwRhL3TecFk-_1/blog/ap_20090630104636831.jpg?lb_____DSG7GVjjd" alt="" /><br />
Toạ độ cực gồm một điểm gốc O, một tia Ox. Một điểm M trong mặt phẳng xác định bởi cặp số (R,a), trong đó R là độ dài đoạn MO, a là góc tạo bởi MO với trục Ox. Nếu góc a trong phương trình R = F(a) nằm ở dạng lượng giác hay bội số thì hàm sẽ tuần hoàn. Ví dụ phương trình:</p>
<p align="center">R = 1 &#8211; Cos<sup>2</sup>(5*a*<span style="font-size:13pt;font-family:Symbol;">p</span>/180)</p>
<p>với  a<span style="font-family:Symbol;">Î</span> [0<sup>0</sup>, 360<sup>0</sup>] sẽ tạo nên bông hoa 10 cánh. Một điểm M = (R, a) của toạ độ cực có thể đổi sang toạ độ Đề các (x,y) theo công thức: x = R Cos(a), y = R Sin(a).</p>
<p>Chương trình <strong>Hoa10.pas</strong> nhằm vẽ đồ thị trên trong toạ độ cực:</p>
<p>uses crt, graph;</p>
<p>var gd, gm, u, v, u1, u2, v1, v2: integer;</p>
<p>x, y, x1, y1, x2, y2, tlx, tly, t, t1, r: real;</p>
<p>begin clrscr;</p>
<p>x1:=-1; x2:=1; y1:=-1; y2:=1;</p>
<p>u1:=30; u2:=475; v1:=450; v2:=5;</p>
<p>tlx:=(u2-u1)/(x2-x1); tly:=(v1-v2)/(y2-y1);</p>
<p>gd:=detect; initgraph(gd,gm,&#8221;); setcolor(red);</p>
<p>rectangle(u1,v2,u2,v1); t:=0; t1:=pi/180;</p>
<p>repeat</p>
<p>r:= 1-SQR(cos(5*t*t1));</p>
<p>x:= r* cos(t * t1); y:= r * sin(t * t1);</p>
<p>u:= u1 + Round((x-x1) * tlx);   v:= v1 &#8211; Round((y-y1) * tly);</p>
<p>if (u&#62;=u1) and (u&#60;=u2) and (v&#62;=v2) and(v&#60;=v1) then</p>
<p>Putpixel(u,v,white); t:=t+0.05;</p>
<p>until (t&#62; 360);</p>
<p>readln;</p>
<p>end.</p>
<p><strong><span style="font-size:14pt;">Bài tập</span></strong></p>
<p>1. Hãy vẽ liên tục các hình chữ nhật nằm trọn trong màn hình cho đến khi ấn một phím bất kỳ thì kết thúc. Yêu cầu: chiều dài, chiều rộng, màu nét vẽ viền, mẫu tô và màu tô trong ruột hình chữ nhật đều là ngẫu nhiên, độ dài tối thiểu của một cạnh hình chữ nhật là 10 điểm.</p>
<p>2. Vẽ quả bóng màu đỏ và ghi vào một biến con trỏ. Xoá màn hình, vẽ  bầu trời đầy sao, cho quả bóng chuyển động ngẫu nhiên (hướng ngẫu nhiên, độ dài bước ngẫu nhiên không quá 5 điểm) trên màn hình mà không xoá các ngôi sao.</p>
<p>3. Vẽ đồ thị hàm số Y = sin(x)*exp(-0.1*x) (mô tả một dao động tắt dần) với các vùng vẽ như sau: x1= -35, y1= -20, x2=15, y2= 20, u1= 50, v1= 429, u2= 625, v2= 10.</p>
<p>4. Vẽ đường xoáy trôn ốc ngược chiều kim đồng hồ trong toạ độ cực cho bởi R= 50 &#8211; 0.3* a* PI/ 180, trong đó a là góc tăng từ 0 độ cho tới khi R &#60; 0 thì dừng, mỗi lần tăng 0.05 độ. Vùng giới hạn trong hệ toạ độ (x,y) là x1= -51, x2= 51, y1= -51, y2= 51. Vùng giới hạn trên màn hình là u1= 30, u2= 475, v1= 450, v2= 5.</p>
<p>5. Vẽ các đường cong sau trong toạ độ cực:</p>
<p>a)  R = 1 + cos(a) , 0 &#60;= a &#60;= 2p (đường hình tim)</p>
<p>b)  R = 5 &#8211; &#124; sin(10a) &#124; , 0 &#60;= a &#60;= 2p (đường hình bánh răng)</p>
<p>c)  R = sqrt(p / a), a &#62; 0 (đường xoắn hình sên).</p>
<p>6. Vẽ các đường cong sau cho dưới dạng tham số:</p>
<p>a)  x = t + cos(3t),  y = t + sin(3t),  -10 &#60;= t &#60;= 10 (đường xoắn lò so).</p>
<p>b)  x = cos3(t),  y = sin3(t),  0 &#60;= t &#60;= 2p  (đường hình sao)</p>
<p>c)  x = 2 cos(t) &#8211; cos(2t),  y = 2 sin(t) &#8211; sin(2t),  0 &#60;= t &#60;= 2p (đường hình tim).</p>
<p><span style="font-size:12pt;"> <span style="font-weight:bold;">Bùi Thế Tâm soạn 30/6/2009</span><br />
</span></p>
</div>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal: Danh sách liên kết dùng con trỏ]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/pascal-dslket/</link>
<pubDate>Mon, 19 Oct 2009 02:12:17 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/pascal-dslket/</guid>
<description><![CDATA[1. Danh sách liên kết đơn Danh sách là một dãy hữu hạn các phần tử thuộc cùng một lớp đối tượng nào ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>1. <span style="font-weight:bold;">Danh sách liên kết đơn</span></p>
<p>Danh sách là một dãy hữu hạn các phần tử thuộc cùng một lớp đối tượng nào đó. Ví dụ : danh sách sinh viên, danh sách vật tư, danh sách các hoá đơn, danh sách các số thực. Trong các bài trước ta đã <strong>dùng mảng</strong> để biểu thị một danh sách. Cách này có các nhược điểm: kích thước của mảng phải định trước nên tốn bộ nhớ (số phần tử thực tế  dùng nhiều khi rất ít so với khai báo), khi thêm một phần tử vào mảng hoặc xoá một phần tử ra khỏi mảng ta phải mất nhiều thời gian để dồn mảng.<!--more--></p>
<p>Danh sách liên kết dùng để cài đặt một danh sách sẽ khắc phục được các nhược điểm trên của mảng. Danh sách liên kết thuận gồm nhiều phần tử nằm không liên tục trong Heap. Cấu tạo của danh sách liên kết thuận: có một con trỏ <strong>first</strong> chứa địa chỉ của phần tử đầu tiên  của danh sách, phần tử đầu có phần dữ liệu và một con trỏ <strong>next</strong> để chứa địa chỉ của phần tử thứ hai, tổng quát phần tử thứ i có phần dữ liệu và một con trỏ next để chứa địa chỉ của phần tử thứ i+1, đối với phần tử cuối cùng giá trị của con trỏ next bằng NIL.  Để thuận tiện khi thêm phần tử mới vào cuối danh sách liên kết ta dùng một con trỏ <strong>last</strong> chứa địa chỉ của phần tử cuối cùng. Khởi tạo một danh sách rỗng first = NIL</p>
<p><img src="http://a367.yahoofs.com/lifestory/Pm__DOT__vyqiGERqqXwRhL3TecFk-_2/blog/ap_20091120103211923.jpg?lb_____Duf4gqLEe" alt="" width="470" height="74" /></p>
<p>Chương trình Dslk.pas minh hoạ các cách làm việc với danh sách liên kết thuận. Phần dữ liệu của một phần tử là các thông tin về một sinh viên.<br />
uses crt;<br />
type SVienPtr = ^SVien;<br />
SVien = record  maso: string[6];<br />
hoten: string[23];<br />
dtb: real;<br />
next : SVienPtr<br />
end;<br />
var  first, last : SVienPtr; chon: byte; traloi: char;<br />
procedure Bosung;<br />
var  p: SVienPtr; ans: integer;<br />
begin<br />
while true do<br />
begin  new(p);<br />
with p^ do begin<br />
write(&#8216;Ma sinh vien : &#8216;); readln(maso);<br />
write(&#8216;Ho va ten : &#8216;); readln(Hoten);<br />
write(&#8216;Diem trung binh: &#8216;); readln(dtb);<br />
end;<br />
p^.next:=NIL;<br />
if first=NIL then begin first:= p; last:= p end<br />
else begin last^.next:= p; last:= p end;<br />
write(&#8216;Co tiep tuc khong 1/0 ? &#8216;);  readln(ans);<br />
if ans=0 then break;<br />
end;<br />
end;<br />
procedure DuyetXuoi;<br />
var  p: SVienPtr;<br />
begin if first = NIL then begin writeln(&#8216;D.sach rong&#8217;); exit end;<br />
p := first;<br />
while p &#60;&#62; NIL do<br />
begin  with p^ do writeln(maso:5,&#8217;  &#8216;,Hoten:25,&#8217;  &#8216;,dtb:5:2);<br />
p := p^.Next;<br />
end;<br />
end;<br />
procedure ChenSau;<br />
var q,p: SVienPtr; found: boolean; masv: string[6];<br />
begin  if first &#60;&#62; NIL then  begin<br />
write(&#8216;Ma so SV can tim de chen : &#8216;); readln(masv);<br />
p:= first; found:= false;<br />
while (p&#60;&#62;NIL) and (not found) do<br />
if p^.maso=masv then found := true else p:=p^.next;<br />
if found then<br />
begin  new(q);<br />
with q^ do begin<br />
write(&#8216; Ma so   : &#8216;); readln(maso);<br />
write(&#8216; Ho ten  : &#8216;); readln(Hoten);<br />
write(&#8216; Diem trung binh : &#8216;); readln(dtb);<br />
end;<br />
q^.next:= p^.next; p^.next:= q;<br />
end else begin write(&#8216;Khong tim thay&#8230;&#8217;); readln end;<br />
end;<br />
end;<br />
procedure TimXoa;<br />
var masv: string[6]; found: boolean; p,q: SVienPtr;<br />
begin write(&#8216;Ma so SV can loai khoi danh sach : &#8216;); readln(masv);<br />
p:= first;<br />
if p&#60;&#62;NIL then  begin   found:= false;<br />
while (p&#60;&#62;NIL) and (not found) do<br />
if p^.maso=masv then found := true<br />
else begin q:=p; p:=p^.next end;<br />
if found then<br />
begin if p=first then first :=p^.next else q^.next:=p^.next;<br />
if p^.next=NIL then last:=q; dispose(p)<br />
end else begin write(&#8216;Khong tim thay&#8230;&#8217;); readln end;<br />
end;<br />
end;<br />
Begin clrscr; First := NIL;<br />
repeat<br />
writeln; writeln(&#8216;1. Bo sung mot sinh vien&#8217;);<br />
writeln(&#8216;2. Duyet danh sach sinh vien&#8217;);<br />
writeln(&#8216;3. Tim kiem mot phan tu va chen vao sau&#8217;);<br />
writeln(&#8216;4. Tim kiem mot phan tu va xoa&#8217;);<br />
writeln(&#8216;5. Ket thuc chuong trinh&#8217;);<br />
writeln; write(&#8216;Chon chuc nang: &#8216;); readln(chon); writeln;<br />
case chon of<br />
1: Bosung;<br />
2: DuyetXuoi;<br />
3: ChenSau;<br />
4: TimXoa;<br />
end;<br />
until chon=5;<br />
while first&#60;&#62;NIL do begin last:= first; first:= first^.next;<br />
dispose(last) end;<br />
End.</p>
<p>2. <span style="font-weight:bold;">Danh sách liên kết kép</span></p>
<p>Danh sách liên kết kép là danh sách mà mỗi phần tử của nó gồm ba thành phần: phần dữ liệu, con trỏ <strong>next</strong> chứa địa chỉ phần tử tiếp sau, con trỏ <strong>prev</strong> chứa địa chỉ của phần tử liền trước, con trỏ next của phần tử cuối cùng trong danh sách bằng NIL, con trỏ prev của phần tử đầu tiên cũng bằng NIL. Danh sách liên kết kép hoàn toàn xác định bởi hai con trỏ: con trỏ <strong>first</strong> chứa địa chỉ phần tử đầu tiên, con trỏ <strong>last</strong> chứa địa chỉ phần tử cuối cùng. Danh sách liên kết kép cho phép dễ dàng xác định phần tử đứng trước một phần tử đã biết, do đó nó thuận tiện hơn  danh sách liên kết thuận trong các thao tác: duyệt ngược danh sách, chèn một phần tử mới vào trước một phần tử, xoá một phần tử.</p>
<p><img src="http://a367.yahoofs.com/lifestory/Pm__DOT__vyqiGERqqXwRhL3TecFk-_2/blog/ap_20091120103549157.jpg?lb_____Df9FgclxN" alt="" width="468" height="71" /></p>
<p>Chương trình DslkKep.pas minh hoạ cách làm việc với danh sách liên kết kép.<br />
uses crt;<br />
type svienPtr = ^svien;<br />
svien = record maso : string[6];<br />
hoten: string[23];<br />
dtb  : real;<br />
prev, next : svienPtr;<br />
end;<br />
var first,last: svienPtr; chon: byte;<br />
procedure Bosung;<br />
var p,q: svienPtr; ans: char;<br />
begin<br />
while true do begin<br />
new(p); with p^ do<br />
begin write(&#8216;- Ma so: &#8216;); readln(maso);<br />
write(&#8216;- Ho va ten: &#8216;); readln(hoten);<br />
write(&#8216;- Diem trung binh: &#8216;); readln(dtb); end;<br />
if first=NIL then  begin p^.next:= NIL;<br />
p^.prev := NIL; first:= p; last:= p;  end<br />
else begin q:= last; q^.next:= p; p^.next:= NIL;<br />
p^.prev:= q; last:= p; end;<br />
write(&#8216;Co tiep tuc khong C/K ?&#8217;);  readln(ans);<br />
if upcase(ans) = &#8216;K&#8217; then break;<br />
end;<br />
end;<br />
procedure DuyetXuoi;<br />
var p: svienPtr;<br />
begin<br />
if first &#60;&#62; NIL then<br />
begin p:= first;<br />
while p&#60;&#62; NIL do<br />
begin with p^ do<br />
writeln(maso,&#8217;  &#8216;,hoten,&#8217;  &#8216;,dtb:1:2);<br />
p:= p^.next;<br />
end;<br />
end<br />
else writeln(&#8216;Danh sach rong &#8230;&#8217;); readln;<br />
end;<br />
procedure DuyetNguoc;<br />
var p: svienPtr;<br />
begin<br />
if first &#60;&#62; NIL then<br />
begin p:= last;<br />
while p&#60;&#62; NIL do<br />
begin  with p^ do<br />
writeln(maso,&#8217;  &#8216;,hoten,&#8217;  &#8216;,dtb:1:2);<br />
p:= p^.prev;<br />
end;<br />
end<br />
else writeln(&#8216;Danh sach rong &#8230;&#8217;); readln;<br />
end;<br />
procedure ChenTruoc;<br />
var  p,q,r: svienPtr; found: boolean; masv: string[6];<br />
begin write(&#8216;Ma so SV can tim : &#8216;); readln(masv);<br />
if first&#60;&#62;NIL then Begin<br />
p:= first; found:= false;<br />
while (p&#60;&#62;NIL) and (not found) do<br />
if p^.maso=masv then found := true else p:=p^.next;<br />
if found then<br />
begin new(q);<br />
with q^ do<br />
begin write(&#8216;- Ma so: &#8216;); readln(maso);<br />
write(&#8216;- Ho va ten: &#8216;); readln(hoten);<br />
write(&#8216;- Diem trung binh: &#8216;); readln(dtb);<br />
end;<br />
if p=first then<br />
begin q^.next:= p; first^.prev:= q;  first:= q end<br />
else begin r:=p^.prev; q^.next:= r^.next; r^.next:= q;<br />
q^.prev:= p^.prev; p^.prev:= q end;<br />
end<br />
else begin write(&#8216;Khong tim thay&#8230;&#8217;); readln end;<br />
End;<br />
end;<br />
procedure TimXoa;<br />
var  p,q,pt: svienPtr; found: boolean; masv: string[6];<br />
begin<br />
write(&#8216;Ma so SV can loai khoi danh sach : &#8216;); readln(masv);<br />
if first&#60;&#62;NIL then begin<br />
p:= first; found:= false;<br />
while (p&#60;&#62;NIL) and (not found) do<br />
if p^.maso=masv then found := true else p:=p^.next;<br />
if found then<br />
begin  q:= p^.prev; pt:= p^.next; if q&#60;&#62;NIL then q^.next:= p^.next;<br />
if pt&#60;&#62;NIL then pt^.prev:= p^.prev;<br />
if p=first then first:= pt; if p=last then last:= q;<br />
dispose(p);<br />
end<br />
else begin  write(&#8216;Khong tim thay &#8230;&#8217;); readln end;<br />
end;<br />
end;<br />
Begin first:= NIL; clrscr;<br />
repeat  writeln(&#8216;1. Bo sung phan tu&#8217;);<br />
writeln(&#8216;2. Duyet danh sach theo chieu xuoi&#8217;);<br />
writeln(&#8216;3. Duyet danh sach theo chieu nguoc&#8217;);<br />
writeln(&#8216;4. Chen vao truoc mot phan tu&#8217;);<br />
writeln(&#8216;5. Tim kiem va xoa mot phan tu&#8217;);<br />
writeln(&#8216;6. Ket thuc chuong trinh&#8217;);<br />
write(&#8216;   Chon chuc nang : &#8216;); readln(chon);<br />
case chon of<br />
1: Bosung;     2: DuyetXuoi;   3: DuyetNguoc;<br />
4: ChenTruoc;  5: TimXoa;<br />
end;<br />
until chon=6;<br />
while first&#60;&#62; NIL do begin last:=first; first:=first^.next;<br />
dispose(last); end;<br />
End.</p>
<p>3. <span style="font-weight:bold;">Ngăn xếp dùng danh sách liên kết</span></p>
<p>Stack là một danh sách theo đó tất cả các công việc chèn và huỷ đều được thực hiện ở một đầu của danh sách (gọi là đỉnh của ngăn xếp). Stack giống như một chồng đĩa, đĩa nào đặt cuối cùng lên đỉnh chồng thì đĩa đó sẽ được lấy ra đầu tiên. Do đó Stack còn có tên gọi là LIFO (last in first out &#8211; vào sau ra trước). Việc thêm một phần tử vào stack có tên gọi là đẩy (Push) vào stack, còn việc huỷ một phần tử khỏi stack gọi là lấy (Pop) khỏi stack.</p>
<p>Stack dùng danh sách liên kết hoàn toàn giống danh sách liên kết thuận, nhưng chỉ có điều khác là khi thêm phần tử mới hay huỷ một phần tử ta luôn luôn làm ở đầu danh sách. Do đó ta phải duy trì một con trỏ Top để trỏ vào phần tử đầu tiên của danh sách (đỉnh của stack)</p>
<p>Chương trình StDslk.pas minh hoạ cách làm việc với stack dùng danh sách liên kết, các phần tử của stack là các số nguyên dương.<br />
uses crt;<br />
type  StackPtr= ^node;<br />
node = record<br />
data: integer;<br />
next: StackPtr;<br />
end;<br />
var top: StackPtr; chon,n: integer;<br />
procedure Push(n: integer);<br />
var p: StackPtr;<br />
begin new(p); p^.data:= n; p^.next:= top; top:= p;<br />
end;<br />
function Pop: integer;<br />
var p: StackPtr;<br />
begin  if top=NIL then pop:=0<br />
else begin pop:= top^.data; p:= top;<br />
top:= top^.next;  dispose(p)  end;<br />
end;<br />
procedure Duyet;<br />
var p: StackPtr;<br />
begin<br />
if top&#60;&#62;NIL then<br />
begin p:=top;<br />
while p&#60;&#62;NIL do begin writeln(p^.data,&#8217;  &#8216;); p:=p^.next end;<br />
end<br />
else writeln(&#8216;Stack rong&#8217;); readln;<br />
end;<br />
Begin clrscr; top:=NIL;<br />
repeat write(&#8216;1. Push  2. Pop  3. Duyet  4. Thoat. Chon: &#8216;);<br />
read(chon);<br />
case chon of<br />
1: begin write(&#8216;Vao n : &#8216;); readln(n); Push(n) end;<br />
2: begin n:= Pop;<br />
if n&#60;&#62;0 then writeln(&#8216;Phan tu lay ra = &#8216;,n)<br />
else writeln(&#8216;Stack rong&#8217;);<br />
end;<br />
3: Duyet;<br />
end;<br />
until chon=4;<br />
end.</p>
<p>4. <span style="font-weight:bold;">Hàng đợi dùng danh sách liên kếp</span></p>
<p>Queue là một danh sách mà việc thêm một phần tử mới được thực hiện ở đuôi queue, việc huỷ một phần tử được thực hiện ở đầu queue. Queue giống như một dãy khách hàng xếp hàng trả tiền trong siêu thị, người xếp hàng trước sẽ được phục vụ trước và ra khỏi hàng, người mới tham gia xếp hàng thì xếp vào cuối hàng. Do đó queue còn có tên gọi FIFO (first in first out &#8211; vào trước thì ra trước).</p>
<p>Queue dùng danh sách liên kết hoàn toàn giống danh sách liên kết thuận , nhưng chỉ có điều khác là khi thêm phần tử mới ta luôn luôn nối vào cuối danh sách, khi huỷ một phần tử  ta luôn huỷ phần tử đầu tiên trong danh sách. Do đó ta phải duy trì hai con trỏ: front trỏ vào phần tử đầu, back trỏ vào phần tử cuối</p>
<p>Chương trình QueDslk.pas tạo một hàng đợi gồm các số nguyên dương dùng danh sách liên kết thuận.<br />
uses crt;<br />
type  queuePtr= ^node;<br />
node = record  data: integer;<br />
next: queuePtr;<br />
end;<br />
var front,back: queuePtr; chon,n: integer;<br />
procedure ThemVao(n: integer);<br />
var p: queuePtr;<br />
begin new(p); p^.data:= n; p^.next:= NIL;<br />
if front=NIl then begin front:=p; back:=p end<br />
else begin back^.next:=p; back:=p end;<br />
end;<br />
function LayRa: integer;<br />
var p: queuePtr;<br />
begin  if front=NIL then LayRa:=0<br />
else begin LayRa:= front^.data; p:= front;<br />
front:= front^.next;  dispose(p)  end;<br />
end;<br />
procedure Duyet;<br />
var p: queuePtr;<br />
begin if front&#60;&#62;NIL then<br />
begin p:=front;<br />
while p&#60;&#62;NIL do begin write(p^.data,&#8217;  &#8216;); p:=p^.next end;<br />
writeln;<br />
end else writeln(&#8216;Queue rong&#8217;); readln;<br />
end;<br />
Begin clrscr; front:=NIL; back:=NIL;<br />
repeat write(&#8216;1.Push 2.Pop 3.Duyet 4.Thoat. Chon: &#8216;); read(chon);<br />
case chon of<br />
1: begin write(&#8216;Vao n : &#8216;); readln(n); ThemVao(n) end;<br />
2: begin n:= LayRa; if n&#60;&#62;0 then writeln(&#8216;Phan tu lay ra = &#8216;,n)<br />
else writeln(&#8216;Queue rong&#8217;);<br />
end;<br />
3: Duyet;<br />
end;<br />
until chon=4;<br />
end.<br />
<span style="font-weight:bold;">Bùi Thế Tâm soạn  29/6/2009, bổ sung ngày 20/11/2009<br />
</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal: Con trỏ]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/turbo-pascal-con-tro/</link>
<pubDate>Mon, 19 Oct 2009 02:06:28 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/turbo-pascal-con-tro/</guid>
<description><![CDATA[Các biến thuộc kiểu dữ liệu đã học như integer, real, mảng, tập hợp, bản ghi . . . gọi là các biến t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Các biến thuộc kiểu dữ liệu đã học như integer, real, mảng, tập hợp, bản ghi . . . gọi là các biến tĩnh vì chúng được xác định rõ ràng khi khai báo và sau đó được dùng thông qua tên của chúng. Thời gian tồn tại của biến tĩnh cũng là thời gian tồn tại của khối chương trình có chứa khai báo các biến này. Do đó nếu chương trình sử dụng một số lượng lớn các biến tĩnh thì sẽ không đủ bộ nhớ. Ví dụ khi khai báo var A: array[1..5000] of real;  máy sẽ phân một vùng nhớ cố định 30000 byte cho mảng A, trong chương trình có thể ta không dùng đến cả 5000 phần tử. Để tránh lãng phí bộ nhớ Turbo Pascal cho phép dùng biến động (dynamic variable). Các biến này được lưu trữ trong vùng Heap (vùng nhớ tự do của máy), khi cần chúng có thể được tạo ra để chứa dữ liệu, khi không cần có thể xoá chúng đi để giải phóng bộ nhớ. Biến động không có tên và do một con trỏ quản lý.  <!--more--></p>
<p><strong><span style="font-size:14pt;font-family:Arial;">1. Khai báo kiểu con trỏ và biến con trỏ</span></strong></p>
<p>Kiểu con trỏ là một kiểu dữ liệu đặc biệt dùng để lưu trữ những giá trị địa chỉ. Biến con trỏ có độ lớn 4 byte : hai byte thấp chứa địa chỉ offset, 2 byte cao chứa địa chỉ segment. Nhờ biến con trỏ ta có thể xin cấp phát động trên vùng Heap. Có hai kiểu con trỏ: con trỏ định kiểu và con trỏ không định kiểu.</p>
<p><strong>Con trỏ định kiểu</strong> là con trỏ cần xác định kiểu dữ liệu mà nó trỏ đến. Cách khai báo kiểu con trỏ và biến con trỏ (theo hai cách):</p>
<p><span style="font-size:10pt;font-family:Arial;">Type  KiểuConTrỏ = ^KiểuDữLiệu ;</span></p>
<p><span style="font-size:10pt;font-family:Arial;">Var    BiếnConTrỏ1 : KiểuConTrỏ ;  BiếnConTrỏ2 : ^KiểuDữLiệu ; </span></p>
<p>trong đó KiểuDữLiệu có thể là real, integer, char, mảng, bản ghi . . . Khi một biến con trỏ chứa địa chỉ byte đầu tiên của một vùng nhớ thì ta nói con trỏ đang trỏ tới vùng nhớ này. Con trỏ real trỏ tới vùng nhớ 6 byte, con trỏ integer trỏ tới vùng nhớ 2 byte. . .  Kiểu con trỏ cũng có thể là thành phần của bất kỳ một kiểu có cấu trúc nào (mảng, bản ghi). Hai con trỏ định kiểu gọi là tương thích (trong các phép gán, so sánh, truyền dữ liệu cho tham số) nếu cùng trỏ tới một kiểu dữ liệu.</p>
<p><strong>Con trỏ không định kiểu</strong> là con trỏ không quan tâm đến kiểu dữ liệu mà nó đang trỏ tới, chỉ quan tâm đến địa chỉ. Cách khai báo:  <strong><span style="font-size:10pt;">Var P: Pointer ;</span></strong> Con trỏ không định kiểu tương thích với mọi kiểu con trỏ khác.</p>
<p>Ví dụ:         Type   IntPtr = ^Integer ;</p>
<p>SVienPtr = ^SVien ; { Kiểu bản ghi SVien có thể khai sau }</p>
<p>SVien = Record</p>
<p>HoTen : string[25] ;</p>
<p>DiemTB : real ;</p>
<p>End ;</p>
<p>Var  P1 : IntPtr ; P : SVienPtr ;  P2: ^Word ; Q: Pointer ;</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">2. Các thao tác đối với con trỏ</span></strong></p>
<p><strong>Gán một giá trị địa chỉ cho con trỏ</strong> theo các cách: <strong><span style="font-size:10pt;">P := @x ; P := Addr(x); P := Ptr(segment, offset);</span></strong> trong đó P là biến con trỏ bất kỳ, x là tên biến (hoặc tên hàm, thủ tục). Các hàm Addr, Ptr và toán tử @ trả về một địa chỉ kiểu Pointer.</p>
<p><strong>Hằng NIL</strong>. Lệnh gán P := NIL nhằm làm cho con trỏ P không trỏ vào đâu cả (P là con trỏ kiểu bất kỳ).</p>
<p><strong>Phép gán (:=) giữa hai con trỏ</strong>: hai con trỏ có thể gán cho nhau trong trường hợp tương thích, khi đó chúng cùng trỏ tới một địa chỉ. Hai con trỏ định kiểu trỏ tới các kiểu dữ liệu khác nhau là không tương thích, song chúng lại tương thích với kiểu Pointer. Ví dụ sau khai báo <strong><span style="font-size:10pt;">Var p, s: byte; q : ^real; r: pointer ;</span></strong> thì lệnh gán<strong><span style="font-size:10pt;"> p := s</span></strong> là đúng, lệnh gán<strong><span style="font-size:10pt;"> q := p ;</span></strong> là sai, song hai lệnh sau là đúng <strong><span style="font-size:10pt;">: r := p ; q := r ;</span></strong></p>
<p><strong>Hai giá trị con trỏ có thể so sánh</strong> bằng nhau (=) hay khác nhau (&#60;&#62;) nếu chúng tương thích. Với các giá trị con trỏ không có các phép so sánh  &#62;   &#62;=  &#60;   &#60;=.</p>
<p><strong>Để truy cập nội dung vùng dữ liệu mà con trỏ P đang trỏ</strong> ta dùng ký hiệu P^, P^ xem như là một biến thông thường. Nếu P là con trỏ định kiểu thì P^ là biến có kiểu là kiểu dữ liệu mà P trỏ tới. Nếu P là con trỏ không định kiểu thì P^ là một biến không định kiểu có địa chỉ lưu trong P, nó được dùng khi không quan tâm đến kiểu dữ liệu được truy cập.</p>
<p>Chương trình <strong>ConTro.pas</strong> minh hoạ ý nghĩa của biến con trỏ:</p>
<p>var x: real; p,q: ^real;<br />
begin x:= 123.456789; p:= @x; q:= addr(x);<br />
writeln(&#8216;x = &#8216;,x:13:5,&#8217;  p^ = &#8216;,p^:13:5,&#8217;  q^ = &#8216;,q^:13:5);<br />
writeln(&#8216;Dia chi bien x : &#8216;,seg(x),&#8217;:',ofs(x));<br />
writeln(&#8216;Dia chi luu trong con tro p : &#8216;,seg(p^),&#8217;:',ofs(p^));<br />
readln;<br />
end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">3. Cấp phát động</span></strong></p>
<p>Đối với biến con trỏ ta có thể dùng kỹ thuật cấp phát động nhờ các thủ tục New, Getmem để tạo các biến động P^ mới. Vùng cấp phát động bao giờ cũng là vùng nhớ tự do (Heap). Turbo Pascal quản lý vùng Heap thông qua con trỏ Heap. Con trỏ Heap luôn luôn trỏ vào byte tự do đầu tiên của vùng nhớ còn tự do của Heap. Mỗi lần dùng thủ tục New tạo ra một biến động thì con trỏ Heap dịch chuyển về phía đỉnh của vùng nhớ tự do một số byte tương ứng với kích thước của biến động mới được tạo.</p>
<p>Các hàm và thủ tục liên quan tới cấp phát động:</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><strong> Thủ tục New(P)</strong>, trong đó P là một con trỏ định kiểu, sẽ cấp phát một vùng nhớ trên Heap có kiểu và kích thước do P quy định, P trỏ tới vùng nhớ vừa cấp (tức là P chứa địa chỉ byte đầu tiên của vùng nhớ), tạo ra biến định kiểu P^ (gọi là biến động) và có thể dùng P^ như một biến thông thường. Vùng nhớ đã cấp phát được hệ thống bảo vệ cho đến khi bị thu hồi. Nếu dùng New(P) nhiều lần thì P chứa địa chỉ vùng nhớ được cấp phát lần cuối cùng.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Dispose(P)</strong> thu hồi vùng nhớ đã được cấp phát cho con trỏ P bởi New(P)</p>
<p>Chương trình <strong>SVien.pas</strong> minh hoạ cách dùng các thủ tục New và Dispose:</p>
<p>type SVienPtr = ^SVien;<br />
SVien = Record Hoten: string[25]; DiemTb: real end;<br />
var p,q: SVienPtr;<br />
begin  new(p); p^.hoten:= &#8216;Bui The Tam&#8217;; p^.diemtb:= 5.5;<br />
q:= p; new(p);<br />
write(&#8216;Vao ho ten : &#8216;); readln(p^.hoten);<br />
write(&#8216;Vao diem trung binh : &#8216;); readln(p^.diemtb);<br />
writeln(&#8216;Sinh vien 1: &#8216;,q^.hoten,&#8217;  &#8216;,q^.diemtb:5:2);<br />
writeln(&#8216;Sinh vien 2: &#8216;,p^.hoten,&#8217;  &#8216;,p^.diemtb:5:2);<br />
dispose(q); dispose(p);<br />
readln; end.</p>
<p>Chương trình <span style="font-weight:bold;">CTMang.pas</span> nêu cách khai báo một biến con trỏ kiểu mảng và cách truy nhập các phần tử của mảng.<br />
const nmax = 1000;<br />
type mang= array[1..nmax] of integer;<br />
var a: ^mang; i,n, tong: integer;<br />
begin write(&#8216;Vao n = &#8216;); readln(n); new(a); tong := 0;<br />
for i:=1 to n do<br />
begin write(&#8216;a&#8217;,i,&#8217; = &#8216;); readln(a^[i]); tong:= tong+a^[i] end;<br />
write(&#8216;Mang A: &#8216;); for i:=1 to n do  write(a^[i],&#8217;   &#8216;) ; writeln;<br />
dispose(a); writeln(&#8216;Tong = &#8216;,tong); readln;<br />
end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục GetMem(var P : pointer; n : word)</strong> cấp phát n byte trên Heap cho con trỏ P mà không quan tâm đến kiểu dữ liệu, P chứa địa chỉ byte đầu tiên của vùng nhớ, biến động P^ được dùng như một biến không định kiểu. Khối nhớ lớn nhất có thể tạo trên Heap là 65528 byte.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục FreeMem(var P : pointer; n : word)</strong> thu hồi vùng nhớ n byte được cấp phát bằng GetMem cho con trỏ P.</p>
<p>Chương trình <strong>MangDong.pas</strong> minh hoạ cách dùng các thủ tục Getmem, Freemem để tạo các mảng động (kích thước của chúng không cần ấn định trước) nhằm tiết kiệm bộ nhớ. Lúc đầu mảng chỉ khai tượng trưng có 1 phần tử, sau đó mảng được cấp phát vùng nhớ vừa đủ cho n phần tử cần dùng.</p>
<p>type mang=array[1..1] of real;<br />
var a:^mang; i,n: integer; tong: real;<br />
begin write(&#8216;n = &#8216;); readln(n); tong:= 0;<br />
Getmem(a,n* sizeof(real));<br />
for i:=1 to n do<br />
begin write(&#8216;a&#8217;,i,&#8217; = &#8216;); readln(a^[i]); tong:= tong+a^[i] end;<br />
for i:=1 to n do  writeln(&#8216;a[',i,'] = &#8216;,a^[i]:13:5);<br />
Freemem(a,n* sizeof(real)); writeln(&#8216;Tong = &#8216;,tong:13:5); readln;<br />
end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Biến HeapEnd: pointer</strong> trỏ tới điểm cuối của Heap được chương trình sử dụng, <strong>biến HeapOrg: pointer</strong> trỏ tới điểm bắt đầu của Heap được dùng cấp phát động. Các biến HeapEnd và HeapOrg được hệ thống khởi gán khi chương trình bắt đầu chạy và không thay đổi khi chương trình chạy.</p>
<p>* <strong>Biến HeapPtr: pointer</strong> trỏ tới đỉnh của Heap, tức là đỉnh của vùng nhớ cấp phát động và cũng là đáy của vùng nhớ tự do. Khởi đầu giá trị HeapPtr = HeapOrg.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm MemAvail: LongInt</strong> cho tổng số byte còn tự do trên Heap. <strong>Hàm MaxAvail: LongInt</strong> cho số byte liên tục lớn nhất còn tự do trên Heap. Các vùng nhớ còn tự do trên Heap thường bị phân ra thành các khối nhỏ do máy cấp phát và giải toả các vùng nhớ trên Heap không theo một thứ tự nào. Để tránh tràn Heap, trước khi cấp phát bộ nhớ cho một đối tượng có kích thước lớn (như mảng, mảng các bản ghi) ta nên dùng hàm MaxAvail để kiểm tra có đủ bộ nhớ không.</p>
<p>Chương trình <strong>Heap.pas</strong> minh hoạ cách dùng các biến và hàm ở trên để quản lý Heap. Trong Turbo Pascal cho phép khai báo một mảng có kích thước không quá 64 KB.</p>
<p>type mang1 = array[1..65535] of byte;<br />
mang2 = array[1..100, 1..109] of real;<br />
var a: ^mang1; b: ^mang2; top: pointer; i,j: longint;<br />
begin writeln(&#8216;HeapOrg = &#8216;,seg(HeapOrg^),&#8217;:',ofs(HeapOrg^));<br />
writeln(&#8216;HeapEnd = &#8216;,seg(HeapEnd^),&#8217;:',ofs(HeapEnd^));<br />
writeln(&#8216;HeapPtr = &#8216;,seg(HeapPtr^),&#8217;:',ofs(HeapPtr^));<br />
mark(top);<br />
new(a); for i:=1 to 65535 do a^[i]:=1;<br />
writeln(&#8216;MemAvai = &#8216;,memavail,&#8217;  MaxAvail = &#8216;,maxavail);<br />
if MaxAvail &#62;= sizeof(mang2) then<br />
begin new(b);<br />
for i:=1 to 100 do for j:=1 to 109 do b^[i,j]:=1.234;<br />
writeln(&#8216;MemAvai = &#8216;,memavail,&#8217;  MaxAvail = &#8216;,maxavail);<br />
end;<br />
writeln(a^[65535],&#8217;  &#8216;,b^[100,109]:8:3); release(top);<br />
writeln(&#8216;MemAvai = &#8216;,memavail,&#8217;  MaxAvail = &#8216;,maxavail);<br />
readln ;<br />
end.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Mark(var Top: pointer)</strong> gán giá trị của con trỏ Heap cho con trỏ Top. Thủ tục này dùng để đánh dấu địa chỉ bắt đầu cấp phát động.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Release(var Top: pointer)</strong>: thu hồi tất cả các vùng nhớ được cấp phát bắt đầu từ địa chỉ được lưu trong con trỏ Top nhờ thủ tục Mark(Top) cho đến đỉnh Heap hiện tại. Thủ tục Mark và Release  nhằm xoá một loạt các biến động khỏi Heap.</p>
<p>Chương trình <strong>MangCT.pas</strong> minh hoạ cách dùng các thủ tục Mark, Release và mảng các con trỏ.</p>
<p>const nmax = 1000;<br />
var b: array[1..nmax] of ^integer; i,n,tong: integer; top: pointer;<br />
begin write(&#8216;Vao n = &#8216;); readln(n); tong:=0; mark(top);<br />
for i:=1 to n do  begin new(b[i]);<br />
write(&#8216;b&#8217;,i,&#8217; = &#8216;); readln(b[i]^); tong:= tong+b[i]^; end;<br />
for i:=1 to n do  write(b[i]^,&#8217;   &#8216;) ; writeln; release(top);<br />
writeln(&#8216;Tong = &#8216;,tong); readln;<br />
end.<br />
<span style="font-weight:bold;"><br />
Bài tập </span><br />
1. Sử dụng hàm Randomize và hàm Random (hàm tạo một số ngẫu nhiên trên đoạn [0, 1] để tạo hai mảng số ngẫu nhiên A và B, mỗi mảng gồm 10.000 phần tử. In hai mảng này ra tệp văn bản, mỗi dòng 5 số, mỗi số có 6 số lẻ.</p>
<p>2. Khai 4 mảng số thực A, B, C và D. Mỗi mảng có N phần tử, N &#60;= 10.000. Tạo số liệu ngẫu nhiên cho các mảng A và B. Tính mảng C và D theo công thức: C[i] = A[i] + B[i], D[i] = A[i] &#8211; B[i] với i = 1, . . ., N. In các mảng C và D ra màn hình hay ra tệp, mỗi dòng 5 số, mỗi số có 5 số lẻ.<br />
<span style="font-weight:bold;"> </span></p>
<p><span style="font-weight:bold;">Bùi Thế Tâm soạn 29/6/2009</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal : Unit tự tạo]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/pascal-unit-tutao/</link>
<pubDate>Mon, 19 Oct 2009 02:03:53 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/pascal-unit-tutao/</guid>
<description><![CDATA[1. Unit tự tạo Ngoài các thư viện chương trình có sẵn trong unit chuẩn của Turbo Pascal như System, ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><strong><span style="font-size:14pt;font-family:Arial;">1. Unit tự tạo</span></strong></p>
<p>Ngoài các thư viện chương trình có sẵn trong unit chuẩn của Turbo Pascal như System, Crt, Dos, Graph … người sử dụng còn có thể xây dựng cho mình các thư viện chương trình mới bằng cách tự tạo các unit. Mục đích của unit tự tạo: tạo các thư viện hàm và thủ tục để tránh lặp lại những công việc giống nhau, giải quyết vấn đề thiếu bộ nhớ khi thiết kế các chương trình lớn, tạo công cụ để liên kết các module chương trình với nhau mà vẫn đảm bảo tính độc lập cho từng lập trình viên.<!--more--></p>
<p><strong><span style="font-size:13pt;font-family:Arial;">a) Cấu trúc của một Unit</span></strong></p>
<p>Cũng giống như bất kỳ một chương trình nguồn Pascal nào, tệp unit có dạng text và chứa các dòng lệnh của ngôn ngữ Pascal. Tuy nhiên chúng khác nhau về cấu trúc. Các thành phần của unit bao gồm: phần định nghĩa (tên unit), phần giao tiếp (Interface), phần cài đặt (Implementation), phần khởi tạo (Initialization), phần kết thúc (End).</p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span> <strong><span style="font-size:13pt;">Phần định nghĩa</span></strong> nhằm mục đích báo cho trình biên dịch biết đây là unit (nếu không có phần này thì mặc nhiên cho là chương trình). Phần này chỉ cần một câu lệnh: <strong><span style="font-size:10pt;">Unit TenUnit ;</span></strong> trong đó TenUnit là tên của Unit, nó phải trùng với phần chính của tên tệp lưu trên đĩa. Ví dụ nếu tạo một unit có tên là Tools lưu trên đĩa bởi tệp Tools.pas thì ở dòng định nghĩa phải là <strong><span style="font-size:10pt;">Unit Tools ;</span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span><span style="font-size:10pt;"> </span><strong><span style="font-size:13pt;">Phần giao tiếp</span></strong> khai báo tất cả những gì dùng chung (các chương trình và Unit khác có thể sử dụng). Phần này bắt đầu bằng từ khoá Interface, theo sau là tên các Unit, hằng, biến, kiểu dữ liệu, tên hàm và thủ tục dùng để giao tiếp với bên ngoài.</p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span><span style="font-size:10pt;"> </span><strong><span style="font-size:13pt;">Phần cài đặt</span></strong> chứa những gì dành riêng cho Unit và dùng để cài đặt các thủ tục, hàm đã khai báo ở phần giao tiếp. Đây chính là phần cốt lõi, quyết định chức năng của thư viện chương trình cần xây dựng. Phần này bắt đầu bằng từ khoá Implementation. Các chương trình con thuộc phần này được tự do sử dụng các khai báo trong phần Interface, ngoài ra mỗi chương trình con có thể có tập các biến riêng của mình. Trong thân một chương trình con có thể gọi tới các chương trình con khác của Unit.</p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span><span style="font-size:10pt;"> </span><strong><span style="font-size:13pt;">Phần khởi tạo</span></strong> (có thể có hoặc không): phần này nằm ngay trước phần kết thúc, bắt đầu bằng từ khoá Begin, theo sau là các lệnh để khởi tạo. Nếu trong một chương trình chính có dùng nhiều Unit thì phần khởi tạo (nếu có) của từng unit sẽ được thực hiện (theo thứ tự chỉ ra trong Uses) trước khi thực hiện chương trình.</p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span><span style="font-size:10pt;"> </span><strong><span style="font-size:13pt;">Phần kết thúc</span></strong> chỉ gồm từ khoá <strong>End.</strong> (có dấu chấm ở sau) báo cho trình biên dịch biết đã hết phần cài đặt của unit. Tương tự như tệp chương trình nguồn, tất cả những gì viết sau từ khoá End. đều không có tác dụng.</p>
<p>Dạng mẫu của một Unit (tên tệp là MyUnit.pas):</p>
<p><strong>Unit MyUnit ;</strong></p>
<p><strong>Interface</strong></p>
<p>Khai báo Uses</p>
<p>Khai báo Const, Type, Var</p>
<p>Khai báo Procedure, Function</p>
<p><strong>Implementation</strong></p>
<p>Khai báo Uses</p>
<p>Khai báo Const, Type, Var</p>
<p>Cài đặt các Procedure, Function</p>
<p><strong>Begin</strong></p>
<p>Các lệnh khởi tạo &#8211; chỉ xuất hiện khi có từ khoá Begin</p>
<p><strong>End.</strong></p>
<p><strong><span style="font-size:13pt;font-family:Arial;">b) Cách sử dụng Unit</span></strong></p>
<p>Sau khi tạo được unit, có thể biên dịch vào đĩa hoặc bộ nhớ. Đối với các unit thường sử dụng nên biên dịch ra đĩa thành các tệp *.TPU tương ứng bằng cách: khởi động Pascal, nạp tệp unit cần dịch, vào menu Compile, chọn Destination là Disk, ấn Alt+F9. Các chương trình muốn sử dụng unit nào, chỉ cần thêm tên unit đó vào câu lệnh Uses</p>
<p>Tệp <strong>TVien.pas</strong> sau nhằm tạo một unit của người dùng có tên là TVien:</p>
<p>Unit TVien;<br />
Interface<br />
const nmax=100;<br />
type mang1= array[1..nmax] of real;<br />
mang2= array[1..nmax,1..nmax] of integer;<br />
var i,j,n,m: integer;<br />
function TichVH(n:integer; x,y: mang1): real;<br />
procedure ChuyenVi(n: integer; var P: mang2);<br />
Implementation<br />
function TichVH;<br />
var i: integer; s: real;<br />
begin  s:=0; for i:=1 to n do s:=s+x[i]*y[i];<br />
TichVH:= s;<br />
end;<br />
procedure ChuyenVi;<br />
var i,j,k: integer;<br />
begin  for i:=1 to n-1 do<br />
for j:=i+1 to n do<br />
begin  k:=P[i,j];<br />
P[i,j]:=P[j,i]; P[j,i]:=k<br />
end;<br />
end;<br />
begin  n:= 5;<br />
end.<br />
Các chương trình khác có thể dùng các thành phần sau của Unit TVien: hằng số nmax; các kiểu dữ liệu mang1, mang2; các biến nguyên i, j, n, m; hàm TichVH; thủ tục ChuyenVi. Trong phần khởi tạo: khởi tạo biến n bằng 5. Sau khi biên dịch thành tệp Tvien.tpu ra đĩa, ta có thể lập hai chương trình: tính tích vô hướng hai véc tơ, chuyển vị ma trận.</p>
<p>Chương trình <span style="font-weight:bold;">Tich2Vt.pas</span> tính tích vô hướng hai véc tơ nhập vào từ bàn phím:<br />
uses crt,TVien;<br />
var  a,b: mang1;<br />
begin<br />
clrscr;<br />
for i:=1 to n do<br />
begin write(&#8216;a&#8217;,i,&#8217;, b&#8217;,i,&#8217; = &#8216;);<br />
readln(a[i],b[i])<br />
end;<br />
writeln(&#8216;Tich vo huong = &#8216;,TichVH(n,a,b):1:5);<br />
readln;<br />
end.<br />
Trong chương trình này không phải khai lại kiểu Mang1, các biến nguyên i, n cũng không cần khai, giá trị của n bằng 5 (lấy từ Unit TVien). Như vậy mỗi véc tơ a, b đều có 5 phần tử.</p>
<p>Chương trình <span style="font-weight:bold;">ChuyenVi.pas </span>nhằm chuyển vị ma trận vuông A cấp m qua đường chéo chính.<br />
uses crt,TVien;<br />
var a:mang2;<br />
begin clrscr;<br />
write(&#8216;Co ma tran m = &#8216;); readln(m);<br />
for i:=1 to m do<br />
for j:=1 to m do<br />
begin write(&#8216;a[',i,',',j,'] = &#8216;);<br />
readln(a[i,j])<br />
end;<br />
for i:=1 to m do<br />
begin for j:=1 to m do write(a[i,j],&#8217;   &#8216;);<br />
writeln<br />
end;<br />
readln; chuyenvi(m,a);<br />
for i:=1 to m do<br />
begin for j:=1 to m do write(a[i,j],&#8217;   &#8216;);<br />
writeln<br />
end;<br />
readln;<br />
end.</p>
<p>Trong chương trình này không phải khai lại kiểu Mang2, các biến nguyên i, j, m cũng không cần khai.</p>
<p><strong>Chú ý : </strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span>Thư mục chứa các tệp TPU được xác định như sau: trong môi trường phát triển tích hợp (IDE) vào menu Options, chọn Directories, nhập đường dẫn tới thư mục TPU trong hộp &#8220;EXE &#38; TPU Directories&#8221;. Nếu để trống mục này, trình biên dịch sẽ tìm các tệp TPU trên thư mục hiện hành.</p>
<p><span style="font-size:10pt;font-family:Symbol;">* </span><span style="font-size:10pt;"> </span>Nếu một chương trình sử dụng các unit có chứa hàm hoặc thủ tục trùng tên thì tên unit khai báo sau trong câu lệnh USES sẽ được ưu tiên. Ví dụ: trong unit Crt chuẩn đã có thủ tục ClrScr; trong unit TVien ta tự xây dựng một thủ tục ClrScr (tạo một cửa sổ nhỏ trên màn hình). Giả sử ở đầu chương trình chính ta dùng lệnh</p>
<p align="center">Uses CRT, TVIEN ;</p>
<p>Khi đó nếu trong chương trình chính dùng lệnh ClrScr thì máy sẽ thực hiện thủ tục ClrScr của Unit TVien. Muốn gọi đúng thủ tục ClrScr của unit Crt ta thực hiện như sau: Crt.ClrScr.</p>
<p><span style="font-size:10pt;font-family:Symbol;">* </span><span style="font-size:10pt;"> </span>Nếu chương trình chính và các Unit (hoặc giữa các Unit) có các đại lượng trùng tên, thì trong chương trình chính tên sẽ chỉ định đại lượng định nghĩa trong chương trình chính, trong unit nào thì tên sẽ chỉ định đại lượng định nghĩa trong unit đó.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span>Các unit có thể tham khảo vòng, ví dụ unit A dùng unit B, unit B dùng unit C, unit C lại dùng unit A. Điều này được thực hiện bằng cách chèn câu lệnh USES và tên các unit cần tham khảo vòng ngay sau khai báo Implementation.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">2. Sử dụng tệp Include</span></strong></p>
<p>Ngoài cách tổ chức thư viện theo Unit, Turbo Pascal còn có cách tổ chức thư viện chương trình theo các tệp Include (bao gồm). Giả sử chương trình nguồn của một hoặc nhiều chương trình con đã được thử nghiệm hoàn toàn chính xác, ta để chúng trên một tệp có đuôi PAS (ví dụ ThuVien1.pas), tệp này gọi là tệp Include. Sau này khi lập một chương trình khác, ta muốn sử dụng các chương trình con trong tệp ThuVien1.pas thì chỉ cần đánh dấu vị trí trong chương trình mà tại đó tệp Include sẽ được chèn vào bằng việc dùng dẫn hướng biên dịch: <strong>{ $I ThuVien1.pas }</strong>. Khi dịch chương trình gặp lệnh trên, máy sẽ lôi tệp nguồn ThuVien1.pas từ đĩa chèn vào vị trí đã đặt lệnh và biên dịch. So với cách dùng unit, cách này có thời gian dịch chương trình lâu hơn nhưng cách dùng lại rất đơn giản.</p>
<p>Giả sử tệp <span style="font-weight:bold;">ThuVien1.pas</span> có dạng:<br />
Function CVDT(r: real): real;<br />
Begin  CVDT := 2*Pi*r ; End;</p>
<p>Chương trình chính <span style="font-weight:bold;">DTron.pas</span> tính chu vi đường tròn:<br />
var bk: real;<br />
{ $I ThuVien1.pas }<br />
begin<br />
write(&#8216;Vao ban kinh duong tron : &#8216;); readln(bk);<br />
writeln(&#8216; Chu vi duong tron : &#8216;, CVDT(bk):1:5);<br />
readln;<br />
end.<br />
<span style="font-weight:bold;">Bài tập</span><br />
1. Lập một unit ThuVien1.tpu gồm hàm tìm ước số chung lớn nhất, tìm bội số chung nhỏ nhất của hai số nguyên, và thủ tục sắp xếp một mảng số thực theo thứ tự tăng hoặc giảm dần. Tiếp theo dịch tệp ThuVien1.pas ra tệp ThuVien1.tpu, ta được Unit ThuVien1. Dùng unit này giải ba bài toán sau:<br />
a) Cho số nguyên n. Tìm tất cả các phân số tối giản dạng i / j với 1&#60;= i, j &#60;= n. Thuật toán : với mỗi phân số i / j , nếu ước số chung lớn nhất của i và j là 1 thì phân số là tối giản.<br />
b) Nhập vào từ bàn phím một mảng số thực gồm n phần tử, sắp xếp mảng theo thứ tự giảm dần.<br />
c) Tìm USCLN và BSCNN của n số nhập vào từ bàn phím.</p>
<p>2. Xây dựng một unit gồm các hàm tính: diện tích hình tam giác, diện tích hình thang, chu vi đường tròn, diện tích hình tròn, diện tích mặt cầu, diện tích xung quanh khối tứ diện đều, thể tích khối tứ diện đều . . . Dịch unit này ra tệp có đuôi TPU. Dùng unit để tính chu vi, diện tích, thể tích các hình trên với số liệu nhập vào từ bàn phím.</p>
<p><span style="font-weight:bold;">Bùi Thế Tâm soạn 29/6/2009</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal: Unit CRT]]></title>
<link>http://buithetam.wordpress.com/2009/10/19/pascal-unit-crt/</link>
<pubDate>Mon, 19 Oct 2009 02:00:21 +0000</pubDate>
<dc:creator>ngoctan</dc:creator>
<guid>http://buithetam.wordpress.com/2009/10/19/pascal-unit-crt/</guid>
<description><![CDATA[Unit là một tập hợp các hằng số, các kiểu dữ liệu, các biến, các thủ tục và hàm. Mỗi Unit xem như mộ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Unit là một tập hợp các hằng số, các kiểu dữ liệu, các biến, các thủ tục và hàm. Mỗi Unit xem như một thư viện chương trình. Turbo Pascal có sẵn các unit chuẩn: unit System, unit Crt,  unit Dos, unit Printer, unit Overlay, unit Graph, unit Turbo3, unit Graph3, unit Windos. Năm unit đầu tiên chứa trong tệp Turbo.tpl, tệp này được tải vào bộ nhớ ngay khi Turbo Pascal khởi động. Ngoài các unit chuẩn có sẵn người dùng có thể tự mình lập các unit riêng.   <!--more--></p>
<p>Trong chương này sẽ nghiên cứu unit Crt, unit này dùng để điều khiển việc in thông tin ra màn hình, điều khiển bàn phím và sử dụng âm thanh. Khi dùng các hàm và thủ tục của unit Crt ở đầu chương trình cần có khai báo: <strong><span style="font-size:11pt;">uses crt;</span></strong></p>
<p><strong><span style="font-size:14pt;font-family:Arial;">1. Điều khiển in thông tin ra màn hình ở chế độ văn bản</span></strong></p>
<p>Trong chế độ văn bản màn hình chuẩn hiện nay có 80 cột và 25 dòng, góc trên bên trái màn hình có toạ độ (1,1), trục x hướng sang phải và có giá trị từ 1 đến 80, trục y hướng xuống dưới và có giá trị từ 1 đến 25. Trên màn hình có một điểm sáng nhấp nháy gọi là con trỏ màn hình. Việc in thông tin bởi lệnh write bắt đầu từ vị trí con trỏ, in xong một ký tự con trỏ tự động chuyển tới vị trí kế tiếp. Thông tin được nhập vào từ bàn phím bởi lệnh read cũng hiện lên màn hình bắt đầu từ vị trí con trỏ.</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">Cửa sổ văn bản và các hàm, thủ tục liên quan</span></strong><strong></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span> <strong>Thủ tục Window(x1, y1, x2, y2: byte)</strong>: thiết lập một cửa sổ mới để trình bày, (x1,y1) là toạ độ góc trên bên trái và (x2,y2) là toạ độ góc dưới bên phải cửa sổ. Khi một cửa sổ mới được thiết lập thì mọi kết xuất ra màn hình đều nằm trong cửa sổ mới, mọi giá trị toạ độ đều là tương đối đối với cửa sổ hiện hành (góc trên trái cửa sổ có toạ độ (1,1) ). Cửa sổ hiện hành có hiệu lực cho đến khi định nghĩa một cửa sổ khác. Lời gọi window(1,1,80,25) sẽ quay về chế độ toàn màn hình (cửa sổ ngầm định).</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Crlscr</strong> : xoá tất cả các ký tự trên cửa sổ hiện hành, đưa con trỏ về toạ độ (1,1), đặt màu nền của cửa sổ theo lệnh TextBackGround trước đó.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục ClrEol</strong> : xoá các ký tự từ vị trí hiện tại của con trỏ cho tới cuối dòng trong cửa sổ hiện hành.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục DelLine</strong>: xoá dòng chứa con trỏ trong cửa sổ hiện hành, các dòng ở dưới dịch lên trên một dòng, một dòng trống với màu nền hiện hành thêm vào đáy cửa sổ.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục InsLine</strong>: chèn một dòng trống với màu nền hiện hành vào vị trí con trỏ hiện tại, các dòng ở dưới sẽ đẩy xuống một dòng.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Gotoxy(x,y: byte)</strong>: đưa con trỏ về cột x dòng y của cửa sổ hiện tại.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm WhereX: byte</strong> cho toạ độ x của con trỏ trong cửa sổ hiện tại.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm WhereY: byte</strong> cho toạ độ y của con trỏ trong cửa sổ hiện tại.</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">Màu chữ và màu nền</span></strong>. Mỗi ký tự trên màn hình tương ứng với hai giá trị màu: màu chữ và màu nền (màu của hình chữ nhật phía sau ký tự). Unit Crt định nghĩa các hằng với các tên màu tương ứng:</p>
<table style="border:medium none;border-collapse:collapse;" border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td style="border:1pt solid windowtext;width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">giá   trị</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">tên   hằng</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">màu</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">hệ   2</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">giá   trị</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">tên   hằng</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">màu</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">hệ   2</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">0</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Black</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">đen</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">000</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">8</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">DarkGray</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">xám   tối</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1000</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">1</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Blue</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">001</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">9</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">LightBlue</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh   sáng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1001</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">2</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Green</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh   lá cây</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">010</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">10</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">LightGreen</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh   lá cây sáng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1010</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">3</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Cyan</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh   lơ</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">011</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">11</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">LightCyan</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">xanh   lơ sáng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1011</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">4</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Red</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">đỏ</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">100</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">12</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">LightRed</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">đỏ   sáng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1100</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">5</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Magenta</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">tím</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">101</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">13</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">LightMagenta</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">tím   sáng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1101</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">6</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">Brown</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">nâu</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">110</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">14</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">Yellow</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">vàng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1110</p>
</td>
</tr>
<tr>
<td style="width:38.8pt;padding:0 1.4pt;" valign="top">
<p align="center">7</p>
</td>
<td style="width:56.1pt;padding:0 1.4pt;" valign="top">
<p align="center">LightGray</p>
</td>
<td style="width:63.75pt;padding:0 1.4pt;" valign="top">
<p align="center">xám   sáng</p>
</td>
<td style="width:29.75pt;padding:0 1.4pt;" valign="top">
<p align="center">111</p>
</td>
<td style="width:37.4pt;padding:0 1.4pt;" valign="top">
<p align="center">15</p>
</td>
<td style="width:74.8pt;padding:0 1.4pt;" valign="top">
<p align="center">White</p>
</td>
<td style="width:84.15pt;padding:0 1.4pt;" valign="top">
<p align="center">trắng</p>
</td>
<td style="width:36.2pt;padding:0 1.4pt;" valign="top">
<p align="center">1111</p>
</td>
</tr>
</tbody>
</table>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục TextBackGround(color: byte)</strong>: đặt màu nền, color có giá trị từ 0 đến 7. Muốn màu nền loang đều trên màn hình thì sau lệnh này ta phải có lệnh Clrscr.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục TextColor(color: byte)</strong>: đặt màu chữ, color có giá trị từ 0 đến 15. Các giá trị màu được đặt có hiệu lực với các lệnh in sau đó cho đến khi gặp một lệnh đặt màu mới. Màu nền ngầm định là 0, màu chữ ngầm định là 7.</p>
<p>Thuộc tính màu lưu trong một byte có cấu trúc như sau: bit 7 là thuộc tính nhấp nháy, ba bit tiếp theo (6, 5, 4) là màu nền chứa được 8 giá trị, bốn bit đầu tiên (3, 2, 1, 0) là màu chữ chứa được 16 giá trị. Vì 1000 000 (hệ 2) = 128 hệ 10, nên hằng Blink trong unit Crt định nghĩa là 128. Unit Crt dùng biến <strong>TextAttr</strong> : byte để cất giữ thuộc tính màu theo cấu trúc như trên. Chẳng hạn nếu TextAttr hiện có giá trị bằng 61 thì màu nền là Cyan, màu chữ là LightMagenta, vì 61 = 3*16+13. Ngược lại ta cũng có thể gán thuộc tính màu cho biến này để đặt lại màu chữ và màu nền, lệnh <strong><span style="font-size:11pt;">TextAttr :=1*16+15+128</span></strong> sẽ đặt màu nền là Blue, màu chữ là White và nhấp nháy.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục NormVideo</strong>: khôi phục biến TextAttr theo giá trị mà nó có khi chương trình bắt đầu chạy.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục HighVideo</strong>: cho bit 3 của TextAttr bằng 1, tức là chuyển các màu 0-7 thành các màu 8-15 tương ứng.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục LowVideo</strong>: chon bit 3 của TextAttr bằng 0, tức là chuyển các màu 8-15 thành các màu 0-7 tương ứng.</p>
<p>Chương trình <strong>TLuong.pas</strong>: nhập dữ liệu về một nhân viên trong một cửa sổ (mã, họ tên, hệ số lương, hệ số phụ cấp trách nhiệm), in kết quả tính lương ở cửa sổ thứ hai (lương chính = 290000 * hệ số lương, phụ cấp = 290000*hệ số phụ cấp, bảo hiểm xã hội = 5% lương chính, bảo hiểm y tế = 1% lương chính, số tiền được lĩnh), về lại cửa sổ thứ nhất để nhập người tiếp theo. Chương trình minh hoạ cách mở nhiều cửa sổ và chuyển đổi cửa sổ làm việc. Cuối chương trình cần khôi phục cửa sổ ngầm định của DOS và thuộc tính văn bản ngầm định. Thủ tục Khung(x1,y1,x2,y2): vẽ một khung nét kép trên màn hình với toạ độ góc trên trái là (x1,y1), toạ độ góc dưới bên phải là (x2,y2). Các cửa sổ trên màn hình có đóng khung bên ngoài.</p>
<p>uses crt;<br />
type nhanvien = record<br />
manv: string[6];<br />
hoten: string[25];<br />
hesoluong, hesopc: real;<br />
luong,phucap,bhxh,bhyt,tien: real;<br />
end;<br />
procedure Khung(x1,y1,x2,y2: byte);<br />
var i: integer;<br />
begin<br />
for i:=x1+1 to x2-1 do<br />
begin gotoxy(i,y1); write(chr(205));<br />
gotoxy(i,y2); write(chr(205)) end;<br />
for i:=y1+1 to y2-1 do<br />
begin gotoxy(x1,i); write(chr(186));<br />
gotoxy(x2,i); write(chr(186)) end;<br />
gotoxy(x1,y1); write(chr(201)); gotoxy(x2,y1); write(chr(187));<br />
gotoxy(x1,y2); write(chr(200)); gotoxy(x2,y2); write(chr(188));<br />
end;<br />
var x: nhanvien; min: real; tt:char;<br />
begin textbackground(1); textcolor(15); clrscr;<br />
min:=290000; Khung(1,1,39,9); Khung(41,11,80,24); tt:=&#8217;C';<br />
while upcase(tt)=&#8217;C&#8217; do begin<br />
window(2,2,38,8); clrscr;<br />
gotoxy(9,1); write(&#8216;DU LIEU NHAP VAO&#8217;);<br />
gotoxy(3,2); write(&#8216;Vao ma nhan vien : &#8216;); readln(x.manv);<br />
gotoxy(3,3); write(&#8216;Vao ho ten : &#8216;); readln(x.hoten);<br />
gotoxy(3,4); write(&#8216;He so luong : &#8216;); readln(x.hesoluong);<br />
gotoxy(3,5); write(&#8216;He so phu cap trach nhiem : &#8216;); readln(x.hesopc);<br />
gotoxy(3,6); write(&#8216;An Enter xem ket qua tinh&#8230;&#8217;); readkey;<br />
window(42,12,79,23);<br />
gotoxy(9,1); write(&#8216;KET QUA TINH LUONG&#8217;);<br />
gotoxy(2,2); write(&#8216;Ma nhan vien : &#8216;,x.manv);<br />
gotoxy(2,3); write(&#8216;Ho ten : &#8216;,x.hoten);<br />
gotoxy(2,4); write(&#8216;He so luong : &#8216;,x.hesoluong:1:2);<br />
gotoxy(2,5); write(&#8216;He so phu cap trach nhiem : &#8216;,x.hesopc:1:2);<br />
x.luong := min*x.hesoluong;<br />
x.phucap := min*x.hesopc;<br />
x.bhxh := 0.05* x.luong;<br />
x.bhyt := 0.01* x.luong;<br />
x.tien := x.luong+x.phucap-x.bhxh-x.bhyt;<br />
gotoxy(2,6); write(&#8216;Luong chinh : &#8216;,x.luong:7:0);<br />
gotoxy(2,7); write(&#8216;Phu cap trach nhiem : &#8216;,x.phucap:7:0);<br />
gotoxy(2,8); write(&#8216;Bao hiem xa hoi : &#8216;,x.bhxh:7:0);<br />
gotoxy(2,9); write(&#8216;Bao hiem y te : &#8216;,x.bhyt:7:0);<br />
gotoxy(2,10); write(&#8216;Tien thuc linh : &#8216;,x.tien:7:0);<br />
gotoxy(2,11); write(&#8216;Co nhap tiep khong C/K ?&#8217;); tt:= readkey;<br />
if upcase(tt)&#60;&#62;&#8217;C&#8217; then break; clrscr;<br />
end;<br />
window(1,1,80,25);  TextAttr:= 7; clrscr;<br />
end.</p>
<p>Chương trình <span style="font-weight:bold;">Mau.pas</span> minh hoạ cách dùng các hàm và thủ tục về màu sắc.<br />
uses crt;<br />
begin  clrscr;<br />
writeln(&#8216;TextAttr sau khi khoi dong chuong trinh = &#8216;,TextAttr);{7}<br />
TextAttr := $B6; {= 1011 0110 he 2} writeln;<br />
writeln(&#8216;Mau chu Brow nhap nhay, mau nen Cyan&#8217;);<br />
HighVideo;  { TextAttr = 1011 1110 he 2 } writeln;<br />
writeln(&#8216;Mau chu Yellow nhap nhay, mau nen Cyan&#8217;);<br />
TextAttr := $2D; {= 0010 1101 he 2} writeln;<br />
writeln(&#8216;Mau chu LightMagenta khong nhay, mau nen Green&#8217;);<br />
LowVideo; { TextAttr = 0010 0101 he 2} writeln;<br />
writeln(&#8216;Mau chu Magenta khong nhay, mau nen Green&#8217;);<br />
NormVideo; { TextAttr = 0000 0111 he 2 = 7 he 10} writeln;<br />
writeln(&#8216;Mau chu LightGray, nen Black, TextAttr= &#8216;,TextAttr);<br />
readln;<br />
end.</p>
<p><strong><span style="font-size:13pt;font-family:Arial;">Các chế độ màn hình</span></strong><strong><span style="font-family:Arial;"> </span></strong></p>
<p><span style="font-size:10pt;font-family:Symbol;">·</span><span style="font-size:10pt;"> </span><strong>Thủ tục TextMode(mode: word)</strong>: đặt lại chế độ màn hình, toàn bộ màn hình cũ bị xoá, về lại chế độ toàn màn hình, con trỏ về góc trên bên trái, biến TextAttr được đặt lại theo giá trị nguyên thuỷ. Các giá trị của Mode:</p>
<p>Tên hằng                 Giá trị      Mô tả</p>
<p>BW40                     0              40 cột 25 dòng, đen/trắng trên màn hình màu</p>
<p>C40                        1              40 cột 25 dòng, chế độ màu trên màn hình màu</p>
<p>BW80                     2              80 cột 25 dòng, đen/trắng trên màn hình màu</p>
<p>C80                        3              80 cột 25 dòng, chế độ màu trên màn hình màu</p>
<p>Mono                      7              80 cột 25 dòng, đen/trắng trên màn hình đơn sắc</p>
<p>Font8&#215;8                  256          đặt chế độ 50 dòng cho màn hình VGA</p>
<p>Giá trị ngầm định cho các màn hình hiện nay là C80. Giá trị Font8&#215;8 dùng kết hợp với các giá trị khác, ví dụ TextMode(C40+Font8&#215;8) sẽ đặt chế độ màn hình 40 cột, 50 dòng, 16 màu trên màn hình VGA. Biến LastMode lưu lại giá trị mode của lần gọi TextMode gần nhất.</p>
<p>Chương trình <strong>Mode.pas</strong> trình diễn tất cả các chế độ màn hình. Thủ tục Print() lấp đầy màn hình bằng một ký tự.</p>
<p>uses crt;<br />
procedure Print(m,n: byte; ch: char);<br />
var i,j: integer;<br />
begin clrscr;<br />
for i:=1 to m-1 do for j:=1 to n do begin gotoxy(j,i); write(ch); end;<br />
for j:=1 to n-1 do begin gotoxy(j,m); write(ch) end;<br />
gotoxy(1,1);<br />
end;<br />
var OldMode: byte;<br />
begin clrscr;<br />
writeln(&#8216;Lastmode = &#8216;,LastMode,&#8217; TextAttr = &#8216;,TextAttr); readkey;<br />
OldMode:=Lastmode;  TextAttr:= 3*16+12; Print(25,80,&#8217;A'); readkey;<br />
TextMode(C80+Font8&#215;8); TextAttr:=1*16+ 15; Print(50,80,&#8217;B'); readkey;<br />
TextMode(Mono); Print(25,80,&#8217;C'); readkey;<br />
TextMode(C40+Font8&#215;8);TextAttr:=1*16+13; Print(50,40,&#8217;D'); readkey;<br />
TextMode(BW80); Print(25,80,&#8217;E'); readkey;<br />
TextMode(BW80+256); Print(50,80,&#8217;F'); readkey;<br />
TextMode(BW40); Print(25,40,&#8217;G'); readkey;<br />
TextMode(BW40+256); Print(50,40,&#8217;H'); readkey;<br />
TextMode(OldMode);<br />
writeln(&#8216;Lastmode = &#8216;,LastMode,&#8217; TextAttr = &#8216;,TextAttr); readln;<br />
end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">2. Điều khiển bàn phím</span></strong></p>
<p>Unit Crt cung cấp các hàm để nhận biết các phím được ấn:</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm KeyPressed: boolean</strong> cho giá trị True nếu vùng đệm bàn phím khác rỗng (tức là trước đó đã có phím được ấn mà máy chưa xử lý) và cho False nếu trái lại. Hàm này chỉ kiểm tra mà không làm thay đổi trạng thái vùng đệm bàn phím. Vòng lặp <strong><span style="font-size:11pt;">repeat until keypressed;</span></strong><span style="font-size:13pt;"> </span>sẽ dừng chương trình cho đến khi có một phím được ấn.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Hàm ReadKey: char</strong> lấy ra ký tự đầu tiên trong vùng đệm bàn phím và trả về ký tự này. Thông thường vùng đệm là rỗng, do đó khi gặp lệnh ReadKey chương trình dừng lại chờ người dùng ấn một phím, hàm trả về ký tự vừa ấn, tuỳ theo giá trị này ta có thể quyết định sự làm việc tiếp theo của chương trình. Khi ấn một phím thông thường, máy sẽ gửi vào vùng đệm bàn phím một ký tự, ký tự này có mã ASCII tương ứng, ví dụ chữ A có mã 65, phím Enter có mã 13, phím ESC có mã 27. Khi ấn các phím đặc biệt và các tổ hợp phím máy gửi vào vùng đệm hai ký tự (ký tự  đầu tiên luôn có mã bằng 0, ký tự thứ hai có mã khác 0), ví dụ khi ấn phím mũi tên lên máy gửi vào vùng đệm hai ký tự có mã là (0, 72), Ctrl+F1 là (0, 94). Để nhận diện các phím đặc biệt ta phải hai lần gọi hàm ReadKey để lấy hai ký tự và dùng ký tự thứ hai để nhận biết phím đã ấn. Chương trình ReadKey.pas ở dưới cho ta cách nhận biết tất cả các phím thông thường, các phím đặc biệt và các tổ hợp phím. Vòng lặp sau dùng để làm sạch vùng đệm bàn phím:  <strong><span style="font-size:11pt;">while keypressed do ch:=readkey;</span></strong></p>
<p>Chương trình <strong>KeyPres.pas</strong>: in các kí tự ngẫu nhiên từ A đến Z với màu chữ trên màu nền, vị trí trên màn hình đều là ngẫu nhiên cho tới khi ấn một phím thì kết thúc.</p>
<p>uses crt;<br />
var x,y,c: byte;<br />
begin clrscr; randomize;<br />
repeat  x:= random(80)+1; y := random(25)+1;<br />
c:= random(26)+1; c:=c+64;<br />
textbackground(random(8)); textcolor(random(16)); gotoxy(x,y);<br />
if (x&#60;&#62;80) or (y&#60;&#62;25) then write(chr(c)); delay(500);<br />
until keypressed;<br />
textattr:=7; clrscr;<br />
end.</p>
<p>Chương trình <span style="font-weight:bold;">ReadKey.pas:</span> in ra mã của phím được ấn (cả phím đặc biệt).<br />
uses crt;<br />
var  ch: char;<br />
begin clrscr; writeln(&#8216;Nhan mot phim : &#8216;); ch := readkey;<br />
if ch = chr(0) then  begin ch := readkey;<br />
writeln(&#8216;Ban vua an phim dac biet co ma 0 va &#8216;,ord(ch));<br />
end<br />
else writeln(&#8216;Ban vua an phim co ma ASCII : &#8216;,ord(ch));<br />
readln;<br />
end.</p>
<p>Chương trình <span style="font-weight:bold;">MuiTen.pas:</span> vẽ một hình chữ nhật nền trắng có độ rộng 14 và chiều cao 5 kí tự, dùng 4 phím mũi tên để di chuyển hình chữ nhật theo 4 chiều, ấn ESC kết thúc chương trình.<br />
uses crt;<br />
procedure ChuNhat(x1,y1,mau: byte);<br />
var i,j: byte;<br />
begin textcolor(mau);<br />
for i:=0 to 4 do for j:=0 to 13 do<br />
begin gotoxy(x1+j,y1+i); write(chr(219)) end;<br />
gotoxy(x1,y1);<br />
end;<br />
var x,y,k: byte; ch: char;<br />
begin clrscr; x:=40; y:=12; ChuNhat(x,y,white);<br />
repeat ch:= readkey;<br />
if ch=#0 then<br />
begin ch:= readkey; k:= ord(ch);<br />
case k of<br />
72: begin ChuNhat(x,y,Black); dec(y); ChuNhat(x,y,white) end;<br />
80: begin ChuNhat(x,y,Black); inc(y); ChuNhat(x,y,white) end;<br />
77: begin ChuNhat(x,y,Black); inc(x); ChuNhat(x,y,white) end;<br />
75: begin ChuNhat(x,y,Black); dec(x); ChuNhat(x,y,white) end;<br />
end;<br />
end;<br />
until ch = #27;<br />
end.</p>
<p><strong><span style="font-size:14pt;font-family:Arial;">3. Tạo âm thanh</span></strong></p>
<p>Các hàm và thủ tục để tạo âm thanh:</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Sound(n: word)</strong>: làm cho loa phát ra một âm thanh có tần số là n Hertz cho đến khi gặp thủ tục Nosound.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Nosound</strong>: tắt âm thanh đã phát ra do thủ tục Sound.</p>
<p><span style="font-size:10pt;font-family:Symbol;">*</span><span style="font-size:10pt;"> </span><strong>Thủ tục Delay(m: word)</strong>: dừng chương trình trong thời gian m mili giây.</p>
<p>Có thể dùng ba thủ tục này để tạo một nốt nhạc. Một nốt nhạc được đặc trưng bởi cao độ và trường độ, cao độ được thể hiện bởi thủ tục Sound(n), trường độ được thể hiện bởi thủ tục Delay(m). Ví dụ để tạo nốt sol tròn dùng bộ ba lệnh: <strong><span style="font-size:11pt;">sound(392); delay(1600); nosound;</span></strong></p>
<p>Cao độ của các nốt nhạc ở các bát độ thấp, trung bình, cao và rất cao (đơn vị là Hertz), trường độ các nốt (đơn vị là mili giây) cho trong bảng sau:</p>
<p><strong>Cao độ các nốt                                                               Trường độ</strong></p>
<p>Đô              131          262       523          1047          Nốt tròn               1600</p>
<p>Đô #           139          277       554          1109          Nốt trắng              800</p>
<p>Rê               147          294       587          1175          Nốt đen                400</p>
<p>Rê #            156          311       622          1245          Nốt móc đơn        200</p>
<p>Mi               165          330       659          1319           Nốt móc kép        100</p>
<p>Pha             175          349       698          1397            Nốt móc ba          50</p>
<p>Pha #          185          370       740          1480</p>
<p>Sol              196          392       784          1568</p>
<p>Sol #           208          415       831          1661</p>
<p>La               220          440       880          1760</p>
<p>La #            233          466       932          1865</p>
<p>Si                247          494       988          1976</p>
<p>Chương trình <strong>BaoDong.pas</strong>: tạo hồi còi báo động cho đến khi ấn một phím.</p>
<p>uses crt;<br />
begin clrscr; writeln(&#8216;An phim bat ky de ket thuc bao dong&#8217;);<br />
repeat sound(359); delay(400); sound(200); delay(350)<br />
until keypressed; nosound;<br />
end.</p>
<p>Chương trình <span style="font-weight:bold;">LangToi.pas:</span> chơi bản nhạc &#8220;Làng tôi&#8221; của Văn Cao. Hệ số k dùng để điều khiển tốc độ chơi nhanh hay chậm của bản nhạc. Nếu nhập k&#62;1 (ví dụ 1.5, 2.0) thì bản nhạc chơi chậm lại, nếu k&#60;1 (ví dụ 0.8) bản nhạc chơi nhanh lên, tuỳ theo tốc độ máy mà nhập k cho thích hợp. Thủ tục Tn(c,t) nhằm tạo một nốt nhạc có cao độ là c hertz và trường độ là k*t mili giây.<br />
uses crt;<br />
var dem : integer; k : real; ch : char;<br />
procedure tn(c: word; t: word);<br />
begin sound(c); delay(trunc(k*t)); nosound  end;<br />
begin clrScr; dem := 0; writeln(&#8216;LANG TOI cua Van Cao&#8217;);<br />
write(&#8216;Vao he so toc do k = &#8216;); readln(k);<br />
repeat inc(dem); Writeln(&#8216;Choi ban nhac lan thu &#8216;,dem);<br />
tn(262,800); tn(330,400); tn(392,800); tn(440,400); tn(392,800); tn(392,400); tn(523,400); tn(494,400); tn(440,400); tn(392,800); tn(440,400); tn(392,400); tn(349,400); tn(330,400); tn(392,1200); tn(262,800); tn(294,400); tn(330,800); tn(392,400); tn(523,800);<br />
tn(587,400); tn(659,800); tn(587,400); tn(523,400); tn(587,400); tn(523,400); tn(392,400); tn(330,400); tn(392,400); tn(523,1200); tn(523,800); tn(523,400); tn(440,800); tn(440,400); tn(494,800); tn(494,400); tn(392,1200); tn(349,800); tn(349,400); tn(440,800);<br />
tn(440,400); tn(330,800); tn(294,400); tn(392,1200); tn(262,800); tn(294,400); tn(330,800); tn(349,400); tn(392,800); tn(330,400); tn(294,800); tn(262,400); tn(523,800); tn(494,400); tn(587,800); tn(392,400); tn(523,1200);<br />
write(&#8216;Choi nhac tiep khong (C/K)? &#8216;); ch:=readkey; writeln;<br />
until upcase(ch) = &#8216;K&#8217;;<br />
end.<br />
<span style="font-weight:bold;"><br />
Bài tập</span><br />
1. Tạo các cửa sổ ngẫu nhiên trên màn hình với màu nền ngẫu nhiên, toạ độ cửa sổ ngẫu nhiên. Khi nào ấn phím bất kỳ thì kết thúc chương trình.</p>
<p>2. Lập trình nhập dữ liệu cho một mảng bản ghi a[1..n]. Mỗi bản ghi a[i] gồm các trường: họ tên sinh viên, ngày sinh, lớp học, điểm thi môn tin học đại cương. Các thông báo nhập và dữ liệu nhập vào bố trí trên 6 cửa sổ, mỗi cửa sổ cần có màu khác nhau, các thông báo nhập và phần dữ liệu nhập trên mỗi cửa sổ cũng có màu khác nhau. Mẫu màn hình:<br />
Vào số sinh viên cần nhập :  10<br />
Đang nhập sinh viên thứ    :  7<br />
Vào họ và tên sinh viên     :  Nguyễn Văn Thanh<br />
Vào ngày sinh                   :  20/12/1988<br />
Tên lớp học                       :  QT4-K45<br />
Điểm thi môn Tin học       :  9.5<br />
Sau khi nhập xong hãy in kết quả nhập mảng a[1..n] ra màn hình theo dạng bảng.<br />
<span style="font-weight:bold;">Bùi Thế Tâm soạn 30/6/2009</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[SOFTWARE]]></title>
<link>http://muhardiisman.wordpress.com/2009/10/16/software/</link>
<pubDate>Fri, 16 Oct 2009 12:27:52 +0000</pubDate>
<dc:creator>muhardiisman</dc:creator>
<guid>http://muhardiisman.wordpress.com/2009/10/16/software/</guid>
<description><![CDATA[DOWNLOAD &#8211; Turbo Pascal 7.1 DOWNLOAD &#8211; Update McAfee virusscan enterprise 7.0-8.0 Word t]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p><a title="Update McAfee" href="http://www.mcafee.com/apps/downloads/security_updates/superdat.asp?region=us&#38;segment=enterprise" target="_blank">DOWNLOAD &#8211; Turbo Pascal 7.1</a></p>
<p><a title="Update McAfee" href="http://www.mcafee.com/apps/downloads/security_updates/superdat.asp?region=us&#38;segment=enterprise" target="_blank">DOWNLOAD</a> &#8211; Update McAfee virusscan enterprise 7.0-8.0</p>
<p>Word to PDF Converter<a class="alignleft" title="PRIMO PDF" href="http://download.cnet.com/PrimoPDF/3000-18497_4-10264577.html?part=dl-10264577&#38;subj=dl&#38;tag=button" target="_blank">DOWNLOAD -</a><!--more--></p>
<p><a class="alignleft" title="PDF TO WORD ONLINE" href="http://www.pdftoword.com/" target="_blank">KLIK DISINI</a> &#8211; PDF TO WORD ONLINE</p>
<p><a class="alignleft" title="PDF TO WORD" href="http://www.hellopdf.com/download.php" target="_self">DOWNLOAD</a> &#8211; PDF TO WORD</p>
<p><a title="Nokia PC SUITE 7.1" href="http://nds1.nokia.com/files/support/global/phones/software/Nokia_PC_Suite_7_1_30_9_eng_web.exe" target="_blank">DOWNLOAD</a>- Nokia PC SUITE for Nokia 6120 classic</p>
<p><a class="alignleft" title="XAMPP" href="http://download.softpedia.com/dl/9e5e83c05c2dcd5e3f329b4df5d0b20c/4b14af2b/100032107/software/internet/servers/xampp-win32-1.7.2.exe" target="_blank">DOWNLOAD</a>- XAMPP Local Host v 1.7.2</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Escribir en otro programa desde Delphi]]></title>
<link>http://israelflorescornejo.wordpress.com/2009/10/09/delphi/</link>
<pubDate>Fri, 09 Oct 2009 16:32:42 +0000</pubDate>
<dc:creator>israelflorescornejo</dc:creator>
<guid>http://israelflorescornejo.wordpress.com/2009/10/09/delphi/</guid>
<description><![CDATA[Function AsignarTextoVentanaExterna(const TituloVentana : String; const sText : String) : WideString]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Function AsignarTextoVentanaExterna(const TituloVentana : String; const sText : String) : WideString;<br />
var<br />
hWindow : THandle;<br />
hChild  : THandle;</p>
<p>aTemp      : array[0..5000] of Char;<br />
sClassName : String;</p>
<p>ContElementos: integer;<br />
begin<br />
ContElementos := 0;<br />
Result := &#8221;;<br />
hWindow := FindWindow(Nil,PChar(TituloVentana));<br />
if hWindow = 0 then begin<br />
ShowMessage(&#8216;Error al intentar cargar la aplicaión. Intente otra vez.&#8217;);<br />
exit;<br />
end;</p>
<p>hChild := GetWindow(hWindow, GW_CHILD);<br />
while hChild &#60;&#62; 0 do Begin<br />
if GetClassName(hChild, aTemp, SizeOf(aTemp)) &#62; 0 then begin<br />
sClassName := StrPAS(aTemp);</p>
<p>if sClassName = &#8216;TEdit&#8217; then begin<br />
ContElementos := ContElementos + 1;<br />
case ContElementos of<br />
4: begin<br />
StrPCopy(aTemp,sText);<br />
SendMessage(hChild,WM_SETTEXT,SizeOf(aTemp),Integer(@aTemp));<br />
end;<br />
end;<br />
end;<br />
end;<br />
hChild := GetWindow(hChild, GW_HWNDNEXT);<br />
end;<br />
end;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[turbo pascal windows (no ms-dos)]]></title>
<link>http://programarenajax.wordpress.com/2009/09/03/turbo-pascal-windows-no-ms-dos/</link>
<pubDate>Thu, 03 Sep 2009 12:21:55 +0000</pubDate>
<dc:creator>admin</dc:creator>
<guid>http://programarenajax.wordpress.com/2009/09/03/turbo-pascal-windows-no-ms-dos/</guid>
<description><![CDATA[Para los que recién empiezan y no lo encuentran. bájenlo de acá: http://rapidshare.com/files/2750935]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Para los que recién empiezan y no lo encuentran. bájenlo de acá: <a href="http://rapidshare.com/files/275093545/TPW.rar.html">http://rapidshare.com/files/275093545/TPW.rar.html </a>password: <span style="color:#008000;">http://programarenajax.wordpress.com</span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[برنامج Borland Turbo C++ 4.5]]></title>
<link>http://ibraheemblog.wordpress.com/2009/09/03/%d8%a8%d8%b1%d9%86%d8%a7%d9%85%d8%ac-borland-turbo-c-4-5/</link>
<pubDate>Wed, 02 Sep 2009 21:29:20 +0000</pubDate>
<dc:creator>Ibraheem</dc:creator>
<guid>http://ibraheemblog.wordpress.com/2009/09/03/%d8%a8%d8%b1%d9%86%d8%a7%d9%85%d8%ac-borland-turbo-c-4-5/</guid>
<description><![CDATA[هاد برنامج  Borland Turbo C++ 4.5   مترجم (compiler ) للغة ++C بعد بحث طويل عن مترجم لهذه  اللغة نصح]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>هاد برنامج  Borland Turbo C++ 4.5   مترجم (compiler ) للغة ++C</p>
<p>بعد بحث طويل عن مترجم لهذه  اللغة نصحني البعض به فجربته و نال اعجابي لأنه قريب جدا من Turbo pascal الذي قضيت معه سنة دراسية كاملة كان فيها وفيا معي ( يعني ما في منوا ما عذبني ) &#8230;.</p>
<p>و فجأة  حصل ما لم يكن في الحسبان ضاع الـ CD المتضمن البرنامج و اضطررت الى تغير الهارد ديسك &#8230;&#8230;.</p>
<p>تجولت في محلات الكمبيوتر و ال CDs  باحثا عن هذا المترجم أو أي مترجم آخر لكن عبثا لم أجد أي شيء فالحمد الله كل مراكز بيع الـ CDs لا تحتوي الا الأغاني و الألعاب &#8230;</p>
<p>و فجأة وجدت نفسي أمام ++Microsoft Visual C  لم يعجبني هذا البرنامج كما أن التعامل معه بايخ و غليظ لذلك بدأت رحلة البحث عن مترجم آخر ..</p>
<p>لم يكن لدي أي وقت لذلك ما كان الي غير الانترنت غوغلت باحثا عن البرنامج ووجدت طلبي &#8230;.</p>
<p style="text-align:center;"><span style="color:#339966;">مواصفات البرنامج</span></p>
<p style="text-align:center;"><span style="color:#339966;"><!--more--><br />
</span></p>
<ul>
<li>نسخة الاصدار : Borland Turbo C++ 4.5</li>
</ul>
<ul>
<li>حجم الاصدار : 24 M.B  \* للتحميل من سورية بواسطة اتصال Dial up يلزمك تقريب الساعة و ثلاث أرباع الساعة .</li>
</ul>
<p>ملف التحميل مجلد مضغوط قم بفك الضغط ثم ابحث عن ملف  <span style="color:#ff0000;">INSTALL.EXE</span> لا تغلطوا و تروحوا على setup.exe &#8230;.  بعدين بتتبعوا خظوات التنصيب اذا ما عرفتوا ردولي خبر لاكتب المراحل ..</p>
<p><span style="color:#ff0000;"> يدعم الفيستا &#8230;.. هك قالولي مو مجربوا<br />
</span></p>
<p><a href="http://www.emasters.co.uk/userfiles/3803/Borland%20Turbo%20C++%204.5.rar"><img class="aligncenter" title="Download" src="http://uploads.bizhat.com/templates/images/download_btn.jpg" alt="" width="205" height="75" /></a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Lepiej późno niż wcale cz.2]]></title>
<link>http://kamillb.wordpress.com/2009/08/10/lepiej-pozno-niz-wcale-cz-2/</link>
<pubDate>Mon, 10 Aug 2009 18:10:27 +0000</pubDate>
<dc:creator>kamillb</dc:creator>
<guid>http://kamillb.wordpress.com/2009/08/10/lepiej-pozno-niz-wcale-cz-2/</guid>
<description><![CDATA[Kaleka beczy ,że od dawna nie pojawił się żadnej wpis a więc oto jest. &#8220;Grę&#8221; zacząłem pi]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Kaleka beczy ,że od dawna nie pojawił się żadnej wpis a więc oto jest. &#8220;Grę&#8221; zacząłem pisać kiedy w liceum przez dwa lata męczyli nas głupim Pascalem a zagadnienie pętli trwało 4 godziny lekcyjne(a powinno 4 minuty).</p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/7e35CIaJBNw&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/7e35CIaJBNw&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></p>
<p>Do pobrania w <a title="http://70719kt.p14.pl/" href="http://70719kt.p14.pl/"><strong>repozytorium</strong></a>.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Turbo Pascal]]></title>
<link>http://dhidhin.wordpress.com/2009/07/31/turbo-pascal/</link>
<pubDate>Fri, 31 Jul 2009 02:30:55 +0000</pubDate>
<dc:creator>Dhidhin Haris</dc:creator>
<guid>http://dhidhin.wordpress.com/2009/07/31/turbo-pascal/</guid>
<description><![CDATA[Bahasa Pascal merupakan salah satu bahasa pemrograman komputer yang sudah sangat lama, tapi sampe se]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Bahasa Pascal merupakan salah satu bahasa pemrograman komputer yang sudah sangat lama, tapi sampe sekarang masih banyak orang yang menggunakannya, terutama bagi yang baru mau masuk dunia pemrograman yaitu di sekolah-sekolah, terutama untuk memahami tentang algoritma pemroraman.</p>
<p>Untuk mempelajari bahasa Pascal ini, kita butuh software yang bisa kita pakai untuk menulis program pascal sekaligus untuk mengcompile file-nya. Software itu salah satunya adalah Turbo Pascal. Dibawah ini anda dapat mendownload software Turbo Pascal versi 7.0</p>
<p><a href="http://www.4shared.com/file/121849460/1244dce7/Turbo_Pascal_70.html" target="_blank">Download Turbo Pascal 70.zip</a></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Adventures In Game Development]]></title>
<link>http://ballpointgames.wordpress.com/2009/05/21/adventures-in-game-development/</link>
<pubDate>Thu, 21 May 2009 09:58:17 +0000</pubDate>
<dc:creator>ballpointgames</dc:creator>
<guid>http://ballpointgames.wordpress.com/2009/05/21/adventures-in-game-development/</guid>
<description><![CDATA[Initially I practiced game development with QBasic 1.0 on an 8086 and an 80286.  I ascended to Turbo]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Initially I practiced game development with QBasic 1.0 on an 8086 and an 80286.  I ascended to Turbo Pascal 6 on a 486.  This was using the borland graphics interface(BGI) library.  You can usually spot this library in play by the presence of a file named &#8220;egavga.bgi&#8221;.</p>
<p>I utilized some shareware or freeware &#8216;basic&#8217; compiler to put some of those QBasic games into a standalone executable form(.exe file).</p>
<p>Next up, from the internet I obtained DJGPP c++ along with ALLEGRO library and installed it on a dos-based 486-dx2 66mhz, and performed some sprite editing with a dos image editor.  Everything up to this point was dos-based game development.</p>
<p>Feeling the  lure of the intenet I tried making a game applet in Java but applets suck.  I had with me an academic version of Visual c++ 6 on CD but I lost it so I basically had to make do with &#8220;alternative freeware c++ stuff&#8221; until Visual Studio Express was released.  Thus I spent a long time using Borland c++ 5.5 command line tools as I introduced myself to WINAPI.</p>
<p>As I started learning about OpenGL I made a 3D Pong-clone, and a simple polygon car travelling around a simple polygonal terrain.</p>
<p>Of all this, much of it ended up lost as hard disks began to fail.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[¡Hola, mundo!]]></title>
<link>http://codigodelphi.wordpress.com/2009/04/28/hola-mundo/</link>
<pubDate>Wed, 29 Apr 2009 00:55:09 +0000</pubDate>
<dc:creator>marswalker</dc:creator>
<guid>http://codigodelphi.wordpress.com/2009/04/28/hola-mundo/</guid>
<description><![CDATA[program HelloWorld; uses crt; begin writeln(&#8216;Hello World!&#8217;); end. Te damos la bienvenida]]></description>
<content:encoded><![CDATA[program HelloWorld; uses crt; begin writeln(&#8216;Hello World!&#8217;); end. Te damos la bienvenida]]></content:encoded>
</item>
<item>
<title><![CDATA[Programista]]></title>
<link>http://kaemic.wordpress.com/2009/03/21/programista/</link>
<pubDate>Sat, 21 Mar 2009 16:00:43 +0000</pubDate>
<dc:creator>kaemic</dc:creator>
<guid>http://kaemic.wordpress.com/2009/03/21/programista/</guid>
<description><![CDATA[Witam was. Chciałbym poinformować o tym, że wystartowała moja nowa strona. Będę na niej umieszczać (]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Witam was. Chciałbym poinformować o tym, że wystartowała moja nowa strona. Będę na niej umieszczać (przeważnie) programy + kody źródłowe programów stworzonych przeze mnie w Turbo Pascalu. Będę sie starał by każdy z programów był IMP (Idiot-Mistake-Proof), ale nie gwarantuje, że każdy w 100%. Nie pozostaje mi nic innego jak serdecznie zaprosić was <em><strong><a title="Programownia Kaemica" href="http://www.kaemic.ovh.org/index.html" target="_blank">Tutaj</a></strong></em>. W ramach internacjonalizmu strona jest prowadzona po angielsku.</p>
<p>Póki co znajdują sie tam dwa programy, jeden do liczenia funkcji liniowej i drugi do liczenia największego wspólnego dzielnika (NWD) dwóch liczb z zastosowaniem (do wyboru) pierwszego oraz drugiego algorytmu Euklidesa.</p>
<p>Dyskordianie wszystkich krajów łączcie się! Hail Eris, powszechne Hail Discordia.</p>
<p><span style='text-align:center; display: block;'><object width='425' height='350'><param name='movie' value='http://www.youtube.com/v/rYg4DzivXe4&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' /><param name='allowfullscreen' value='true' /><param name='wmode' value='transparent' /><embed src='http://www.youtube.com/v/rYg4DzivXe4&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;hd=0' type='application/x-shockwave-flash' allowfullscreen='true' width='425' height='350' wmode='transparent'></embed></object></span></p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[UNS: Primer contacto]]></title>
<link>http://nosuccess.wordpress.com/2009/03/17/uns-primer-contacto/</link>
<pubDate>Tue, 17 Mar 2009 23:20:21 +0000</pubDate>
<dc:creator>damianponte</dc:creator>
<guid>http://nosuccess.wordpress.com/2009/03/17/uns-primer-contacto/</guid>
<description><![CDATA[¡Primera clase universitaria en la Universidad Nacional del Sur! Empezé a cursar la carrera de Licen]]></description>
<content:encoded><![CDATA[¡Primera clase universitaria en la Universidad Nacional del Sur! Empezé a cursar la carrera de Licen]]></content:encoded>
</item>
<item>
<title><![CDATA[Your Automatisms Betray You]]></title>
<link>http://hbfs.wordpress.com/2009/03/11/your-automatisms-betray-you/</link>
<pubDate>Wed, 11 Mar 2009 12:32:51 +0000</pubDate>
<dc:creator>Steven Pigeon</dc:creator>
<guid>http://hbfs.wordpress.com/2009/03/11/your-automatisms-betray-you/</guid>
<description><![CDATA[Yesterday someone dropped on the IRC channel where my fellow programmers, computer enthusiasts, and ]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Yesterday someone dropped on the IRC channel where my fellow programmers, computer enthusiasts, and I hang out to get help to find a bug. He uses one of the paste sites (like <a href="http://pastebin.ca" target="_blank">pastebin.ca</a>,  <a href="http://pastebin.com" target="_blank">pastebin.com</a>, or <a href="http://www.rafb.net/paste/" target="_blank">rafb.net</a>), pastes his piece of offending code, and so we get a look at the code. Of course, I go over the short program, notice a mistake in the <tt>scanf</tt> but it took me a full two minutes to notice the loop:</p>
<pre class="brush: cpp;">
for (c=0; c++; c&lt;n)
 {
   ...
 }
</pre>
<p>That kind of bug always takes a while to find because <em>we don&#8217;t read what&#8217;s actually written, but what we think is written</em>, unless we pay the utmost attention to the code&#8212;what we should be doing anyway, but do not always. Usually, you zero in on that kind of bug rapidly, as you guide your search from the bug&#8217;s symptoms which leads you to defect&#8217;s approximate location. If you&#8217;re like me&#8212;write a little, test a lot&#8212;you find those bugs right away most of the times. However, even if you zero in rapidly, you still get a coarse-grained location: module, class, function.</p>
<p><!--more--></p>
<p>However, that particular type of error does not happen very often to programmers with a good level of experience with a given programming language (in this case, <a href="http://en.wikipedia.org/wiki/C_(programming_language)" target="_blank">C</a>) because programmers rapidly develop <a href="http://en.wikipedia.org/wiki/Automatic_behavior" target="_blank">automatisms</a> that protects them from such mistakes. First, that is because they know the language well enough to know the order of the statements within a <tt>for</tt> about as well as they now how to ride a bicycle; second, because their automatisms make them write statements in the right order, even though they might not master a particular statement or do not fully understand the semantics.</p>
<p>Such automatisms&#8212;surely decried by &#8220;hot&#8221; programmers&#8212;are not bad. They generally help code reliability because the programmers always use the same kind of constructs that they are used of getting right. But automatisms have their down side. Not only may they limit the creativity of programmers by confining them to their own safe <em>Terra Cognita</em>, keeping them from stretching their envelope and getting better, they may also, and maybe more fundamentally, corrupt the way they are thinking about programming.</p>
<p>Indeed, if a programmer brings his functional-language automatisms with him while coding in C, he may be in big trouble. First, many of the natural functional language constructs make no sense whatsoever in C or C++, either because they are against the language general conceptual style, or because they cannot be implemented efficiently&#160;<sup>1</sup>. In other words, your automatisms, mostly unbeknownst to you, may prevent you from being totally immersed into the current programming language&#8212;therefore from writing really good code. You know what I&#8217;m talking about. Have you ever seen a C++ program that reeks of minimally translated <a href="http://en.wikipedia.org/wiki/Fortran" target="_blank">Fortran</a> but yet was really first written in C++?</p>
<p>Of course you do.</p>
<p align="center">*<br />
*&#8195;*</p>
<p>You know, your old automatisms may haunt you a long time. I used to program in (<a href="http://en.wikipedia.org/wiki/Turbo_Pascal" target="_blank">Turbo</a>) <a href="http://en.wikipedia.org/wiki/Pascal_(programming_language)">Pascal</a> quite a lot before I turned to C and eventually C++. The last time I wrote a large Pascal program must have been in 2002 or so, then again it was <a href="http://en.wikipedia.org/wiki/Object_Pascal" target="_blank">Delphi</a>, which is still better. Yet, I still surprise myself writing <tt>:=</tt> in a C program, or spend a few minute understanding why the compiler complains about <tt>while (cond) do { }</tt>.</p>
<hr align="left" width="30%">
<sup>1</sup>&#160;Efficient implementation may mean that the implementation is computationally efficient (it is fast, requires little memory, etc.) or that it requires little code. Fast and frugal code is dogma to C programmers, so a construction that is inherently inefficient will be frown upon even though it may well be what it actually takes. The size of the source code required to implement some functional-style construct is truly enormous in C and C++, which aren&#8217;t functionnal languages. Enormous quantity of code to perform tasks that could be performed differently using at lot less code cannot be considered &#8220;efficient&#8221; programming.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[ModuL praktikum PK...]]></title>
<link>http://wasisadi.wordpress.com/2009/03/05/modul-praktikum-pk/</link>
<pubDate>Thu, 05 Mar 2009 14:56:04 +0000</pubDate>
<dc:creator>wasisadi</dc:creator>
<guid>http://wasisadi.wordpress.com/2009/03/05/modul-praktikum-pk/</guid>
<description><![CDATA[d bLog ne dah q upLoad moduL praktikum PK tuk anak2 matematika 2008&#8230;dah q print k pdf, silahka]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>d bLog ne dah q upLoad moduL praktikum PK tuk anak2 matematika 2008&#8230;dah q print k pdf, silahkan downLoad d woLf&#8217;s box, d kanan bawah, yang warnanya biru&#8230;tuk sementara ne, yang d upLoad cukup 4 duLu&#8230;</p>
<p><!--more--></p>
<p>sebenere, q mw nulis dikit2, tuk mereview praktikum yg sudah2&#8230;tp q dah ngatuk, dan q jg msh punya tugas yang harus q selesaikan&#8230;jd, Laen kaLi ja y&#8230;</p>
<p>tuk sementara ne, bLajar sendiri dL&#8230;pesenQ, kLo praktikum jangan maLah bengong&#8230;d coba2, gt&#8230;pahami ap yang kaLian ketikkan&#8230;</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Comando de repetição REPEAT]]></title>
<link>http://entendendo.wordpress.com/2008/12/04/comando-de-repeticao-repeat/</link>
<pubDate>Thu, 04 Dec 2008 11:09:24 +0000</pubDate>
<dc:creator>entendendo</dc:creator>
<guid>http://entendendo.wordpress.com/2008/12/04/comando-de-repeticao-repeat/</guid>
<description><![CDATA[O comando REPEAT é usado para repetir uma ou mais vezes enquanto a expressão for contemplada.   Exem]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;">O comando REPEAT é usado para repetir uma ou mais vezes enquanto a expressão for contemplada.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;">Exemplo:</p>
<p>Código pascal</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;">BEGIN</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><strong><span style="font-family:Verdana;">Repeat</span></strong><span style="color:black;font-family:Verdana;"> <span> </span></span><span style="color:#99cc00;font-family:Verdana;">{</span></span><span style="font-size:10pt;color:#99cc00;font-family:Verdana;">Irá repetir tudo que estiver abaixo do REPEAT e antes do UNTIL}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:10pt;color:black;font-family:Verdana;"> </span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"><span>   </span>Write(‘Digite a palavra TESTE =&#62; ‘);</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"><span>  </span><span> </span>Readln(palavra);</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="font-size:small;"><strong><span style="font-family:Verdana;">Until</span></strong><span style="color:black;font-family:Verdana;"> (Palavra = ‘TESTE’); </span></span><span style="font-size:10pt;color:#99cc00;font-family:Verdana;">{ UNTIL é aonde fica a condição do REPEAT, no caso irá repetir até que palavra seja igual a TESTE}</span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;">END.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> </span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;">O programa irá REPETIR ATÉ QUE o usuário digite a palavra TESTE, se ele não digitar TESTE a pergunta ficará se repetindo para ele.</span></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"></span></p>
<p class="MsoNormal" style="margin:0;"><span style="color:black;font-family:Verdana;"><span style="font-size:small;"> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </span></span></p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
