Short term plans for the web BASIC

Scott and I had a sitdown design time last Friday and also managed to get started on some code for the web BASIC he is working on. The idea here is that you will be able to visit a site with a tabbed interface. The first few tabs will each have a code pane with an example program, and a Run button. Click on the button, and the program will run underneath on the same page. This should be a good way to get a feel for what kind of programming is possible. An additional tab will have an empty code pane so that you can try writing your own.

We will support the INPUT statement, so you can create interactive programs. The standard style of BASIC will be supported in this way. We will also include the ability to draw graphics and embed them into the output so you can draw graphs or game boards, etc. Fast animation wont really be possible using an http style of interaction, but if you want to create games that draw images (Star Trek, or Mastermind, or Sudoku) it should be fine.

Programs will be cached on the server for a few hours (or a day perhaps) so if you create a program on the site that you really like, you can share it with a friend by pushing a button to send an email with a URL that will take him straight to the program in his web browser. I think thats pretty cool because theres no need to install any software. It should work in any popular web browser including most phone browsers.

Scott already has some of this working. This should be fun. :-)
Read More..

Whats my story

As an implementor of BASIC, where am I coming from?

The home computer, a way back machine - In regards to the BASIC programming language, I think my strongest formative influence comes from working with old home computers. There was something wonderful about these machines that plugged into the family television set. They were simple when compared to computers now, and you could get your mind around them. You could master the whole computer because all of the details fit in a 5x8" spiral bound manual a couple of hundred pages long.

Personal Mastery - Perhaps similarly, I used to work on my own cars. I loved working on old Volkswagen Beetles, and I owned a bunch of them. I knew pretty much everything about the Beetle, and I loved knowing all about it. Its about that feeling you get when you master something. Nowadays I take my cars to the experts because I simply cannot understand the new cars. If it breaks down, I call a tow truck. Its harder to love cars today. This is how computers have become.

Interactivity - Lets see. Just like you can take the parts of an old car and flip them over in your hands, see how they fit together and what makes them tick, programming in BASIC on a home computer was like that. You could stop your program, look at variables (flip them over in your hands, so to speak), execute a little line of code on the fly, and resume execution at any point. If you wanted to mess with the video mode, or tweak the sound, or read/write some memory value, you could. The very nature of the machine permitted it. There is was, all laid out before you like clay in your hands and it was not so vast that you were overwhelmed by it all.

BASIC today - So I really feel that if at all possible BASIC programming should still be like this, but it mostly is not. Most BASIC languages today are compilers. This means that once you start to run your program, you cannot just stop it and tweak it. You cant change the code of a running program without needing to restart the program from scratch. In addition, the huge functionality of modern operating systems inspires programming language implementors to continually make their BASIC languages bigger and bigger. This is an artificial barrier to personal mastery.

The reverse 80/20 rule - Okay, since only 20 percent of the Windows operating system functionality is needed 80 percent of the time, why create a programming language that tries to embrace all of it? Home computers did most of what a computer is useful for, and compared to computers today they didnt do much of anything. The reality is that an awful lot of useful things can be done with a very small language.

Small is beautiful - Balance is also beautiful. BASIC should try to strike a balance between being small, and also supporting the most often needed features of Windows, the Mac OS or whatever operating system it runs on.

Aesthetics matter - How does your BASIC language look, like BASIC? Im not kidding. Many programming languages today that call themselves BASIC dont look anything like BASIC. Tacking ideas and syntax onto BASIC from other languages only complicates things. If it doesnt look like BASIC, it isnt BASIC. I dont mean this in a snobby way. I just think that the feel of the original language is worth preserving because it had a nice simple down to earth quality. Removing that quality also removes some of the fun, and I dont see why we need to do that. ;-)
Read More..

Number rhombus2

Q. Write a C program to print the number in following fashion:
      1
     212
    32123
   4321234
  543212345
   4321234
    32123
     212
      1


Ans.


/*c program for number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter number of rows : ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
   for(sp=num-r; sp>0; sp--)
       printf(" ");
   for(c=r; c>=1; c--)
       printf("%d",c);
   for(c=2; c<=r; c++)
       printf("%d",c);
   printf("
"
);

 }
 for(r=1; r<=num; r++)
 {
   for(sp=r; sp>=1; sp--)
       printf(" ");
   for(c=num-r; c>=1; c--)
       printf("%d",c);
   for(c=2; c<=num-r; c++)
       printf("%d",c);
   printf("
"
);

 }
 getch();
 return 0;
}


/*************** OUTPUT ***************/





Read More..

Star Zero Nested Pattern

Q. Write a C program to print the following star-zero nested pattern pyramid as:

*000*000*
0*00*00*0
00*0*0*00
000***000

Ans.

How to make above star-zero nested pattern:

*000*000*
0*00*00*0
00*0*0*00
000***000

In above star-zero nested pattern, there are 4 loops(each loop have different color), so before you making above pyramid, you should make first individual each loop, after making all loop, join them.
Thats done.

/*c program for star-zero nested pattern pyramid*/
#include<stdio.h>
int main()
{

 int num,n,r,c;
 printf("Enter number of rows : ");
 scanf("%d", &num);
 n=num;
 for(r=1; r<=num; r++,n--)
 {
   for(c=1; c<r; c++)
      printf("0");
   for(c=1; c<=n; c++)
   {
      if(c==1)
         printf("*");
      else
         printf("0");
   }
   printf("*");
   for(c=1; c<n; c++)
      printf("0");
   for(c=1; c<=r; c++)
   {
      if(c==1)
         printf("*");
      else
         printf("0");
   }
   printf("
"
);

 }
 getch();
 return 0;
}

/**************************************************************
The output of above program would be
***************************************************************/


Output of Star-Zero Nested Pattern C program
Figure: Screen-shot for Star-Zero Nested Pattern C program

Read More..

Number Triangle

Q. Write a C program to print the following number triangle as:

     1
    21
   321
  4321
 54321

Ans.

/*c program for number pyramid*/
#include<stdio.h>
int main()
{

 int num,r,c,sp;
 printf("Enter no of rows : ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(sp=num-r; sp>=1; sp--)
     printf(" ");
  for(c=r; c>=1; c--)
     printf("%d",c);
  printf("
"
);

 }
 getch();
 return 0;
}

The output of above program would be:


Output of number triangle C program
Figure : Screen shot for number triangle C program

Read More..

Overloading Operator II

In the previous article Overloading
[] Operator
, we overloaded the [] operator in a class to access data
within the class by indexing method.


The operator [] function was defined as below:


  int myclass::operator[](int index)
{
// if not out of bound
if(index<num)
return a[index];
}

As you can see, the above operator
function
is returning values, hence it could only be used on the right
hand side of a statement. It’s a limitation!


You very well know that a statement like below is very common with respect
to arrays:


a[1]=10;


But as I said, the way we overloaded the [] operator, statement like the one
above is not possible. The good news is, it is very easy to achieve this.


For this we need to overload the [] operator like this:


  int &myclass::operator[](int index)
{
// if not out of bound
if(index<num)
return a[index];
}

By returning a reference
to the particular element, it is possible to use the index expression on the
left hand side of the statement too.


The following program illustrates this:



// Example Program illustrating
// the overloading of [] operator
// ----
// now the index expression can be
// used on the left side too
#include <iostream.h>

class myclass
{
// stores the number of element
int num;
// stores the elements
int a[10];

public:
myclass(int num);

int &operator[](int);
};

// takes the number of element
// to be entered.(<=10)
myclass::myclass(int n)
{
num=n;
for(int i=0;i<num;i++)
{
cout<<"Enter value for element "<<i+1<<":";
cin>>a[i];
}
}

// returns a reference
int &myclass::operator[](int index)
{
// if not out of bound
if(index<num)
return a[index];
}

void main()
{
myclass a(2);

cout<<a[0]<<endl;
cout<<a[1]<<endl;

// indexing expression on the
// left-hand side

a[1]=21;
cout<<a[1];
}


Related Articles:


Read More..

Street Cred Game


From the visual side, this game appeared older with pixel art or broken images. Even so, the image is full color makes the game seem more exciting.

When I started playing, you will be given two options namely Qualifier and Nationals. However, to play a game at Nationals session, you must complete the first all race racing at the session Qualifier.

No different from how to play car racing games in general. After selecting a car, you can immediately sped from the beginning to the end line.

Theres nothing that will compete with your enemies. But, do not drive home because there are many obstacles along the way, ranging from ordinary cars to large trucks. Do not let your car hit by another car or truck because it will make you eliminated. But please note that there are some things that you do have to hit to get the bonus value such as money, gold, and nitrous oxide to supplement the cars speed. This car racing game has several levels. The higher the level, will be the more obstacles that must be avoided on the road.
Read More..