Wednesday, October 9, 2013

How to use MASAM for Assembly Coding.

This tutorial will guide you how to assemble .asm files using MASAM via command prompt

Mini Compiler for C language [Compiler Construction Project]

Compiler construction: Mini Compiler
Design and implement a compiler for the programming language having the following specifications:

Thursday, August 1, 2013

File Compressor in C++

Hello friends, Here is the code of File Compressor...

The main features of this program are:

  1. Works like note pad (i.e create, open, save , text document )
  2. Can generate random bits of data
  3. Can compress binary data (i.e If there are 10 or more 1’s consecutively replace them +10+, +11+, ... +20+, …..  OR in case of 0’s replace them -10-, -11-,-12-, ....... -20-, ....
  4. Can uncompressed data (i..e replace +10+ with '1111111111' , -10-, '000000000' , ....... )
  5. GUI interface,........
Pictorial View:






Codding:
void CompressFile(HWND hWnd, HWND hEdit)
{
int len = GetWindowTextLength(hEdit);
if(len <= 0)
{
MessageBox(hWnd,"THERE IS NO TEXT TO COMPRESS",ERROR,MB_OK);
return;
}
else{
int iChars = len+1;
CHAR* pstrText;
CHAR* compText;
CHAR* buff;
if ((pstrText = (CHAR*) malloc (sizeof (CHAR) * iChars)) != NULL) {
compText = (CHAR*) malloc (sizeof (CHAR) * (iChars));
buff = (CHAR*) malloc (sizeof (CHAR) * iChars);
compText[0] = buff[0] = '\0';
GetWindowText (hEdit, pstrText, iChars);
int i,count_0,count_1;
i = count_0 = count_1 = 0;
char value[10];
while(i<=len)
{
if(pstrText[i] == '1')
{
int l = 0;
while(pstrText[i] == '1')
buff[l++] = pstrText[i++];
buff[l] = '\0';
if(l>=10)
{
strcat(compText,"+");
itoa(l,value,10);
strcat(compText,value);
strcat(compText,"+");
}
else
strcat(compText,buff);
}
else if(pstrText[i] == '0')
{
int l = 0;
while(pstrText[i] == '0')
buff[l++] = pstrText[i++];
buff[l] = '\0';
if(l>=10)
{
strcat(compText,"-");
itoa(l,value,10);
strcat(compText,value);
strcat(compText,"-");
}
else
strcat(compText,buff);
}
else
{
buff[0]=pstrText[i++];
buff[1]='\0';
strcat(compText,buff);
}
}
SetWindowText(hEdit, compText);
free (buff);
free (pstrText);
free (compText);
}
}
}
void UncompressFile(HWND hWnd, HWND hEdit)
{
int len = GetWindowTextLength(hEdit);
if(len <= 0)
{
MessageBox(hWnd,"THERE IS NO TEXT TO UNCOMPRESS",ERROR,MB_OK);
return;
}
else{
int iChars = len+1;
CHAR* pstrText;
CHAR* uncompText;
CHAR* buff;
if ((pstrText = (CHAR*) malloc (sizeof (CHAR) * iChars)) != NULL) {
buff = (CHAR*) malloc (sizeof (CHAR) * iChars);
buff[0] = '\0';
int t_size = 0;
GetWindowText (hEdit, pstrText, iChars);
char str[100];
int i=0;
while(i<=len)
{
if(pstrText[i] == '-'){
int l = 0;
while(pstrText[++i] != '-')
buff[l++] = pstrText[i];
buff[l] = '\0';
t_size = t_size + atoi(buff);
}
else if(pstrText[i] == '+')
{
int l = 0;
while(pstrText[++i] != '+')
buff[l++] = pstrText[i];
buff[l] = '\0';
t_size = t_size + atoi(buff);
}
else
t_size++;
i++;
}
if ((uncompText = (CHAR*) malloc (sizeof (CHAR) * t_size)) != NULL) {
uncompText[0]='\0';
int j=0;
i=0;
while(i
{
if(pstrText[i] == '-')
{
int l = 0;
while(pstrText[++i] != '-')
buff[l++] = pstrText[i];
buff[l] = '\0';
t_size = atoi(buff);
int k = 0;
while(k < t_size)
{uncompText[j++] = '0';k++;}
}
else if(pstrText[i] == '+')
{
int l = 0;
while(pstrText[++i] != '+')
buff[l++] = pstrText[i];
buff[l] = '\0';
t_size = atoi(buff);
int k = 0;
while(k < t_size)
{uncompText[j++] = '1';k++;}
}
else
uncompText[j++] = pstrText[i];
i++;
}
uncompText[j]='\0';
SetWindowText(hEdit, uncompText);
free (uncompText);
}
free(pstrText);
free(buff);
}
}
}
//Genrate Random Bits
void GenrateRandomBits(HWND hWnd, HWND hEdit)
{
char randomData[10000];
randomData[0] = '\0';
char Buff[2];
int randomBit;
for (int i = 0; i < 8000; i++)
{
randomBit = rand()%2;
itoa(randomBit,Buff,10);
strcat(randomData,Buff);
}
SetWindowText(hEdit, randomData);
}
view raw filecompressor hosted with ❤ by GitHub
   

Thursday, May 23, 2013

Simulated Annealing Algorithm


Simulated Annealing Algorithm:

    This algorithm overcomes all the problems occurred in Hill Climbing (i.e Stuck on Flat, local maximum, stuck on shoulder). It randomly chooses current node, basis on the temperature  schedule and the probability of choosing  next node.

 Below picture show the actual algorithm of simulated annealing. you can download full project code on the link given at the end.


#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
using namespace std;
class Node
{
public:
int state;
int value;
Node *ch1;
Node *ch2;
Node *ch3;
Node *ch4;
Node()
{
ch1=NULL;
ch2=NULL;
ch3=NULL;
ch4=NULL;
value=0;
}
} *root;
int level = 2;
Node* best;
void Problem(Node *current,Node * Parent,int c_level)
{
cout<<endl<<"Enter Value: ";
cin>>current->value;
current->ch1 = Parent;
if( c_level < level)
{
current->ch2 = new Node;
Problem(current->ch2, current, c_level + 1);
current->ch3 = new Node;
Problem(current->ch3, current, c_level + 1);
current->ch4 = new Node;
Problem(current->ch4, current, c_level + 1);
}
else
{
current->ch2 = Parent;
current->ch3 = Parent;
current->ch4 = Parent;
}
}
Node * SimulatedAnnealing(Node * current)
{
int temprature = 50000;
int rand1,E;
float rand2, p;
Node *next = new Node;
srand(time(NULL));
while(true)
{
temprature = temprature*0.99;
if(temprature == 0)return best;
rand1 = rand()%4+1;
if(rand1==1 && current->ch1!=NULL)
next=current->ch1;
else if(rand1==2 && current->ch2!=NULL)
next=current->ch2;
else if(rand1==3 && current->ch3!=NULL)
next=current->ch3;
else if(rand1==4 && current->ch4!=NULL)
next=current->ch4;
E = next->value - current->value;
if(E > 0)
{
current = next;
cout<<endl<<"CURRENT NODE:"<<current->value;
if(best->value<current->value)
best = current;
}
else
{
p = pow(2.71,(E/temprature));
rand2 = p;
if(rand2 < p)
{
current = next;
if(best->value<current->value)
best = current;
// cout<<endl<<"CURRENT NODE:"<<current->value;
}
}
}
}
int main()
{
int c_level = 0;
root = new Node;
best = root;
Problem(root, NULL, c_level);
Node *best = SimulatedAnnealing(root);
cout<<"Result : "<<best->value;
getch();
return 0;
}
view raw sa_algo_ai hosted with ❤ by GitHub

Thursday, April 18, 2013

Data Structure Project


Screen Shots:




 









 


 Data Structure Project Demonstration of Stack, Ques, Single Link list and Double Link List. This project is build in DEV C++ using BGI Borland Graphics. Please read how to add graphics in dev C++ before compiling and executing the modified code.

DOWNLOAD PROJECT

Tuesday, April 9, 2013

Armstrong numbers in c++

If sum of cubes of each digit of the number is equal to the number itself, then the number is called an Armstrong number.

For example, 153 = ( 1 * 1 * 1 ) + ( 5 * 5 * 5 ) + ( 3 * 3 * 3 )
        
Write a program that prints all Armstrong numbers from 1-1000.


Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int rem,res,div;
for(int i = 1; i<=1000; i++)
{
rem = i%10;
div = i/10;
res = rem*rem*rem;
if(div>=1)
{
rem = div%10;
div = div/10;
res = res + rem*rem*rem;
if(div>=1)
{
rem = div%10;
div = div/10;
res = res + rem*rem*rem;
}
}
if(res == i)
cout<<res<<endl;
}
getch();
return 0;
}
view raw main.c hosted with ❤ by GitHub



OUTPUT:


Tuesday, April 2, 2013

Message Encryption/ Decryption Software in C#

SCREEN SOOTS:

MAIN SCREEN


Playfair Cipher Encryption/Decryption



Monoalphabetic Encryption/Decrption


Description:
   This project is developed in C# Visual Studio 2010. I have implemented Playfair and monoalphabetic Encrption/Decryption Algorithms.

DOWNLOAD:
https://docs.google.com/file/d/0B8-JebQ_QBSEdzRJcHZVOElPcnM/edit?usp=sharing

Monday, April 1, 2013

Solar System in C++ Computer Graphics

Solar System using Circle formula in computer Graphics.





Computer Graphics Assignment implementing solar system via coding circle formula.

ANGLE CALCULATING FORMULAS
x=(dist*cos(theta*PI) + sin(theta*PI))+350;
y=(dist*sin(theta*PI)+cos(theta*PI))+350;

Download Project Files Here:

https://docs.google.com/file/d/1QS9rNJ-n7IiFQ0cjrDgs4f-4xM3aOm5Iarbpz-tHj67XNo0tddm_xjUlCrzS/edit?usp=sharing


Sunday, March 31, 2013

Photo Editor | Universal Filter in C#

SCREEN SHOTS:







This project is built in MS Visual Studio 2012 using C#. I have added Universal Filter option and blur options to edit the image. You can comment below if you need any information in understanding the code.

DOWNLOAD PROJECT HERE:


Saturday, March 30, 2013

MINI PAINT in C++

MINI PAINT IN C++ SCREEN SHOT:




This project is created using graphics.h header file in DEV C++. Please read my post how to add graphics in dev c++  before using this code.

Download the code from Git Hub:

Leave comment if you have any problem in using this code.

Friday, March 29, 2013

TIC TAC TOE Game in C++


Screen Shoots:


Download Project: 


Description:

   This project is Developed in C++ using BGI Graphics. Read my post How to add graphics.h in dev C++ if you are new to BGI Graphics.

You can post comment here to get help from me.

Thursday, March 28, 2013

Graphical Analog Clock in C++


Graphical Analog Clock Project in C++. This project is developed using OOP concepts. If you feel any problem comment below we can help you.
Get Source Code here
or follow this link 

How to add graphics.h header file in dev c++

You may be wondering how to add graphics.h in dev C++. Dev C++ does not support BGI Graphics we have to include graphics library manually. Here are few steps you must follow before using graphics.h header file. .
Download following files to the directories mentioned:
graphics.h   Directory:> C:\Dev-Cpp\include
libbgi.a        Directory:> download to C:\Dev-Cpp\lib)

Creating Project:

  • STEP 1:  Open DEV C++ Compiler
                    Launch DEV C++ compiler.
  • STEP 2:  Creating New Project
                   i. Go to File>New>Project as shown in following figure:


                   ii. Create New Project "DialogBox" will appear select "empty project"
                       and name your project in the space provided. Select Language
                       C or C++ according to your need. Press Ok and select the
                       location where you want to save.
                   
  • STEP 4: Set linker parameters 
                 Navigate to "Project" menu and choose "Project Options". A dialogbox
                 will appear than select "Parameters" option and type following in
                  "Linker" field.
                 -lbgi
                 -lgdi32
                 -lcomdlg32
                 -luuid
                 -loleaut32
                 -lole32
                           

Press OK, you are now able to use graphics.h functions in your code.
  • STEP 5: Testing sample Program
               In new versions of dev c++ compiler automatically adds one source file to
               project. If there is no any existing source file simply add new file By
               chossing new file option from file menu. Type  the following code and
               save the file. I saved file as "main.cpp" its your chooice whatever you
               name it.
#include<graphics.h>
int main( ){
initwindow( 700 , 700 , "MY First Program");
circle(200, 200, 150);
getch();
return 0;
}
view raw example_1_bgi hosted with ❤ by GitHub

             

  • STEP 6: Compiling and Runing the program
          If you have followed all the steps carefully after compiling and runing the
          program your output should be somthing like this:
                       
  •  STEP 7: Find more functions
             Follow these links for more functions of graphics.h
              1. http://www.programmingsimplified.com/c/graphics.h
              2. http://www.cs.colorado.edu/~main/bgi/doc/initgraph.html
              3. http://www.cs.colorado.edu/~main/bgi/doc/

You can comment here if you have any trouble.