Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Colombo
Red Hat Certified System Administrator (RHCSA) - RHEL 10
Sanjeewani95
Updated:
Friday at 7:43 PM
NURSING , CAREGIVER , HOTEL & BEAUTY COURSES
IVA Para Medical Campus
Updated:
Thursday at 9:24 AM
Handmade Character Soft Toys Peppa Pig Family
anil1961
Updated:
Wednesday at 9:58 PM
Ad icon
Video Content Creator
pramukag
Updated:
Jun 28, 2026
Ad icon
QA Engineer Intern
pramukag
Updated:
Jun 28, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
Education
Thread for Programming and Realeted Topics
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="madurax86" data-source="post: 5599945" data-attributes="member: 1293"><p>This is how you use it,</p><p>the example is done to get you started with out trouble</p><p>* the numbers in yellow show the steps in which the coordinates are entered to the program</p><p>recommended way of entering coordinates is "4 5" (without "") if you want to enter the coordinate (4,5)</p><p>* numbers in red gives the limits of the default console dialog </p><p>* numbers in white are the ones you need to enter *according to the steps* inorder to draw the picture shown in the image</p><p></p><p><img src="http://img503.imageshack.us/img503/3572/zzsd.jpg" alt="" class="fr-fic fr-dii fr-draggable " style="" /></p><p><a href="http://img80.imageshack.us/img80/3760/26002081.jpg" target="_blank">Screenshot</a></p><p></p><p>AND REPORT ERRORS/BUGS IF YOU FIND ANY <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /> </p><p>TRY TO FIX THEM TOO!</p><p>[code]</p><p>#include <cstdlib></p><p>#include <iostream></p><p>#include <windows.h></p><p>#include <math.h></p><p></p><p>using namespace std;</p><p></p><p>void gotoxy(int x, int y)</p><p>{</p><p> COORD coord;</p><p> coord.X = x;</p><p> coord.Y = y;</p><p> SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);</p><p>}</p><p>float round(float n,int place)// taken from http://forums.devshed.com/c-programming-42/round-up-a-decimal-number-in-c-69908.html</p><p>{</p><p> float d;</p><p> int i;</p><p> /* rescale 123.45678 to 12345.678 */</p><p> d = n * pow(10,place);</p><p> /* round off: 12345.678 + 0.5 = 12346.178 -> 12346 */</p><p> i = d + 0.5;</p><p> /* restore to its original scale: 12346 -> 123.46 */</p><p> d = (float)i / pow(10,place);</p><p></p><p> return d;</p><p>}</p><p></p><p>int DrawLine(COORD p1,COORD p2)</p><p>{</p><p> int i,j,w,h,iStart,iEnd;</p><p> short k,l;</p><p> //p1 should be on the left of p2</p><p> if (p1.X>p2.X){</p><p> k=p2.X;</p><p> l=p2.Y;</p><p> p2.X=p1.X;</p><p> p2.Y=p1.Y;</p><p> p1.X=k;</p><p> p1.Y=l;</p><p> }</p><p> double c,r;</p><p> h=abs(p1.Y-p2.Y);</p><p> w=abs(p1.X-p2.X);</p><p> </p><p> iStart=p1.X; //set all to defaults</p><p> iEnd=0;</p><p> gotoxy(0,0); </p><p> if ((h==0) || (w==0))</p><p> {</p><p> if (h==0) {</p><p> for (i=0;i<=w;i++){</p><p> gotoxy(i+p1.X,p1.Y);</p><p> cout<<"*";</p><p> }</p><p> goto end;</p><p> }</p><p> if (w==0) {</p><p> if (p1.Y>p2.Y){</p><p> for (j=0;j<=h;j++){</p><p> gotoxy(p1.X,p1.Y-j);</p><p> cout<<"*";</p><p> }</p><p> goto end;</p><p> }</p><p> else</p><p> {</p><p> for (j=0;j<=h;j++){</p><p> gotoxy(p1.X,p1.Y+j);</p><p> cout<<"*";</p><p> }</p><p> goto end;</p><p> }</p><p> }</p><p> }</p><p> else</p><p> {</p><p> r=h%w;</p><p> r=r/w;</p><p> c=round(h/w,0);</p><p> if (p1.Y>p2.Y){</p><p> for (i=0;i<=w;i++){</p><p> iStart=iEnd;</p><p> iEnd=-(int)(c*(i+1) + r*i);</p><p> if (i==w){</p><p> iStart=iEnd;</p><p> iEnd=h;</p><p> }</p><p> for (j=iStart;j>=iEnd;j--){</p><p> gotoxy(i+p1.X,j+p1.Y);</p><p> cout<<"*";</p><p> }</p><p> }</p><p> }</p><p> else</p><p> {</p><p> for (i=0;i<=w;i++){</p><p> iStart=iEnd;</p><p> iEnd=(int)(c*(i+1) + r*i);</p><p> if (i==w){</p><p> iStart=iEnd;</p><p> iEnd=h;</p><p> }</p><p> for (j=iStart;j<=iEnd;j++){</p><p> gotoxy(i+p1.X,j+p1.Y);</p><p> cout<<"*";</p><p> }</p><p> }</p><p> }</p><p> }</p><p> end:</p><p> return 0;</p><p>}</p><p>main()</p><p>{</p><p> int t;</p><p> COORD p1,p2,p3;</p><p> t=1;</p><p> cout<<"Enter 1st point : ";</p><p> cin>>p1.X>>p1.Y;</p><p> system("CLS");</p><p> p3=p1;</p><p> while (t=1){</p><p> gotoxy(0,0);</p><p> cout<<" ";</p><p> gotoxy(0,0);</p><p> cout<<"("<<p3.X<<","<<p3.Y<<")"<<"Enter next point : ";</p><p> cin>>p2.X>>p2.Y;</p><p> p3=p2;</p><p> DrawLine(p1,p2);</p><p> p1=p3;</p><p> }</p><p>}</p><p></p><p>[/code]</p></blockquote><p></p>
[QUOTE="madurax86, post: 5599945, member: 1293"] This is how you use it, the example is done to get you started with out trouble * the numbers in yellow show the steps in which the coordinates are entered to the program recommended way of entering coordinates is "4 5" (without "") if you want to enter the coordinate (4,5) * numbers in red gives the limits of the default console dialog * numbers in white are the ones you need to enter *according to the steps* inorder to draw the picture shown in the image [IMG]http://img503.imageshack.us/img503/3572/zzsd.jpg[/IMG] [URL="http://img80.imageshack.us/img80/3760/26002081.jpg"]Screenshot[/URL] AND REPORT ERRORS/BUGS IF YOU FIND ANY :D TRY TO FIX THEM TOO! [code] #include <cstdlib> #include <iostream> #include <windows.h> #include <math.h> using namespace std; void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } float round(float n,int place)// taken from http://forums.devshed.com/c-programming-42/round-up-a-decimal-number-in-c-69908.html { float d; int i; /* rescale 123.45678 to 12345.678 */ d = n * pow(10,place); /* round off: 12345.678 + 0.5 = 12346.178 -> 12346 */ i = d + 0.5; /* restore to its original scale: 12346 -> 123.46 */ d = (float)i / pow(10,place); return d; } int DrawLine(COORD p1,COORD p2) { int i,j,w,h,iStart,iEnd; short k,l; //p1 should be on the left of p2 if (p1.X>p2.X){ k=p2.X; l=p2.Y; p2.X=p1.X; p2.Y=p1.Y; p1.X=k; p1.Y=l; } double c,r; h=abs(p1.Y-p2.Y); w=abs(p1.X-p2.X); iStart=p1.X; //set all to defaults iEnd=0; gotoxy(0,0); if ((h==0) || (w==0)) { if (h==0) { for (i=0;i<=w;i++){ gotoxy(i+p1.X,p1.Y); cout<<"*"; } goto end; } if (w==0) { if (p1.Y>p2.Y){ for (j=0;j<=h;j++){ gotoxy(p1.X,p1.Y-j); cout<<"*"; } goto end; } else { for (j=0;j<=h;j++){ gotoxy(p1.X,p1.Y+j); cout<<"*"; } goto end; } } } else { r=h%w; r=r/w; c=round(h/w,0); if (p1.Y>p2.Y){ for (i=0;i<=w;i++){ iStart=iEnd; iEnd=-(int)(c*(i+1) + r*i); if (i==w){ iStart=iEnd; iEnd=h; } for (j=iStart;j>=iEnd;j--){ gotoxy(i+p1.X,j+p1.Y); cout<<"*"; } } } else { for (i=0;i<=w;i++){ iStart=iEnd; iEnd=(int)(c*(i+1) + r*i); if (i==w){ iStart=iEnd; iEnd=h; } for (j=iStart;j<=iEnd;j++){ gotoxy(i+p1.X,j+p1.Y); cout<<"*"; } } } } end: return 0; } main() { int t; COORD p1,p2,p3; t=1; cout<<"Enter 1st point : "; cin>>p1.X>>p1.Y; system("CLS"); p3=p1; while (t=1){ gotoxy(0,0); cout<<" "; gotoxy(0,0); cout<<"("<<p3.X<<","<<p3.Y<<")"<<"Enter next point : "; cin>>p2.X>>p2.Y; p3=p2; DrawLine(p1,p2); p1=p3; } } [/code] [/QUOTE]
Insert quotes…
Verification
Winadiyakata thappara keeyak tibeda?
Post reply
Top
Bottom