473,566 Members | 2,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Graphics program to sort lines

lifeisgreat20009
70 New Member
I want to make a "GRAPHICS PROGRAM" in C language that shows sorting of lines. Something like this:-

------------
-------------------

------

------------------------------------

after sorting the lines should appear as follows on the screen :-

-------
-----------------
---------------------
--------------------------------------

NOTE :- The lines are to be drawn using line() function. also the lines are to be sorted using quick sort algorithm.

Any help would be greatly appreciated.
Thanks !!!!!


I have tried it but it fails to work . The code is below !!!!!!

Expand|Select|Wrap|Line Numbers
  1. #include <graphics.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <conio.h>
  5.  
  6. int main(void)
  7. {
  8.    /* request auto detection */
  9.    int gdriver = DETECT, gmode, errorcode;
  10.  
  11.    int x1=50,y1=50,x2=100,y2=50,x3=70,y3=70,x4=150,y4=70;
  12.    int x5=30,y5=90,x6=50,y6=90,i,l[3],temp,midx,midy;
  13.  
  14.  
  15.  
  16.    /* initialize graphics and local variables */
  17.    initgraph(&gdriver, &gmode, "");
  18.  
  19.    /* read result of initialization */
  20.    errorcode = graphresult();
  21.    /* an error occurred */
  22.    if (errorcode != grOk)
  23.    {
  24.       printf("Graphics error: %s\n", grapherrormsg(errorcode));
  25.       printf("Press any key to halt:");
  26.       getch();
  27.       exit(1);
  28.    }
  29.    midx=getmaxx()/2;
  30.    midy=getmaxy()/2;
  31.    outtextxy(midx-50,10,"UNSORTED LINES");
  32.    outtextxy(midx-50,midy-130,"SORTED LINES");
  33.    line(0,0,getmaxx(),0);
  34.     line(getmaxx(),0,getmaxx(),getmaxy());
  35.     line(getmaxx(),getmaxy(),0,getmaxy());
  36.     line(0,0,0,getmaxy());
  37.  
  38.    setcolor('5');
  39.    line(x1,y1,x2,y2);
  40.    line(x3,y3,x4,y4);
  41.    line(x5,y5,x6,y6);
  42.  
  43.    l[0]=x2-x1;
  44.    l[1]=x4-x3;
  45.    l[2]=x6-x5;
  46.    delay(1000);
  47.    for(i=0;i<=2;i++)
  48.    {
  49.    if(l[i]>l[i+1])
  50.    {
  51.    temp=l[i];
  52.    l[i]=l[i+1];
  53.    l[i+1]=temp;
  54.  
  55.    }  }        delay(1000);
  56.  
  57.    line(x1,y1+110,l[0]+x1,y1+110); delay(1000);
  58.    line(x1,y1+130,l[1]+x1,y1+130);   delay(1000);
  59.    line(x1,y1+150,l[2]+x1,y1+150);
  60.  
  61.  
  62.    getch();
  63.    closegraph();
  64.    return 0;
  65. }
Oct 15 '07 #1
1 1727
weaknessforcats
9,208 Recognized Expert Moderator Expert
You could save yourself a lot of trouble by just looking at each integer and displaying dashes corresponding to the integer value.

That is, if it contains 5, you display - - - - - followed by a newline.
Oct 15 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3752
by: frank | last post by:
Hi all I don't think this is strictly a Python problem, but as it manifests itself in one of my Python programs, I am hoping that somebody in this group can help me. The following is a message I sent to co.os.linux.setup - "My question concerns line graphics on a text-based console. ­My actual problem relates to a program I have...
8
12263
by: Mark Johnson | last post by:
Using: VS 2003 NET C# for Framework and Framework Compact Trying : Moving a Card (Bitmap) as in Solitare (PC + WinCe) Version on OnMouseMove Problem : The affected drawing Area by Invalidate (or Invalidate(Rectangle)) flickers in a nasty way when repainting. This does not happen in the Solitare (PC + WinCe) Versions a well as in a Card...
10
1921
by: Galen Somerville | last post by:
Going from VB6 (RAD) to VB2005 (SAD) The documentation always shows graphics drawing in a paint event like Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _ As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint End Sub But my VB6 program draws to the picturebox PictColor from many different
11
1991
by: Ground21 | last post by:
Hello. I'm new // sorry for my english :) I have to write simple program i c++. But I don't know how to code src - program should know it's name (unit1.exe so the name is "unit1" or "unit1.exe" and it's full path (with volume name - c:\programs). Which commends of c++ should I use? (please do not redirect me to 'help', because I must...
12
3573
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet utilities that allows you to view them with live rotation in a web browser. Also, it includes a introductory tutorial to POV-Ray.
5
6615
by: tomy | last post by:
Hi All I am a newbie to turtle graphics in python, so sorry if you find this question too easy. How can I get smoother lines in turtle graphics? I am using python on windows. Thanks in advance
6
2667
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the string into multiple lines. Is there a way to find out into how many lines the string was split? I am asking because this string is being...
0
3003
by: raylopez99 | last post by:
Hi, I'm getting into GDI+ Forms 2.0 graphics for C#3 using Visual Studio 2008. One thing I notice: the graphics are really slow and flicker on a Pentium IV, with 2 GB RAM, even with doublebuffering turned on. I did learn tricks such as not invalidating everything, but just the control that is part of the form you are working on (i.e.,
4
5312
by: slapsh0t11 | last post by:
Hello! I need help with a program that I believe I am nearly done with. However, there seems to be a few details that preclude me from success. Here is my assignment: Here is my class file (Sorts.java): import java.util.*; /**
0
7673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7584
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1202
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
926
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.