QBasic: Looping

January 15, 2010

In programming, loops are used to repeat an instruction for as much as needed. There are a few ways to loop in BASIC:


An example of the IF THEN GOTO loop can be found here where we used those commands to check for a triangle. The program will keep on asking for the right values to enter (the ones of a real triangle) thus creating a loop that’s stopped when the right values are entered.
Read the rest of this entry »

C++: Programming in Linux – Hello World

January 12, 2010

C++ is one of the most widely used programming languages today. I’m not going to talk about it in general but skip to the first example, which would be the Hello World program.
Before we start you should know that Ubuntu has an included C++ compiler called G++, so you won’t be needing a C++ IDE. I’ll be writing the programs here on GEdit (plain text editor) and compile it with G++. Also Ubuntu has an integrated debugger called GDB. Those two work on the command line, don’t be scared it isn’t complicated.
Read the rest of this entry »

QBasic: An example of INPUT, IF-THEN-ELSE, GOTO commands

December 14, 2009

A program for calculating the area of a triangle using Heron’s formula:


'Program description, it's always good to have one at the top
PRINT "A program for calculating the area of a triangle using Heron's formula."
10 PRINT "Input the value of the triangle's sides:"
INPUT "a = ";a
INPUT "b = ";b
INPUT "c = ";c

'Check if it's a triangle
IF (a < 0 OR b < 0 OR c < 0 OR a + b < c OR a + c < b OR b + c < a) THEN
PRINT "That is not a triangle. Try again."

s = (a + b + c)/2
P = s * (s - a) * (s - b) * (s - c)
P = P ^ (1 / 2)

'Result print-out
PRINT "P = ";P

'Repeat the program
20 INPUT "Repeat the program [press 1 for YES, and 2 for NO]"; out%
IF (out% 1 AND out% 2) THEN
PRINT "Wrong input!"

ELSEIF out% = 1 THEN GOTO 10

Read the rest of this entry »

QBasic: Data Types

December 13, 2009

Every variable used in the program has data type. A variable is created the first time it is referenced in your code, such as when you first set a value to it. As stated before, there are five types of variables. Each one has its own associated suffix to identify its type. It is a wise programmer who learns to use the appropriate data-type for the purpose they choose their variable, and to select the maximum storage (number of bytes) required.
Read the rest of this entry »

QBasic: Installing on Linux and writing your first program

December 9, 2009

Basic is a fairly easy programming language to learn for beginners, that’s why I’m starting with that particular language and will work my way up the complexity scale.
QBasic is an IDE (Integrated development environment) and an interpreter for the BASIC programming language. It was developed by Microsoft more than 20 years ago. And being developed by MS it runs only on Windows, but thanks to emulators, namely Wine, it’s possible to run in it under Linux also. All you need to do to install Wine emulator on your Linux box is to write into the terminal this line:

sudo apt-get install wine

Read the rest of this entry »

Solving problems – the problem resolution process

December 8, 2009

Before I start with the more technical stuff about programming I’d like to write about how to solve problems with a predefined algorithm (an algorithm is a set of instructions that are executed the same way as they are written to solve a problem). The step of solving a problem, the problem solving algorithm is:

1 – Determine the Purpose
2 – What are the Required Data
3 – Determine the Logic
4 – Create the Computer Program
5 – Test and Re-test

Read the rest of this entry »