Kaun Banega Crorepati, a small executable program developed in QBASIC

Download the executible Kaun Banega Crorepati game.
Download Links:

   KBC Game Executable Program

This is small fun sort of game based on the concept of KBC, a famous tv reality show in Startplus.
This program is very simple but if you have really work hard then you can work on the source code of this game and make it more interesting and perfect.
You can work on following grounds to make this program more realistic-
 - integrate data file
 - make administrative screen for feeding questions
 - make question appears random
and more...
All you can with QBASIC code easily.
Ya you can explore your knowledge and test your creativity of programming.
I hope this project will provide you source of motivation of in QBASIC programming.
This project is very well-suited to the SLC candidates of Nepal.

You can work on it.
So, download your free source-code of this KBC game.
Download Link:
 
   KBC Game Source Code

Simple Calculator more than you expect from school teacher!!!

Please click below to obtain (download) source program file.
Open that file is QBASIC.
.Download Link is:
download calculator.bas files
This program looks like simple desktop calculator, ya you can't use mouse, though numeric keypads will work well to do calculations. See how is this calculator functions. I have made the coding as simple as possible so that you can follow the code and understand it easily.
If you want do more scientific calculations, you may try yourself at home. It will be fun to do programming, believe me.
Enjoy your programming.

Procedural vs. Object-Oriented

Lets understand the basic difference between Procedural

Programming Paradigm and Object-Oriented Programming

Paradigm.

QBASIC MATRIX

This program in QBASIC simple. This program displays the

matrix code which is similar to shown in the movie "MATRIX" .

Lecture 1 | Programming Paradigms 1 (Stanford)


Understand Programming Paradigm

Introduction to Procedural Programming - Part III

In this post I will discuss "How To" Procedular Programming.
Lets begin.
We know that programming is logical arrangement of statements (code) targed to obtain certain goal. Every code (statement) except to non-executable are meant to perform certain action. In procedural programming we will segment (divide) these blocks into several manageable parts (procedures/sub-program). For example, a problem of testing where a number is prime, we will write around 7-8 lines code of program; we can think this problem in procedural way- first there is need of a procedure which accepts a input number and second the number is passed  in another procedure which operates number in testing whether number is prime and returns result then finally there is a need of third procedure which will provide the result (output) to the user.
Here students may find little difficult or misleading or may think in different way. I want to aware you that how would you segment programs into several procedure depends I don't say you will be wrong; ya in the beginning it may be little confusion, but not get overloaded. Slowly with revisions and illustration programs you will finally grab the concepts and then onward it will be habitual.
Lets take a look on above illustration in the form of program (if you don't understand program don't get upset; only try to catch concept of procedures):

Program: testing whether number is prime (structure program- no procedures)
CLS
REM asking user to input a number to test for prime
INPUT "Enter a testing number"; n
REM test whether number is prime; set flag f to 1 (we first assume that n is prime)
f=1
FOR i=2 TO n/2
  IF n mod i=0 THEN f=0 : EXIT FOR
NEXT i
REM check value of f to decide prime/composite and display result to the user
IF f=1 THEN
  PRINT n;" is Prime Number!"
ELSE
  PRINT n; " is Composite Number!"
ENDIF
END

Program: testing whether number is prime (Procedural - 1 sub-routines and 2 function)
[Here. ACCEPT function askes testing number and returns to module (calling program)
 ISPRIME function with a value passed through parameter returns 1 if the value is prime
 DISPLAY sub-routine will display the result on the screen]
DECLARE FUNCTION accept()
DECLARE FUNCTION isPrime(num)
DECLARE SUB display(testnum, result)
CLS
v=accept
REM isPrime function is invoked then its return is passed to the display (see more-Functional Operator)
CALL display(v, isPrime(v))
END

FUNCTION accept
INPUT "Enter a testing number="; n
accept=n
END FUNCTION

FUNCTION isPrime(num)
f=1
FOR i=2 TO num/2
  IF num MOD i=0 THEN f=0 : EXIT FOR
NEXT i
isPrime=f
END FUNCTION

SUB display(testnum, result)
IF result=1 THEN
  PRINT testnum;" is Prime!"
ELSE
 PRINT testnum;" is Composite!"
ENDIF
END SUB

For more see upcoming post.
Best wishes!!!

Introduction to Procedural Programming in QBASIC - Part II

In my last post I had briefly discussed about procedure programming. Hope that might have enlightened your knowledge of Procedural Programming in QBASIC. Today I will discuss, its significance, need and benefits.
I would like to start with a very popular verse, "Divide and Conquer"- this was practised by British Empire in 19th and 20th century; you might have learned in History. We know this didn't sustain British Empire but believe me when you practice this in programming (viz. are procedural or modular programming approach) you will feel more comport in writing larger size program after you understand and learn the technique.

With the advent of development and progress in the technology; faster and high-end processors development made developer think larger problems to be solved through programming. When such time came then structure programming failed and brought new difficulties in writing larger sized programs. There were lots of hards like complexities in debugging, repetition of codes, unmanageable codes, unnecessary growth in size of programs and primarily non-integrity codes were the major problems. There was also need of newer methodology of programming and mean time new dimension in the field of programming was introduced i.e. Procedural Programming Approach (often considered as modular programming in general words but keep it in mind the module (modular) and procedure (procedural) are different in the context of QBASIC. Procedure is small-size division whereas as Module is large-size division but both of them are division of blocks of code into very manageable form).
A whole program is breaked (synthesized) into manageable small segments (procedures/subprogram) either functions or sub-routine procedures according to need so that there is reusability of these procedures. From this line importance of procedures can be easily estimated. Let us outline these importance or benefits of procedure (procedural) programming approach:
  (i) Manageable size of code from division into several segments
  (ii) Reusability of codes which reduces size of program by significantly reducing lines of codes without  degrading performance rather optimizing performance.
  (iii) Higher integrity in the codes as there is nearly zero repetition of same set of codes
  (iv) Larger sized programs easy to develop, debug and maintain.

Though this is not enough so many new paradigm of programming are introduced recently and pracised worldwidely but you can say they follow procedural approach with futher enhancements and features.

At last but not least we must admit that procedural programming paved a strong cornerstone in the field of programming.

Hope you enjoyed reading this post. In next post you can find terms and terminologies, statements and functions of QBASIC associated with procedural programming and also how to write procedure programs.

Till then bye. Have a good time!!!

Introduction to Procedural Programming - Part I

Writing Procedural Programs in QBASIC is simple. First lets understand what do you mean by procedural programs, what is benefit of it, why is it necessary in programming, its significance and how to all will be discussed in brief. You need to follow futher in the school text book. If anything like to know more from me please write to me.
Lets start.
Procedural word comes from procedure that means "set of steps to carryout some task". Ofcourse procedural programming is a such a tactics (approach) of write programs where we will divide our whole problem (program) manageably into many procedures that will be invoked (called) at the time of need in program to perform task as per required.
From above you might notice there are two aspects (components) in the procedural programming (programs) that are: (i) calling program and (ii) called program
Lets be clear about these two aspects first.
(i) What is calling program?
-> Basically the module program or sometime procedure (sub-program) itself may call another sub-program (procedure) or say pass control to it, such program is called calling program. Subroutines are called using optional statement "Call" and functions are invoked simply by using the function name either with "Print statement" or Assignment (Optional LET statement).
In other word we can also say that program from where subroutine is called or function is invoked is regarded as "Calling Program".
(ii) What is called program?
-> The subroutine or function (also say sub-program/procedure) that is called or invoked are regarded as "Called Program". Subroutine is enclosed within SUB...END SUB statements and Function is enclosed within FUNCTION...END FUNCTION statement. One more point to be noted that there is another kind of user defined function as well which resides in the module only cannot be allocated as seperate procedure that is DEF  FN... END DEF statement.

In the next post I will distinguish between SUB and FUNCTION and FUNCTION and DEF FN.
Before please check your text book to get into futher topics. It will be very helpful to understand futher.

Be patient and revise again and again to you can grab the discussions here.

Good Luck.
Have a fun. Enjoy your time with your friends.

Counting vowels in the given string using User Defined Functions

DECLARE FUNCTION countvow(s$)
CLS
INPUT "Enter testing string=";v$
PRINT "Number of vowels=";countvow(v$)
END

FUNCTION countvow(s$)
FOR i=1 TO LEN(s$)
  ch$=LCASE$(MID$(s$, i, 1))
  SELECT CASE ch$
  CASE "a", "e", "i", "o", "u"
     cnt=cnt+1
  END SELECT
NEXT i
countvow=cnt
END FUNCTION

Generate Fibonacci series using Sub Routine

REM a, b, n parameters represents first term, second term and number of terms respectively
DECLARE SUB fibo(a, b, n)
CLS
INPUT "First Term="; x
INPUT "Second Term=";y
REM label number is for data validation that length of terms must be less or equal to 20
10:
INPUT "How many terms="; z
IF z>20 THEN 10
CALL fibo(x, y, z)
END


SUB fibo(a, b, n)
PRINT a, b,
REM first two terms are already printed so started from 3
FOR I = 3 to n
  s=a+b
  PRINT s,
  a=b
  b=s
NEXT I
END SUB

Sum of digits of a number using User Defined Function (UDF)

DECLARE FUNCTION digitsum(n)
CLS
INPUT "Enter testing number=";v
PRINT "Sum of ";n;" is "; digitsum(v)
END

FUNCTION digitsum(n)
a=n
WHILE NOT a=0        'writing NOT a=0 is same as writing a<>0
  r=n MOD 10
  s=s+r
  n=int(n/10)
WEND
digitsum=s
END FUNCTION

Summing up digits of provided number

Rem Sum of digits of Number Example: Sum of digits of 254 is 11
CLS
INPUT "Number=";n
a=n
WHILE a<>0
  r=a MOD 10
  s=s+r
  a=int(a/10)
WEND
PRINT "Sum of  digits of ";a; " is ";s
END

Testing Armstrong Number using User Defined Function

DECLARE FUNCTION arm(n)
CLS
INPUT "Enter a testing number=";v
IF arm(v)=1 THEN
  PRINT v;" is Armstrong Number"
ELSE
  PRINT v; " is not Armstrong Number"
ENDIF
END

FUNCTION arm(n)
f=0
a=n
WHILE a<>0
  r=a MOD 10
  s=s+r^3
  a=int(a/10)
WEND
IF s=n THEN f=1
arm=f
END FUNCTION

Testing Armstrong Number

Rem Number which is equal to the sum of cube of its digits is said to Armstrong Number
CLS
INPUT "Enter testing number=";n
v=n
WHILE V<>0
  r = v MOD 10
  s=s+r^3
  v=int(v/10)
WEND
IF n=s THEN
  PRINT n; " is Armstrong Number"
ELSE
  PRINT n; " is not Armstrong Number"
ENDIF
END

Testing Palindrome

CLS
INPUT "Enter string to be tested: ";t$
t$=LCASE$(t$)
FOR I=LEN(t$) TO 1 STEP -1
  r$=r$+MID$(t$, I, 1)
NEXT I
IF r$=t$ THEN
  PRINT t$; " is Palindrome!"
ELSE
  PRINT t$; " is not Palindrome!"
ENDIF
END

Testing Palindrome Using Function...End Function

DECLARE FUNCTION rev$(s$)
CLS
INPUT "Enter string to be tested"; t$
t$=LCASE$(t$)
IF t$=rev$(t$) THEN
  PRINT t$;" is Palindrome!"
ELSE
  PRINT t$;" is not Palindrome!"
ENDIF
END

FUNCTION rev$(s$)
FOR I = LEN(s$) to 1 STEP -1
  r$=r$+MID$(s$, I, 1)
NEXT I
rev$=r$
END FUNCTION

Prime Composite Testing Program Using User Defined Function

DECLARE FUCTION ISPRIME(N)
CLS
INPUT "Testing Number: ";N
IF ISPRIME(N)=1 THEN
    PRINT N; " IS PRIME NUMBER"
ELSE
   PRINT N;" IS COMPOSITE NUMBER"
ENDIF

FUNCTION ISPRIME(N)
'F if flag which is set to 1 means it is assumed to be prime at first
F=1
'if there is any factor from 2 to half of the number n then the number is composite
FOR I= 2 TO N/2
    IF N MOD I=0 THEN
        F=0
        EXIT FOR
     ENDIF
NEXT I
ISPRIME=F
END FUNCTION

Prime Composite Testing Program

CLS
INPUT "Test Number: ";N
'f is flag which is set to 0 indicating testing number is prime and 1 indicating testing number is composite
F=0
FOR I=2 TO N/2
     IF N MOD I=0 THEN
         F=1
         EXIT FOR
     ENDIF
NEXT I
IF F=0 THEN
   PRINT N;" IS PRIME NUMBER"
ELSE
   PRINT N;" IS COMPOSITE NUMBER"
ENDIF