Weekly Qbasic and Qb64 Lesson Topics
April 18, 2024, 10:40:37 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

A new Idea For Friends

Pages: [1]
  Print  
Author Topic: A new Idea For Friends  (Read 328 times)
ChatKing
Post Demos
*
Posts: 23


« on: November 26, 2011, 10:30:38 am »

Hi, Friends

I have written some code after testing it comment about it and I have also an idea, if anybody can write code about it.

First my code:-

Code:
_FULLSCREEN

DIM n(15) AS STRING
DIM a AS INTEGER
DIM b AS INTEGER

CLS
PRINT STRING$(79, "-")
PRINT "Sr.No"; TAB(8); "Original"; TAB(30); "Ascending"; TAB(50); "Descending"
PRINT STRING$(79, "-")
FOR a = 1 TO 15
    LOCATE a + 3, 1
    PRINT a
    LOCATE a + 3, 8
    INPUT "", n(a)
NEXT a

REM Ascending Order

FOR a = 1 TO 15
    FOR b = 1 TO 14
        IF n(b) > n(b + 1) THEN SWAP n(b), n(b + 1)
    NEXT
NEXT

REM Print Ascending Order

FOR a = 1 TO 15
    LOCATE a + 3, 30
    PRINT n(a)
NEXT

REM Descending Order

FOR a = 1 TO 15
    FOR b = 1 TO 14
        IF n(b) < n(b + 1) THEN SWAP n(b), n(b + 1)
    NEXT
NEXT

REM Print Decending Order

FOR a = 1 TO 15
    LOCATE a + 3, 50
    PRINT n(a)
NEXT

PRINT STRING$(79, "-")

SLEEP

SYSTEM

Now the Idea

In this code I tried to input and display the the contents of array in both ascending as well as descending order on same screen, but all this is done first the contents are inputted and then displayed in ascending and descending order how it can be done then when the first item of content is inputted at that time the same is displayed in ascending order and then in descending order similarly when the second content is inputted the first and second contents of array are checked and then displayed in both ascending as well as descending order accordingly and then so on until last item is inputted.

The Example is as below

Upon First Input

Sr. No     Order                  Ascending                Descending
1           Bob                     Bob                         Bob

Upon Second Input

Sr. No     Order                  Ascending                Descending
1            Bob                    Allan                       Bob
2            Allan                   Bob                        Allan

Upon Third input

Sr. No     Order                  Ascending                Descending
1            Bob                    Allan                       Carl
2            Allan                   Bob                        Bob
3            Carl                    Carl                        Allan

and this process continue until last item.

I am waiting for the code from all friends.

Thanks
ChatKing
Report Spam   Logged

Share on Facebook Share on Twitter

ChatKing
Post Demos
*
Posts: 23


« Reply #1 on: November 26, 2011, 01:36:11 pm »

Aha, I have done it, this is great for me, lol

Please must comment on my this effort, I will be waiting

Code:
_FULLSCREEN

DIM SHARED n(15) AS STRING
DIM SHARED an(15) AS STRING

DIM SHARED a AS INTEGER
DIM SHARED b AS INTEGER
DIM SHARED c AS INTEGER

CLS
PRINT STRING$(79, "-")
PRINT "Sr.No"; TAB(8); "Order"; TAB(30); "Ascending"; TAB(50); "Descending"
PRINT STRING$(79, "-")
FOR a = 1 TO 15
    LOCATE a + 3, 1: PRINT a
    LOCATE a + 3, 8: INPUT "", n(a)
    Ascending
    Descending
NEXT
PRINT STRING$(79, "-")
SLEEP
SYSTEM

'-----------------------------------------------------------------------------------------------
SUB Ascending
FOR b = 1 TO a
    an(b) = n(b)
NEXT
FOR b = 1 TO a
    FOR c = 1 TO a - 1
        IF an(c) > an(c + 1) THEN SWAP an(c), an(c + 1)
    NEXT
NEXT

FOR b = 1 TO a
    LOCATE b + 3, 30
    PRINT SPACE$(20)
    LOCATE b + 3, 30
    PRINT an(b)
NEXT
END SUB
'-----------------------------------------------------------------------------------------------
SUB Descending
FOR b = 1 TO a
    an(b) = n(b)
NEXT
FOR b = 1 TO a
    FOR c = 1 TO a - 1
        IF an(c) < an(c + 1) THEN SWAP an(c), an(c + 1)
    NEXT
NEXT

FOR b = 1 TO a
    LOCATE b + 3, 50
    PRINT SPACE$(30)
    LOCATE b + 3, 50
    PRINT an(b)
NEXT

END SUB
Report Spam   Logged
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« Reply #2 on: November 27, 2011, 07:28:04 am »

Thats good, especially, that you got it worked out, on another forum, slightly different sofware,
the user has the option, to display the topics, in ascending or descending order,
from Garry
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy