Online Examination System for all learner!!! coming soon..

VB 6 : Make Web Browser Application

  If you are bored with existing web browsers, you can create your very own web browser using Visual Basic. In order to create the web browser, launch Visual Basic 6, press Ctrl+T to open up the components window and then select Microsoft Internet Control. The control will appear in the toolbox as a small globe. To insert the Microsoft Internet Control into the form, just drag the globe into the form and a white rectangle will appear in the form. You can resize this control to the size you wish. This control is given the default name WebBrowser1.

   To design the interface, you need to insert one combo box which will be used to display the URLs. In addition, you need to insert a few images which will function as command buttons for the user to navigate the Internet; they are the Go command, the Back command, the Forward command, the Refresh command and the Home command. You can actually put in the command buttons instead of the images, but using images will definitely improve the look of the browser.

The code for all the commands is relatively easy to write. There are many methods, events, and properties associated with the web browser but you need to know just a few of them to come up with a functional Internet browser.

 The method navigate is to go the website specified by its Uniform Resource Locator(URL). The syntax is WebBrowser1.Navigate (“URL”). In this program, we want to load the www.programtube01.blogspot.com web page at start-up.

 Related Video:

VB 6 : Tower of Hanoi

click here 
http://www.vb-helper.com/howto_tower_of_hanoi.html
 <<Previous          Downlod Code             Next>>

C++ : Program for Tower of Hanoi

  Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 
  1. Only one disk can be moved at a time.
  2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.
  3. No disk may be placed on top of a smaller disk.

Code:

#include <stdio.h>

// C recursive function to solve tower of hanoi puzzle
void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod)
{
    if (n == 1)
    {
        printf("\n Move disk 1 from rod %c to rod %c", from_rod, to_rod);
        return;
    }
    towerOfHanoi(n-1, from_rod, aux_rod, to_rod);
    printf("\n Move disk %d from rod %c to rod %c", n, from_rod, to_rod);
    towerOfHanoi(n-1, aux_rod, to_rod, from_rod);
}

int main()
{
    int n = 4; // Number of disks
    towerOfHanoi(n, 'A', 'C', 'B'); // A, B and C are names of rods
    return 0;
}

Output:

 Move disk 1 from rod A to rod B
 Move disk 2 from rod A to rod C
 Move disk 1 from rod B to rod C
 Move disk 3 from rod A to rod B
 Move disk 1 from rod C to rod A
 Move disk 2 from rod C to rod B
 Move disk 1 from rod A to rod B
 Move disk 4 from rod A to rod C
 Move disk 1 from rod B to rod C


C : Program for Tower of Hanoi

VB 6 : Implementation of Tic-Tac-Toe game

Code:

Dim score1 As Integer, score2 As Integer
Dim cur As String

Private Sub Form_Load()
  ResetGame
  p2.Enabled = False
  cur = 1
End Sub

Private Sub img_DragDrop(Index As Integer, Source As Control, X As Single, Y As Single)
    If img(Index).Picture = imgX.Picture Or img(Index).Picture = imgO.Picture Then 
    Exit Sub
    img(Index).Picture = Source.Picture
    img(Index).Tag = Source.Tag
    Dim winner As String
    If checkwin <> "no" Then
        If checkwin = "x" Then
            winner = "Player 1"
            score1 = score1 + 1
            s1.Caption = score1
        Else
            winner = "Player 2"
            score2 = score2 + 1
            s2.Caption = score2
        End If
        MsgBox "The winner is " & winner, vbInformation, "Winner"
        ResetGame
    End If
    If cur = 1 Then
        cur = 2
        p1.Enabled = False
        p2.Enabled = True
    Else
        cur = 1
        p1.Enabled = True
        p2.Enabled = False
    End If
End Sub

Private Sub ResetGame()
    For i = 0 To 8
        img(i).Tag = i
        img(i).Picture = Nothing
    Next i
   
End Sub

Private Function checkwin() As String
    Dim a1 As String, a2 As String, a3 As String, b1 As String, b2 As String, b3 As String, _
    c1 As String, c2 As String, c3 As String
   
    a1 = img(0).Tag
    a2 = img(1).Tag
    a3 = img(2).Tag
    b1 = img(3).Tag
    b2 = img(4).Tag
    b3 = img(5).Tag
    c1 = img(6).Tag
    c2 = img(7).Tag
    c3 = img(8).Tag
       
    If a1 <> "0" And a2 <> "1" And a3 <> "2" And _
        b1 <> "3" And b2 <> "4" And b3 <> "5" And _
        c1 <> "6" And c2 <> "7" And c3 <> "8" Then
        MsgBox "Game Draw!", vbInformation, "Game Over"
        ResetGame
    End If
   
       
    If a1 = a2 And a2 = a3 Then
        checkwin = a1
    ElseIf b1 = b2 And b2 = b3 Then
        checkwin = b1
    ElseIf c1 = c2 And c2 = c3 Then
        checkwin = c1
    ElseIf a1 = b1 And b1 = c1 Then
        checkwin = a1
    ElseIf a2 = b2 And b2 = c2 Then
        checkwin = a2
    ElseIf a3 = b3 And b3 = c3 Then
        checkwin = a3
    ElseIf a1 = b2 And b2 = c3 Then
        checkwin = a1
    ElseIf a3 = b2 And b2 = c1 Then
        checkwin = a3
    Else
        checkwin = "no"
    End If
End Function

Output:


 <<Previous Page                    Download Code                    Next Page>>

Related Programs:

  1. VB 6 : Tower of Hanoi
  2. VB 6 : Implementation of Tic-Tac-Toe game
  3. VB 6 :  Make Web Browser Application

C++ : Implementation of Tic-Tac-Toe game

C : Implementation of Tic-Tac-Toe game

VB 6 : Sudoku Solver

C++ : Sudoku Solver

 
This C++ Program demonstrates the Sudoku Problem using Backtracking.
Here is source code of the C++ Program to solve the Sudoku Problem using BackTracking. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.

Code:

/*C++ Program to Solve Sudoku Problem using BackTracking */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
#define UNASSIGNED 0
#define N 9
 
bool FindUnassignedLocation(int grid[N][N], int &row, int &col);
bool isSafe(int grid[N][N], int row, int col, int num);
 
/* assign values to all unassigned locations for Sudoku solution  
 */
bool SolveSudoku(int grid[N][N])
{
    int row, col;
    if (!FindUnassignedLocation(grid, row, col))
       return true;
    for (int num = 1; num <= 9; num++)
    {
        if (isSafe(grid, row, col, num))
        {
            grid[row][col] = num;
            if (SolveSudoku(grid))
                return true;
            grid[row][col] = UNASSIGNED;
        }
    }
    return false;
}
 
/* Searches the grid to find an entry that is still unassigned. */
bool FindUnassignedLocation(int grid[N][N], int &row, int &col)
{
    for (row = 0; row < N; row++)
        for (col = 0; col < N; col++)
            if (grid[row][col] == UNASSIGNED)
                return true;
    return false;
}
 
/* Returns whether any assigned entry n the specified row matches 
   the given number. */
bool UsedInRow(int grid[N][N], int row, int num)
{
    for (int col = 0; col < N; col++)
        if (grid[row][col] == num)
            return true;
    return false;
}
 
/* Returns whether any assigned entry in the specified column matches 
   the given number. */
bool UsedInCol(int grid[N][N], int col, int num)
{
    for (int row = 0; row < N; row++)
        if (grid[row][col] == num)
            return true;
    return false;
}
 
/* Returns whether any assigned entry within the specified 3x3 box matches 
   the given number. */
bool UsedInBox(int grid[N][N], int boxStartRow, int boxStartCol, int num)
{
    for (int row = 0; row < 3; row++)
        for (int col = 0; col < 3; col++)
            if (grid[row+boxStartRow][col+boxStartCol] == num)
                return true;
    return false;
}
 
/* Returns whether it will be legal to assign num to the given row,col location. 
 */
bool isSafe(int grid[N][N], int row, int col, int num)
{
    return !UsedInRow(grid, row, num) && !UsedInCol(grid, col, num) &&
           !UsedInBox(grid, row - row % 3 , col - col % 3, num);
}
 
/* print grid  */
void printGrid(int grid[N][N])
{
    for (int row = 0; row < N; row++)
    {
        for (int col = 0; col < N; col++)
            cout<<grid[row][col]<<"  ";
        cout<<endl;
    }
}
 
/* Main */
int main()
{
    int grid[N][N] = {{3, 0, 6, 5, 0, 8, 4, 0, 0},
                      {5, 2, 0, 0, 0, 0, 0, 0, 0},
                      {0, 8, 7, 0, 0, 0, 0, 3, 1},
                      {0, 0, 3, 0, 1, 0, 0, 8, 0},
                      {9, 0, 0, 8, 6, 3, 0, 0, 5},
                      {0, 5, 0, 0, 9, 0, 6, 0, 0},
                      {1, 3, 0, 0, 0, 0, 2, 5, 0},
                      {0, 0, 0, 0, 0, 0, 0, 7, 4},
                      {0, 0, 5, 2, 0, 6, 3, 0, 0}};
    if (SolveSudoku(grid) == true)
          printGrid(grid);
    else
        cout<<"No solution exists"<<endl;
    return 0;
}

Output:

$ g++ sudoku.cpp
$ a.out
 
3  1  6  5  7  8  4  9  2
5  2  9  1  3  4  7  6  8
4  8  7  6  2  9  5  3  1
2  6  3  4  1  5  9  8  7
9  7  4  8  6  3  1  2  5
8  5  1  7  9  2  6  4  3
1  3  8  9  4  7  2  5  6
6  9  2  3  5  1  8  7  4
7  4  5  2  8  6  3  1  9
 
------------------
(program exited with code: 1)
Press return to continue

JAVA : Features of JAVA

Object-oriented programming:

  • This is the core feature of java.
  • This is to manage the increase in the complexity.
  • It provides a very sophisticated and well defined interface for the data.
  • It is also known as data controlling access code.
  • Another important feature of java being object oriented is abstraction.
  • Complexity can be managed using abstraction.

The three OOP principles:

  • Encapsulation- Its agenda is to manipulate the data and keep the data isolated and safe from the external interference and misuse. The encapsulation is done by the use of the protective wrapper. This prevents the external sources from accessing the data or the code.
  • Inheritance- In this the object would acquire the property of other object present. Itjust follows the concept of the hierarchical classification. This consists of classes, sub classes. Inheritance also is linked or interacts with encapsulation as well.
  • Polymorphism- It is means many ways to carry out the method but from one input.
 Byte code
This is highly optimized by set of instructions designed which is designed to be executed by Java virtual machine that is JVM.

JVM

  • It was designed as an interpreter for the byte code.
  • Another feature of java program is that it is simple.
  • This enables the professionals to learn.
  • Work in a very effective manner but it is also very easy to understand.

Robust

The ability that includes creating a robust program that can be a multiplatform program
are given a very high priority in design of Java.

Multithreading

The real world requirements are met by java which helps to achieve the requirement of
creating interactive and networked programs.

High performance

  • The advantage of being a multi platform functioning program helps to find the cross platform solution. 
  • It provides benefits of being an platform independent code with the help of java run time system.

Distributed

  • This is because it is been designed for the internet which has a distributed environment because of the handling of TCP/IP protocols.
  • This allows the program to find out methods across a network.
  • URL is used in this to access a file on internet.
  • This property supports RMI (Remote Method Invocation).

Dynamic

  • This is the action that is taken during the run-time such as to resolve, verify and add objects.
  • It provides us the function which will allow us to link code dynamically that will be safe.

Simple program

/* Call this file “Example.java” */
Class Example {
Public static void main (string args []) {
System.out.println (“this is a simple java program.”);
}
}

Command line argument to pass the class name is
C :\> java Example
Simple output of the above program
this is a simple java program.
Calling of the file in java cmd
Calling of the file: “Example.java”. 

Related Questions: 

  1. How JAVA differs from C++

JAVA : Introduction

  • Java was designed and conceived by James Gosling, Patrick Naughton, Chris Warth, Ed Frank and Mike Sherdan, which was done at Sun Microsystems in year 1991.
  • It took almost 18 months for java to come into existence as a working version.
  • Initially java was known as “Oak”, which was then renamed as “Java” in year 1995. Since java had much had much of its character designed from C and C++.
  • This character inherited by the two well known and simple programming makes java more appealing to computer and it giants which would lead to a large scale success.
  • But java is misunderstood as the sophisticated internet version representation of C++.
  • It has significant difference practically and philosophically when compared to C++.
  • If you have good knowledge in C++ then you will find java as your cup of tea and you will at ease using and understanding java.

Therefore, there are two main reasons for the evolution of the computer languages. Java had enhanced and refined the object oriented scenario of C++. This gave more features to the users which are as follows:

  •  Multithreading.
  • Library which would provide easy internet access.
  • One of the java’s magic was the byte code. Byte code is set of instruction which is highly optimized and designed to be executed by JVM (Java Virtual Machine). It is an interpreter for byte code. This lead to the design of truly portable programs.

Java redesigned the internet with new feature and networked program which are as follows:

  • Applets - It is a kind of java program that is to be transmitted over and executedautomatically by java compatible web browsers.
  • Security - It provided the security of downloading various applets and programs from internet without containing any virus or Trojan horses.
  • Portability- Since there is large and different kind of operating systems therefore it provides the freedom of running in any operating system so its program can be used in different OS without any issues of compatibility.

The evolutions in java are as follows:

  • Java 1.0
  • Java 1.1
  • Java 1.2
  • J2SE
  • J2SE 1.2
  • J2SE 1.3
  • J2SE 1.4
  • J2SE 5
  • J2SE 5 made various changes to Java 

The new feature that was added is as follow:

  • Generics
  • Annotations
  • Auto boxing and auto-unboxing
  • Enumerations
  • Enhanced, for-each style for loop
  • Variable-length arguments
  • Static import
  • Formatted I/O
  • Concurrency utilities
 In J2SE 5, and the developers kit was called JDK 5. 1.5 used as internal version numberand this is referred as developer version number.Java became the center of innovation in computer technological world. The existence ofJVM and byte code changed the scenario of security and portability in the programmingworld. The way the new ideas are put into the language has been redefined by the JCP i.e.java community process.
<<Previous                        Downlod PDF                        Next>>

Related Questions:


    C : Program to Implement Queue Using Array

    Code:

    /*
     * C Program to Implement a Queue using an Array
     */
    #include <stdio.h>
     
    #define MAX 50
    int queue_array[MAX];
    int rear = - 1;
    int front = - 1;
    main()
    {
        int choice;
        while (1)
        {
            printf("1.Insert element to queue \n");
            printf("2.Delete element from queue \n");
            printf("3.Display all elements of queue \n");
            printf("4.Quit \n");
            printf("Enter your choice : ");
            scanf("%d", &choice);
            switch (choice)
            {
                case 1:
                insert();
                break;
                case 2:
                delete();
                break;
                case 3:
                display();
                break;
                case 4:
                exit(1);
                default:
                printf("Wrong choice \n");
            } /*End of switch*/
        } /*End of while*/
    } /*End of main()*/
    insert()
    {
        int add_item;
        if (rear == MAX - 1)
        printf("Queue Overflow \n");
        else
        {
            if (front == - 1)
            /*If queue is initially empty */
            front = 0;
            printf("Inset the element in queue : ");
            scanf("%d", &add_item);
            rear = rear + 1;
            queue_array[rear] = add_item;
        }
    } /*End of insert()*/
     
    delete()
    {
        if (front == - 1 || front > rear)
        {
            printf("Queue Underflow \n");
            return ;
        }
        else
        {
            printf("Element deleted from queue is : %d\n", queue_array[front]);
            front = front + 1;
        }
    } /*End of delete() */
    display()
    {
        int i;
        if (front == - 1)
            printf("Queue is empty \n");
        else
        {
            printf("Queue is : \n");
            for (i = front; i <= rear; i++)
                printf("%d ", queue_array[i]);
            printf("\n");
        }
    } /*End of display() */

    Output:

    Related Links:

    • http://www.sanfoundry.com/c-program-queue-using-array/


    C++ : Implement stack using array

    Code:

    // Stack - Object oriented implementation using arrays
    #include <iostream>
    using namespace std;
    #define MAX_SIZE 101
    class Stack
    {
    private:
    int A[MAX_SIZE]; // array to store the stack
    int top; // variable to mark the top index of stack.
    public:
    // constructor
    Stack()
    {
    top = -1; // for empty array, set top = -1
    }
    // Push operation to insert an element on top of stack.
    void Push(int x)
    {
    if(top == MAX_SIZE -1) { // overflow case.
    printf("Error: stack overflow\n");
    return;
    }
    A[++top] = x;
    }
    // Pop operation to remove an element from top of stack.
    void Pop()
    {
    if(top == -1) { // If stack is empty, pop should throw error.
    printf("Error: No element to pop\n");
    return;
    }
    top--;
    }
    // Top operation to return element at top of stack.
    int Top()
    {
    return A[top];
    }
    // This function will return 1 (true) if stack is empty, 0 (false) otherwise
    int IsEmpty()
    {
    if(top == -1) return 1;
    return 0;
    }
    // ONLY FOR TESTING - NOT A VALID OPERATION WITH STACK
    // This function is just to test the implementation of stack.
    // This will print all the elements in the stack at any stage.
    void Print() {
    int i;
    printf("Stack: ");
    for(i = 0;i<=top;i++)
    printf("%d ",A[i]);
    printf("\n");
    }
    };
    int main()
    {
    // Code to test the implementation.
    // calling Print() after each push or pop to see the state of stack.
    Stack S;
    S.Push(2);S.Print();
    S.Push(5);S.Print();
    S.Push(10);S.Print();
    S.Pop();S.Print();
    S.Push(12);S.Print();
    }

    Output:

    Related Video:

    Related Links:

    Related Programs:

    C Programming Online Test 1

    Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answ...