answersLogoWhite

0

QBasic

QBasic is an integrated development environment (IDE) and interpreter for a variant of the BASIC programming language. QBasic includes a debugger with code modification and on-the-fly expression evaluation that can run under most versions of DOS, Windows, Linux and FreeBSD.

221 Questions

Explain the if-then-else statement with syntax in computer QBASIC?

Here is a simple example of a program using the IF...THEN...ELSE... statement in QBASIC:

1 CLS

2 INPUT "What is your name?" NAME$

3 IF NAME$ = "Fred" THEN GOTO 4 ELSE GOTO 6

4 PRINT "Fred is a cool name!"

5 END

6 PRINT "Your name isn't Fred, you're Lame!"

7 END

NB: My name isn't Fred!!!

How the statement works is simple...

IF [VARIABLE NAME] [EQUALS/DOES NOT EQUAL/GREATER THAN/LESS THAN] [PERAMETER] THEN [ACTION] [PERAMETER] ELSE [ACTION] [PERAMETER]

A similar function exists in most programming languages, and uses can range from a simple calculation to password control. Also, you can use other commands within this (eg: OR) or use several commands together to give more options:

1 CLS

2 INPUT "What is your name?" NAME$

3 IF NAME$ = "Fred" THEN GOTO 4 ELSE GOTO 6

4 PRINT "Fred is a cool name!"

5 END

6 IF NAME$ = "Bob" THEN GOTO 7 ELSE GOTO 9

7 PRINT "Fred is a cool name, but Bob is OK too!"

8 END

9 PRINT "Fred is OK, Bob is Acceptable but "; NAME$; " is just lame!"

10 END

NB: Bob is not my name either, guess I'm lame!

Hope this answers your query!

Dan

PS: Other statements used in examples:

CLS = Clear Last Screen

INPUT = Allows you to enter data after text is displayed, and attach to the variable

PRINT = Print the text.

END = Finish the program run.

It may also be useful to note, if using QBASIC on Windows Vista the LPRINT function does not work correctly. If you need to output to a printer, it is better to save as a text file and then print within the Windows Vista environment. Alternatively, run an older version of Windows just for programming in. I tend to use Windows 2000 professional - good flexability and pretty stable!

=====

No disrespect meant to the above programmer; who, overall, I think, has done a really fine job of explaining things. ;-)

Nevertheless, for me, the above code contains certain problems which still need to be addressed and fixed...

A) Line number 2...

2 INPUT "What is your name?" NAME$

...is incorrect syntax...instead, it should have said...

2 INPUT "What is your name?";NAME$

...including a semi-colon symbol(;) which is to be placed in between both quoted text("")/and, variable name(NAME$).

B) The first example uses the END statement, twice; and, the second example uses the END statement three times, no less...; but, strictly speaking, there should only be no more than just 'one' single END statement, alone, in any program.

C) The use of LINE NUMBERS together with GOTO statements is completely outdated...and, quite often, can lead to difficult to read, error prone programs; these are ancient relics belonging to the old time 'original' BASIC programming language.

When using the modern day QBASIC programming language we don't need to rely on using such old fashioned statements anymore...much preferring instead to use carefully structured block statements...which makes our program logic read a lot more clear.

I would re-write program 1, by using an IF-THEN-ELSE-END IF statement block, as...

CLS

INPUT "What is your name?";name$

IF name$ = "Fred" THEN

PRINT "Fred is a cool name!"

ELSE

PRINT "Your name isn't Fred, you're Lame!"

END IF

END

I would re-write program 2, by using an IF-THEN-ELSEIF-ELSE-END IF statement block, as...

CLS

INPUT "What is your name?"; name$

IF name$ = "Fred" THEN

PRINT "Fred is a cool name!"

ELSEIF name$ = "Bob" THEN

PRINT "Fred is a cool name, but Bob is OK too!"

ELSE

PRINT "Fred is OK, Bob is Acceptable but "; name$; " is just lame!"

END IF

END

NOTE: In the above amended code; there are no line numbers/and, no goto's.

NOTE: Each of the above programs has 'one'...and, only 'one' single END statement.

NOTE: My own variable names begin by using all lower case letters; and, I will capitalise each 1st letter of any successive word(s) appearing in the same variable name...nameOne$/nameTwo$/nameThirtyThree$...as it makes the code read a lot more clear...when it comes to very quickly and easily distinguishing between what is a QBASIC language keyword such as PRINT/and, what is a variable name which was invented by the actual program writer themselves.

Everybody tends to write code differently; so, if 100 different programmers were asked to write a program which displays exactly the same 'surface output'; then, one would most likely find that the underlying 'source code' beneath has been written entirely differently by every single programmer!

Programming 'style'...is really all down to a matter of personal taste/or, choice. You will learn this as you come across reading more and more programs. For example, going back to the question of what type of variable name to use? Some people like using the minimal, n$/others use all capitals NAME$/and, yet, another writes it as being all lower case, name$/whereas, a next programmer might write it using long form, 3 letter prefix, strName$/-etc. Furthermore, some will add code comments/and, other's don't! Over time, and, with experience we all tend to develop our own much preferred style of writing programs; going according to whichever method we find works best, and, does most tend to suit our own personal needs.

NOTE: The IF statement comes in quite a few different forms...

(single line)

A) IF/THEN

B) IF/THEN/ELSE

(multiple lines; also, called a statement block)

C) IF/THEN/ELSE/END IF

D) IF/THEN/ELSEIF/ELSE/END IF

...which I will quickly illustrate as...

A)

x=1

IF x=1 THEN PRINT "one"

B)

x=3

IF x=1 THEN PRINT "one" ELSE PRINT "NOT one"

C)

x=2

IF x=1 THEN

PRINT "one"

ELSE

PRINT "NOT one"

END IF

D)

x=1 : y=2

IF x=1 THEN

PRINT "one"

ELSEIF x=2 THEN

PRINT "two"

ELSE

PRINT "NOT one/NOT two"

END IF

How to convert Qbasic to C?

10 REM Sample BASIC Program - Counts To Ten 20 REM 30 REM Copyright 2005 Andrew Eichstaedt 40 REM Eichstaedt Development Group 50 REM http://www.andrew-eichstaedt.com 60 REM 70 PRINT "Hello! I am a sample BASIC program" 80 PRINT "that counts to ten." 90 PRINT 100 FOR I=1 TO 10 110 PRINT I 120 NEXT I 130 PRINT 140 PRINT "Thanks for running me." 150 END

What is the extension of qbasic program?

.bas file

====

<--QBASIC CODE end

Now, go and search your computer c:\ directory for the file called: homepage.htm; and, left double click on it to run; your web browser software should automatically launch itself, and, so display the web page output. Right click within an empty space within the web browser page...and, choose View > Source...and, you will be able to see the HTML source codes which were used to originally write the web page with; though, the QBASIC code itself is not displayed but remains entirely hidden.

How do you write vowels in Qbasic?

cls
input" enter any string";a$
f=Len(A$)
d=1
AA:
b$= mid$(a$,d,1)
d=d+1
c=asc(b$)
if c=101 or c=105 or c=970 or c=111 or c=117 then
cnt= cnt+1
end if
if d<=f then goto aa
print cnt;
end

How would you write a program to display even numbers between 0-20?

ALGORITHM EVEN

BEGIN

FOR ( num = 0; num <= 20; num++ )

BEGIN

IF ( num MOD 2 == 0 ) THEN

DISPLAY (num)

END IF

END FOR

END EVEN

in C:

#include <stdio.h>

int main (void) { puts ("0 2 4 6 8 10 12 14 16 18 20"); return 0; }

What is a linear queue?

A linear queue models the FIFO(first in first out) data structure, much like a line in real life. The first person in line will be the first person served, in queues the first element to be added is the first that can be removed. The only adding point is to the end of the list and the only removal point is the beginning of the list.

Queue<String> q = new LinkedList<String>(); // The LinkedList class implements Queue

q.add("Bob"); // Now Bob is at the front of the queue

q.add("Stacy"); // Stacy after Bob

q.add("Will"); // and Will after her

String removed = q.remove(); // Bob is removed

q.add("Michael"); Michael is added after Will

System.out.println(q); // Prints ["Stacy", "Will", "Michael"]

What are control structures used in javascript?

The control structures used in java script are if-statement, for-loop, for-in loop, while loop,do-while loop, switch-statement, with-statement. try-catch-finally statements.

What is the difference between photo electric effect and compton effect?

  • The photo-electric effect causes a current to pass between two plates that already have a voltaic potential difference.
  • the photovoltaic effect causes a voltage to grow between two plates that don't already have one (or changes the applied voltage to something else). There is no current.

In photo electric effect,

  • When light(photon) Strikes on the one plate,electron in outershell of atom is ejected by absorbing the light.And electron can move from its plate to other plate if energy of photon is satisfy the break force of surface into electron and potential energy of two plates.So current is generated.

In photo voltaic effect,

  • When light(photon) Strikes on the one plate, electron in outershell of atom is go up to new energy level by absorbing the light. So no charge carriers move.Therefore no current.

How do you add 2 numbers in QBASIC?

I'm not too sure that I understand exactly what you mean by 'add a square'...?! Thus, I will attempt to answer the question using multiple different ways; hoping that, least, 'one' of these answers might be right...

==>

CLS

PRINT "PROGRAM: Twelve Times Tables Number Square"

PRINT

FOR intTimes% = 1 TO 12

FOR intTables% = 1 TO 12

sum% = intTimes% * intTables%

noOfSpaces% = 0

IF LEN(STR$(sum%)) = 2 THEN noOfSpaces% = 2

IF LEN(STR$(sum%)) = 3 THEN noOfSpaces% = 1

PRINT sum%; SPC(noOfSpaces%);

NEXT

PRINT

NEXT

END

<==

...QBASIC Code/End.

How do you swap two numbers in qbasic?

Create a form with two text boxes (txtNumber1, and txtNumber2) and a command button (cmdSwap).

Option Explicit

Dim numb1 As Variant

Dim numb2 As Variant

Private Sub cmdSwap_Click()

numb1 = txtNumber1.Text

numb2 = txtNumber2.Text

txtNumber2.Text = numb1

txtNumber1.Text = numb2

End Sub

Why qbasic is a higher level languages?

QBasic Benefits :-

1) It is a good language for beginners.

2) It has English-like commands.

3) QBasic has an easy format and is easy to implement.

4) The errors in codes can be fixed easily.

QBasic Limitations:-

1) It is not professional programing language.

2) The language is not structured.

3) It is hard to understand.

4) It is rarely used in real life except in the field of education and training.

How do you display 1 11 111 1111 11111 in qbasic using FOR.NEXT?

cls

a =1

for i = 1 to 5

print a;

a = (a*10)+1

next i

end

What are the words that make up a high-level programming language called?

Some languages have specific terms, however keyword or reserved word is the general terminology we use when referring to a programming language's primary vocabulary. That is; words that cannot be used as identifiers. However, some languages also have contextual keywords. For instance, C++ has final and override contextual keywords. These can be used as both identifiers and keywords, depending on the context. The only reason for this is that people were using these words as identifiers before they were introduced to the language (in C++11) and making them actual keywords would have broken a lot of older code.

How do i type the a with a circlely thing around it?

@...the AT symbol is located...on my 'own' keyboard, at least, next to the [COLON(:)/SEMI-COLON(;)] key. It's above the [single quote(')/(@)]...that means it's an UPPER CASE symbol.

To obtain UPPER CASE 'letters/symbols/numbers' that are shown on your keyboard...you need to...

1. press, and, hold down the [SHIFT] button key...

-(which is, usually, shown as being an 'upwards arrow'...there are two [SHIFT] button keys, each located on either side of the keyboard, next to/and, on top of both the [CTRL] keys)-

2. ...whilst at the same time, pressing down the [@] symbol key.

====

SOME FURTHER NOTES

ASCII/American Standard Code for Information Interchange, uses the numbers:

-> 65-90, to represent UPPER CASE alphabet letters: A-Z

-> 97-122, to represent 'lower case' alphabet letters: a-z

-etc.

You can have a go at experimenting, try typing in all of the ASCII code numbers: 0-255;

to discover seeing what character comes up, next...?!

NOTE: Some ASCII number codes are, in fact, 'invisible' characters that will NOT display...;

such as ASCII number 32 represents a [SPACEBAR] key invisible 'space' character/

too, there is the invisible [TAB] character key which also won't display/-etc.

How do you find the minimum and the maximum of a function?

'*** PROGRAM: Compare 2 numbers using both min/max functions;

' then, output which number is max/and, which is min.

'*** declare variables...

min = 0

max = 0

number1 = 342

number2 = 256

'*** main program...

CLS '...(CL)ear the Output (S)creen

PRINT "Minimum = "; findMin(number1, number2)

PRINT "Maximum = "; findMax(number1, number2)

END '...END of program/halt program code execution

FUNCTION findMax (num1, num2)

answer = 0

IF num1 > num2 THEN answer = num1 ELSE answer = num2

findMax = answer

END FUNCTION

FUNCTION findMin (num1, num2)

answer = 0

IF num1 < num2 THEN answer = num1 ELSE answer = num2

findMin = answer

END FUNCTION

---program output...

Minimum: 256

Maximum: 342

How do you find the smallest value in a set of numbers in qbasic?

Store the numbers in a suitable container such as an array. Assume the first number is the smallest and assign its value to a local variable. Traverse the remainder of the sequence, comparing each element's value to the stored value. If an element has a lower value, assign its value to the local variable. When the sequence is fully traversed, the local variable will hold the value of the smallest value in the sequence. Return that value.

Sum of two matrices in c program?

#include<stdio.h>

#include<conio.h>

main()

{

int a[4][4],b[4][4],c[4][4],i,j;

printf("enter the elements of matrix a");

for(i=0;i<=3;i++)

for(j=0;j<=3;j++)

scanf("%d",&a[i][j]);

printf("the first matris is");

for(i=0;i<=3;i++)

{

printf("\n");

for(j=0;j<=3;j++)

printf("%d",a[i][j]);

}

printf("Enter the elements of second matrix");

for(i=0;i<=3;i++)

for(j=0;j<=3;j++)

scanf("%d",&b[i][j]);

printf("the second matrix is");

for(i=0;i<=3;i++)

{

printf("\n");

for(j=0;j<=3;j++)

printf("%d",b[i][j]);

}

for(i=0;i<=4;i++)

for(j=0;j<=4;j++)

c[i][j]=a[i][j] + b[i][j];

printf("the addition of matrix is");

for(i=0;i<=3;i++)

{

for(j=0;j<=3;j++)

printf("%d\t",c[i][j]);

printf("\n");

}

getch();

}

What is the program to print Fibonacci series in qbasic?

CLS

a = 0

b = 0

FOR i = 1 TO 10

IF a = 0 THEN

f = 1

END IF

PRINT f

b = a

a = f

f = a + b

NEXT i

END

from : Parth jani

parthjani7@yahoo.com

WAP to print even numbers upto 20 and find the total in Q-Basic?

cls

total=0

for i=0 to 20 step -2

total = total+i

print i ;

next i

print "total is " total

end

send by tripti

How do you get FBide basic to pause for 5 seconds before doing the next command?

You can't. If you want to pause between each command you have to step through the commands one at a time, or set a breakpoint at the point you wish to start stepping through.

Process is passive entity is it true?

No, Process is an active entity. Program, on the other hand, is a passive entity.

Write a program that will find the smallest largest and average values in a collection of N numbers Get the value of N before scanning each value in the collection of N numbers?

#include
#include
#include

int main(int argc, char *argv[]){
int n, smallest, largest, sum, temp;
if(argc < 2){

printf("Syntax: foo val1[val2 [val3 [...]]]\n");
exit(1);

}

smallest = largest = sum = atoi(argv[1]);
for(n = 2; n < argc; n++){
temp = atoi(argv[n]);
if(temp < smallest) smallest = temp;
if(temp > largest) largest = temp;
sum += temp;

}

printf("Smallest: %i\nLargest: %i\nAverage: %i\n", smallest, largest, sum / (argc - 1));
return 0;

}