My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Tuesday, December 26, 2017

Program for 2D reflection along Y-axis (using graphics.h)















#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include<math.h>

int main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3;

  //initgraph(&gd,&gm,"c:\tc\bg:");
            initwindow(1200,600);
             printf("\n\t Enter the three points of a triangle: ");
            setcolor(6);
            setlinestyle(0,0,3);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            setcolor(4);

                                   line(x1,y1+240,x2,y2+240);
                                    line(x2,y2+240,x3,y3+240);
                                    line(x3,y3+240,x1,y1+240);
                                    getch();

                         closegraph();
                  }

Program for 2D reflection in C along X-axis (using graphics.h)




















#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include<math.h>

int main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3;

  //initgraph(&gd,&gm,"c:\tc\bg:");
            initwindow(1200,600);
             printf("\n\t Enter the three points of a triangle: ");
            setcolor(6);
            setlinestyle(0,0,3);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            setcolor(4);

                                   line(x1,y1+240,x2,y2+240);
                                    line(x2,y2+240,x3,y3+240);
                                    line(x3,y3+240,x1,y1+240);
                                    getch();

                         closegraph();
                  }

Program for 2D schearing in C (using graphics.h)

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include<math.h>

int main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3;
            int shx,shy;


             initwindow(1200,600);
             printf("\n\t Enter the three points of a triangle: ");
            setcolor(6);
            setlinestyle(0,0,3);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            setcolor(4);
     
                                 printf("\n Enter the shearing factor");
                                    scanf("%d%d",&shx,&shy);
                                    nx1=x1+y1*shx;
                                    ny1=y1+x1*shy;
                                    nx2=x2+y2*shx;
                                    ny2=y2+x2*shy;
                                    nx3=x3+y3*shx;
                                    ny3=y3+x3*shy;
                                    line(nx1,ny1,nx2,ny2);
                                    line(nx2,ny2,nx3,ny3);
                                    line(nx3,ny3,nx1,ny1);
                                    getch();

                         closegraph();
                  }

Program for 2D scaling in c (using graphics.h)

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include<math.h>

int main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3;
            int sx,sy;


             initwindow(1200,600);
             printf("\n\t Enter the three points of a triangle: ");
            setcolor(6);
            setlinestyle(0,0,3);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            setcolor(4);
            printf("\n Enter the scalling factor");
            scanf("%d%d",&sx,&sy);
       
                                   line(x1*sx,y1*sy,x2*sx,y2*sy);
                                    line(x2*sx,y2*sy,x3*sx,y3*sy);
                                    line(x3*sx,y3*sy,x1*sx,y1*sy);
                                    getch();

                         closegraph();
                  }

Program for 2D translation in C (using graphics.h)

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include<math.h>

int main()
{
            int gm;
            int gd=DETECT;
            int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3;
            int xt,yt;


             initwindow(1200,600);
             printf("\n\t Enter the three points of a triangle: ");
            setcolor(6);
            setlinestyle(0,0,3);
            scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
            line(x1,y1,x2,y2);
            line(x2,y2,x3,y3);
            line(x3,y3,x1,y1);
            setcolor(4);
       
                                    printf("\n Enter the translation factor");
                                    scanf("%d%d",&xt,&yt);
                                    nx1=x1+xt;
                                    ny1=y1+yt;
                                    nx2=x2+xt;
                                    ny2=y2+yt;
                                    nx3=x3+xt;
                                    ny3=y3+yt;
                                    line(nx1,ny1,nx2,ny2);
                                    line(nx2,ny2,nx3,ny3);
                                    line(nx3,ny3,nx1,ny1);
                                    getch();

                         closegraph();
                  }

Tuesday, December 19, 2017

C++ program to draw a circle and ellipse in a single window (using graphics.h)

















#include <graphics.h>
#include <iostream>
#include <conio.h>
using namespace std;
void circle();
void ellipse();
void plotpoints(int,int,int,int);
int main(){

int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");

circle();

ellipse();
getch();
closegraph();
return 0;
}

void circle()
{
    int x,y,p,xc,yc,r;
    cout<<"Enter co-ordinate for centre of circle:";
cin>>xc>>yc;
cout<<"Enter radius of circle: ";
cin>>r;

x = 0;
y = r;
p = 1-r;
while(x<=y){
if(p<0){
x=x+1;
y=y+0;
p=p+2*x +1;
}
else{
x=x+1;
y=y-1;
p=p+2*x-2*y+1;
}
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc+y,yc-x,WHITE);
putpixel(xc-x,yc-y,WHITE);
putpixel(xc-y,yc-x,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-y,yc+x,WHITE);
delay(50);
}
}

void ellipse()
{
    int x,y,p,xc,yc,rx,ry;
    cout<<"Enter co-ordinate for centre of ellipse:";
cin>>xc>>yc;
cout<<"Enter the value of rx and ry of ellipse: ";
cin>>rx>>ry;
x=0;
y=ry;
p=ry*ry-ry*rx*rx+(1/4)*rx*rx;
while((2*ry*ry*x)<(2*rx*rx*y))
{
    if(p<0)
    {
        p=p+2*x*ry*ry+ry*ry;
        x=x+1;
        y=y+0;

    }
    else
    {
        p=p-2*y*rx*rx+2*x*ry*ry+ry*ry;
        x=x+1;
        y=y-1;
    }

    plotpoints(x,y,xc,yc);

}
p=(x+0.5)*(x+0.5)*ry*ry+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
while(y>0)
{
    if(p<0)
    {
        x=x+1;
        y=y-1;
        p=p+2*x*ry*ry+rx*rx-2*y*rx*rx;
    }
    else
    {
        x=x+0;
        y=y-1;
        p=p+rx*rx-2*y*rx*rx;
    }
plotpoints(x,y,xc,yc);


}

}
void plotpoints(int x,int y,int xc,int yc)
{
    putpixel(x+xc,y+yc,WHITE);
    putpixel(-x+xc,y+yc,WHITE);
    putpixel(x+xc,-y+yc,WHITE);
    putpixel(-x+xc,-y+yc,WHITE);
    delay(50);
}
                                                                                                                                                                                                                       

Monday, December 18, 2017

C++ program to draw an ellipse using Mid-point algorithm (using graphics.h)

#include<math.h>
#include <graphics.h>
#include <iostream>
#include <conio.h>
using namespace std;
void plotpoints(int,int,int,int);
int main(){
int xc,yc,x,y,p,rx,ry;
int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
cout<<"Enter co-ordinate for centre of ellipse:";
cin>>xc>>yc;
cout<<"Enter the value of rx and ry of ellipse: ";
cin>>rx>>ry;
x=0;
y=ry;
p=ry*ry-ry*rx*rx+(1/4)*rx*rx;
while((2*ry*ry*x)<(2*rx*rx*y))
{
    if(p<0)
    {
        p=p+2*x*ry*ry+ry*ry;
        x=x+1;
        y=y+0;

    }
    else
    {
        p=p-2*y*rx*rx+2*x*ry*ry+ry*ry;
        x=x+1;
        y=y-1;
    }

    plotpoints(x,y,xc,yc);

}
p=(x+0.5)*(x+0.5)*ry*ry+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
while(y>0)
{
    if(p<0)
    {
        x=x+1;
        y=y-1;
        p=p+2*x*ry*ry+rx*rx-2*y*rx*rx;
    }
    else
    {
        x=x+0;
        y=y-1;
        p=p+rx*rx-2*y*rx*rx;
    }
plotpoints(x,y,xc,yc);


}

getch();
closegraph();
return 0;
}
void plotpoints(int x,int y,int xc,int yc)
{
    putpixel(x+xc,y+yc,WHITE);
    putpixel(-x+xc,y+yc,WHITE);
    putpixel(x+xc,-y+yc,WHITE);
    putpixel(-x+xc,-y+yc,WHITE);
    delay(50);
}

C++ program to draw a circle using Mid-point algorithm (using graphics.h)

#include <graphics.h>
#include <iostream>
#include <conio.h>
using namespace std;
int main(){
int xc,yc,x,y,p,r;
int gdriver = DETECT, gmode;
initgraph(&gdriver,&gmode,"c:\\turboc3\\bgi");
cout<<"Enter co-ordinate for centre of circle:";
cin>>xc>>yc;
cout<<"Enter radius of circle: ";
cin>>r;
x = 0;
y = r;
p = 1-r;
while(x<=y){
if(p<0){
x=x+1;
y=y+0;
p=p+2*x +1;
}
else{
x=x+1;
y=y-1;
p=p+2*x-2*y+1;
}
putpixel(xc+x,yc+y,WHITE);
putpixel(xc+y,yc+x,WHITE);
putpixel(xc+x,yc-y,WHITE);
putpixel(xc+y,yc-x,WHITE);
putpixel(xc-x,yc-y,WHITE);
putpixel(xc-y,yc-x,WHITE);
putpixel(xc-x,yc+y,WHITE);
putpixel(xc-y,yc+x,WHITE);
delay(100);
}

getch();
closegraph();
return 0;
}

C++ program to draw a line using Bresenham's algorithm (using graphics.h)

#include<iostream>
#include<graphics.h>
using namespace std;
void drawline(int,int,int,int);
int main(){
    int gdriver=DETECT, gmode, x1, y1, x2, y2;
    initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");
    cout<<"Enter co-ordinates of start point: ";
    cin>>x1>>y1;
    cout<<"Enter co-ordinates of end point: ";
    cin>>x2>>y2;
    drawline(x1, y1, x2, y2);
    getch();
    closegraph();
    return 0;

}
void drawline(int x1,int y1,int x2,int y2 )
{
    int dx,dy,xinc,yinc,x,y,k,pk;
    dx=x2-x1;
    dy=y2-y1;
    if(x2>x1)
        xinc=1;
    else
        xinc=-1;
    if(y2>y1)
        yinc=1;
    else
        yinc=-1;
    if(abs(dx)>abs(dy)){
        x=x1;
        y=y1;
        pk=2*dy-dx;
        for(k=0;k<=dx;k++)
        {
            if(pk<0)
            {
                putpixel(x,y,RED);
                x=x+xinc;
                y=y+0;
                pk=pk+2*dy;
            }
            else{
                putpixel(x,y,RED),
                x=x+xinc;
                y=y+yinc;
                pk=pk+2*(dy-dx);
            }
            delay(100);
        }
    }
    else {
        x=x1;
        y=y1;
        pk=2*dx-dy;
        for(k=0;k<=dy;k++)
        {
            if(pk<0)
            {
                putpixel(x,y,RED),
                x=x+0;
                y=y+yinc;
                pk=pk+2*dx;
            }
            else{
                putpixel(x,y,RED),
                x=x+xinc;
                y=y+yinc;
                pk=pk+2*(dx-dy);
            }
                delay(100);
        }
    }

}

C++ Program for drawing line using DAA algorithm (using graphics.h)

#include <graphics.h>
#include <iostream>
#include <math.h>
using namespace std;
int main( )
{
    float x,y,x1,y1,x2,y2,dx,dy,step;
    int i,gd=DETECT,gm;

    initgraph(&gd,&gm,"c:\\turboc3\\bgi");

    cout<<"Enter the value of x1 and y1 : ";
    cin>>x1>>y1;
    cout<<"Enter the value of x2 and y2: ";
    cin>>x2>>y2;

    dx=abs(x2-x1);
    dy=abs(y2-y1);

    if(dx>=dy)
        step=dx;
    else
        step=dy;

    dx=dx/step;
    dy=dy/step;

    x=x1;
    y=y1;

    i=1;
    while(i<=step)
    {
        putpixel(x,y,GREEN);
        x=x+dx;
        y=y+dy;
        i=i+1;
        delay(100);
    }
    getch();
    closegraph();
}

Thursday, December 14, 2017

Android app for my blog (Vj blog)

You can directly access my blog in your android phone through this app.












Click here to download.

Assistant Maya

This android app will help you get your daily class routine delivered to you in the form of voice and also you can schedule your daily plans so that Maya can recall them for you whenever you require.













     Click here to download.

Wednesday, December 13, 2017

FLAG OF NEPAL MADE IN OPENGL



















Click here to download the source code.

Sunday, October 29, 2017

Exploring Thailand: A Five-Day Adventure

It all started one year back (the planning, preparation and some sorts of online researches about that particular country). But because it was a foreign tour and it was the first time for all of us, it took quite a bit more time to gather all the informations, thus it could not happened at that time. we were five members including me, my brother, sister and my parents. Managing the holidays of all five at the same time we decided to go on tour in the first week of October but though we informed our travel agency approximately one month prior to departure, we were late. Since it was the time of holiday in Nepal, all the tickets of Nepal Airlines were booked. Then we were pushed in the last week of October. Actually it was a challenging date because lots of preparations were to made and there were lots of holidays in that month so it took us some time to get visa of Thailand. Before departing for Bangkok ,we were left with only one day to manage all the financial papers ,exchange the cash, make traveller card to meet the requirements of Department of immigration of Nepal. We were lucky enough to get all those things done within few hours (thanks to the holidays for Diwali because of which there was no queue in the bank).
So after all the preparations done, we were ready to fly on 23rd October to Bangkok at 11:15 am.

Day 1

We reached airport at 8:00 am. It took approximately 2 hours to finish all the formalities at the Tribhuvan international airport. Then we waited for one hour in the airport for our flight. It was the first time I was travelling through airway so I was very excited but at the same time I was a bit nervous as well because I had read about the failure of plane's engine and crash of planes frequently in the newspapers. Also there has been frequent rumours about Nepal Airlines that it never fly on time but it was a completely different case with us, it actually flew exactly on time so it was a good experience from what other people have experienced regarding Nepal Airlines. We reached Suvarnabhumi airport at 4:45 pm (time in Bangkok).
It was really an exciting experience to be there. The airport was very huge and of high standard. It required quite few distance to walk to claim for the baggage. Every thing was very well managed there at the airport. We took our baggage and went to gate no. 10 as instructed by our travel agency to wait for their representative to pick up for transfer to Pattaya city. It took about two hours to reach our hotel "Crown Pattaya beach hotel" in Pattaya, from an airport in Bangkok. The hotel was very clean and tidy. The rooms were very good. Though it was the night time I could not resist myself from seeing the beautiful roads fully pitched. Because the road conditions in our country is really bad, I was amazed seeing their roads.
Everywhere there was flyover to reduce the traffic problems. One thing what I noticed was most of the roads were one way only so it was quite easy while crossing the road. When we reached hotel, we checked in there and after putting our luggage in our room, we went to find Indian hotel. Before leaving for Thailand, I had done few research about the food in Thailand. We were actually worried about what type of food we would get there because we were vegetarian and we preferred only Indian food. We thought it would be difficult to find Indian hotel but God is great. Surprisingly, there was a Punjabi hotel 1-2 minutes from our hotel on walking. Though the food was a bit costly 200 Bhats/person, it was actually very tasty and also food was served on buffet system. Lots of varities were provided in the food. Really speaking, it made my night. After having food we went for a walk besides the beach. The trees planted there in systematic and proper manner, the tall buildings nearly above twenty or thirty floors, lightning everywhere was pleasant to see. We then moved to hotel after walk for few minutes. Overnight at hotel and the first day ended this way. 

Day 2


Second day started with a heavy breakfast in the morning at the hotel. Time is much valued in large city, I witnessed that day. We were informed to be picked from lounge of the hotel at 8:00 am and guess what ,they were exactly on time. A lady came exactly at 8:00 am.We then left for Coral island exactly from hotel. It took about ten minutes to reach the Pattaya beach. That day I saw why tourism is largely flourished in Thailand. A lots of people are involved in it. They all have divided their work and more importantly they are very honest towards their work. Time really matters for them. It was the duty of one person to take us to Pattaya beach. At Pattaya beach , already there were two persons waiting for us to take to Coral island. They tied combination of white and pink ribbon in our wrist for an identity that we were their guests. We then waited for their other guests to come. After few minutes, when they arrived we headed to Coral island on a speed boat. It was a thrilling experience on a boat. The boat was really very fast and the tides were also high which added an adventurous feeling to our journey.
On the way there was a station for those who were interested in parasailing. The station was more like a stationary large boat on water with tides shaking it slowly. I am a bit afraid of height so I din't try parasailing though it seemed very interesting watching others fly. We then headed to Coral island. We reached there at approximately 10:00 am.
We had one and half hours to enjoy at the island. The water was crystal clear and sands were as white as powder. We enjoyed alot during that period of time. We enjoyed coconut water. I enjoyed driving Jet Ski. It felt as if one and half hours flew so quickly. As planned before, we left for the city at 11:30 am to have lunch in an Indian restaurant. When we reached the city, on walking only few steps, we show a man having our photographs framed individually with the frame captioned "Pattaya City". We were surprised because we didn't actually remember when did he take our photographs and more importantly for what purpose. Was it a kind of giveaway to their guests? Was it a  kind of tourism attraction? It was a bit confusing but soon we realised that the photos were taken while we were getting onto the boat to drive to Coral island. It was taken so cleverly that it felt like I am actually posing for the camera for someone to take my photographs. What came as surprise that it wasn't any kind of giveaway for the guests, actually it was for sell. It was a kind of business strategy. That's how tourism works. Lots of people involved in it with creative business skills. The photos were priced 100 Bhats for each. We bought our five frames. The photos were really good.

We then had delicious Indian food in the restaurant nearby. The lady who had picked us from the hotel planned a whole day tour in the city. We first went to underwater sea world. It was worth watching huge no. of sea lives at one palce. We spent 1-2 hours there and then headed to Tiger park . The park was made along with restaurants attached to it.
The park was divided into three parts for large, medium and small tigers. We can take photographs with tigers live there at tiger park paying the specified amount at the counter. The rate varies according to the size of tiger you are willing to take photograph with.
To end the day with the last destination in Pattaya city, we headed to floating market. The name says all. Yes, the whole market is floating on water. We took a ride on wooden made small boat around the market. It was a different experience to be there. We sat there for more than an hour to . The market is very famous for its food varities especially sea food, ice cream and some other stores as well. It was already approximately 7 PM when we left for our hotel. We then had food ,and hence day 2 ended travelling and visiting exciting and beautiful place whole day from the morning.

Day 3



After having breakfast at the hotel in the morning, we checked out from the hotel and left for Bangkok city. It was two hour long journey form Pattaya Beach Hotel to Citin Pratunam (hotel at Bangkok). We reached hotel at approximately 11 am. The check in time was 2 pm. So we waited in the longue of the hotel. We completed the required formality at the reception of the hotel, kept our luggage under the security of hotel and then went for temple tour as planned by our travel agency. We visited few temples, shops of GEMS international and then returned back to hotel. The temples were big, well architectured and beautiful. There were dress codes to enter inside the temple. We could have visited few more temples but the roads leading to them were closed to prepare for the death cremation of their late king. Though I felt somewhat bad in my heart but at the same time you have to respect the sentiments of the people towards their king. We then passed the rest of the days shopping in the street market. The street markets were huge with most of the stalls for clothing.

Day 4


It was actually holiday all around Thailand. Very few shops were opened because of the death cremation of the late king. Vehicles were in less number on the road. Almost every Thai people dressed in black dress . Some of them carrying memories of their late king hanging around umbrella in the form of photographs. Various groups of people were distributing food, water, cold drinks etc at various locations to every people passing by them. The love and respect for their king could be easily seen from all this scenario. We felt our one day will be wasted but we made it worth. Withour knowing the destination , we began our journey around the city on foot in the morning hoping to get to know the city more closely.
Walking few minutes from our hotel , we reached near an over bridge. We thought it was for crossing road but when we went up it was actually an airport link railway. This railway line link to the airports in the city from Suvarnabhumi airport to Phaya Thai. We enquired there and came to know that the fare for travelling in the metro was free for couple of days regarding the late king's death cremation. We travelled in the metro from Ratchaprararop to Suvarnabhumi and back to Phaya Thai for free of cost. We returned to hotel, had launch in the nearby Indian restaurant, took some rest back in the hotel room and headed for our next journey, Lumphini Park at approximately 3.7 Km from our hotel. On the way we saw the inner part of Bangkok city with skyscrapers buildings, night markets.
I was amazed to see that scooters were rented there for travelling from one place to another like taxi. As soon as we reached Lumphini Park, it started raining ,thankfully it was not so heavy.
The park was more like Dreamland with every possible beautiful and natural scenario. Water at the middle, small bridges over the water, small boats in duck shape for sailing, everywhere green and tall building when looking in the sky. It felt like staying there for some hours but we were already late to leave for hotel so spending some quality minutes we headed towards our hotel. Had dinner and stayed overnight at the hotel and hence day 4 also ended on a sweet note.

Day 5

It was the last day in Thailand of our tour. We had our flight at 4 pm and we had to leave for airport at 2 pm. So it was not probably one of those days to go far way roaming because of time bound. Hence, we did our rest of shoppings in the nearby markets, had launch in the restaurant and then checked out from hotel to leave fot the airport. The driver who took us to the hotel was very humble, cooperative and funny person. We reached airport in half an hour, completed all the formalities at the airport and said our final bye to Thailand. We reached Tribhuvan airport at 7:15 pm local time and hence our five days journey ended here.

At last, we had lots of fun in those five days, explored new things in life, visited various new places and had opportunities to meet new people whose life style was completely different than ours. Actually, it was a refreshing experience. Though language was a bit of problem but it was sorted on its own.

Thursday, September 28, 2017

A SIMPLE WEB BROWSER MADE IN C#

VJ BROWSER












Click here to download the source file.

Monday, August 7, 2017

CONVERSION FROM LOWER TO UPPERCASE IN 8086 PROGRAMMING

TITLE LOWER TO UPPERCASE
.MODEL SMALL
.STACK 64
.DATA
MAXCHR DB 20
ACTCHR DB ?
ACTSTR DB 20 DUP(?)
RESULT DB 20 DUP(?)
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

MOV DX,OFFSET MAXCHR
MOV AH,0AH
INT 21H

LEA SI,ACTSTR
LEA DI,RESULT
MOV CX,0000H
MOV BX,0000H
LEA BX,ACTCHR
MOV CX,[BX]

L2:
MOV AL,[SI]
CMP AL,61H
JB L1
CMP AL,7AH
JA L1
SUB AL,20H
L1:
MOV [DI],AL
INC SI
INC DI
LOOP L2

MOV DL,0AH
MOV AH,02H
INT 21H

LEA DX,RESULT
MOV AH,09H
INT 21H

MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN

CONVERSION FROM UPPER TO LOWERCASE IN 8086 PROGRAMMING

TITLE UPPER TO LOWER CASE
.MODEL SMALL
.STACK 64
.DATA
MAXCHR DB 20
ACTCHR DB ?
ACTSTR DB 20 DUP(?)
RESULT DB 20 DUP('$')
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

MOV DX,OFFSET MAXCHR
MOV AH,0AH
INT 21H

LEA SI,ACTSTR
LEA DI,RESULT
MOV CX,0000H
MOV BX,0000H
LEA BX,ACTCHR
MOV CX,[BX]

L2:
MOV AL,[SI]
CMP AL,41H
JB L1
CMP AL,5AH
JA L1
ADD AL,20H
L1:
MOV [DI],AL
INC SI
INC DI
LOOP L2

MOV DL,0AH
MOV AH,02H
INT 21H

LEA DX,RESULT
MOV AH,09H
INT 21H

MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN

Monday, July 31, 2017

Tic tac toe game in C

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include <windows.h>



int board[10] = {2,2,2,2,2,2,2,2,2,2};
int turn = 1,flag = 0;
int player,comp;

void menu();
void go(int n);
void start_game();
void check_draw();
void draw_board();
void player_first();
void put_X_O(char ch,int pos);
 COORD coord={0,0}; // this is global variable
                                    //center of axis is set to the top left cornor of the screen
void gotoxy(int x,int y)
{
    coord.X=x;
    coord.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}



 void main()
{
 system("cls");
 menu();
 getch();

}

void menu()
{
 int choice;
 system("cls");
 printf("\n--------MENU--------");
 printf("\n1 : Play with X");
 printf("\n2 : Play with O");
 printf("\n3 : Exit");
 printf("\nEnter your choice:>");
 scanf("%d",&choice);
 turn = 1;
 switch (choice)
 {
  case 1:
   player = 1;
   comp = 0;
   player_first();
   break;
  case 2:
   player = 0;
   comp = 1;
   start_game();
   break;
  case 3:
   exit(1);
  default:
   menu();
 }
}

int make2()
{
 if(board[5] == 2)
  return 5;
 if(board[2] == 2)
  return 2;
 if(board[4] == 2)
  return 4;
 if(board[6] == 2)
  return 6;
 if(board[8] == 2)
  return 8;
 return 0;
}

int make4()
{
 if(board[1] == 2)
  return 1;
 if(board[3] == 2)
  return 3;
 if(board[7] == 2)
  return 7;
 if(board[9] == 2)
  return 9;
 return 0;
}

int posswin(int p)
{
// p==1 then X   p==0  then  O
 int i;
 int check_val,pos;

 if(p == 1)
  check_val = 18;
 else
  check_val = 50;

 i = 1;
 while(i<=9)//row check
 {
  if(board[i] * board[i+1] * board[i+2] == check_val)
  {
   if(board[i] == 2)
    return i;
   if(board[i+1] == 2)
    return i+1;
   if(board[i+2] == 2)
    return i+2;
  }
  i+=3;
 }

 i = 1;
 while(i<=3)//column check
 {
  if(board[i] * board[i+3] * board[i+6] == check_val)
  {
   if(board[i] == 2)
    return i;
   if(board[i+3] == 2)
    return i+3;
   if(board[i+6] == 2)
    return i+6;
  }
  i++;
 }

 if(board[1] * board[5] * board[9] == check_val)
 {
  if(board[1] == 2)
   return 1;
  if(board[5] == 2)
   return 5;
  if(board[9] == 2)
   return 9;
 }

 if(board[3] * board[5] * board[7] == check_val)
 {
  if(board[3] == 2)
   return 3;
  if(board[5] == 2)
   return 5;
  if(board[7] == 2)
   return 7;
 }
 return 0;
}

void go(int n)
{
 if(turn % 2)
  board[n] = 3;
 else
  board[n] = 5;
 turn++;
}

void player_first()
{
 int pos;

 check_draw();
 draw_board();
 gotoxy(30,18);
 printf("Your Turn :> ");
 scanf("%d",&pos);

 if(board[pos] != 2)
  player_first();

 if(pos == posswin(player))
 {
  go(pos);
  draw_board();
  gotoxy(30,20);
  //textcolor(128+RED);
  printf("Player Wins");
  getch();
  exit(0);
 }

 go(pos);
 draw_board();
 start_game();
}

void start_game()
{
 // p==1 then X   p==0  then  O
 if(posswin(comp))
 {
  go(posswin(comp));
  flag = 1;
 }
 else
 if(posswin(player))
  go(posswin(player));
 else
 if(make2())
  go(make2());
 else
  go(make4());
 draw_board();

 if(flag)
 {
  gotoxy(30,20);
  //textcolor(128+RED);
  printf("Computer wins");
  getch();
 }
 else
  player_first();
}

void check_draw()
{
 if(turn > 9)
 {
  gotoxy(30,20);
  //textcolor(128+RED);
  printf("Game Draw");
  getch();
  exit(0);
 }
}

void draw_board()
{
 int j;

 for(j=9;j<17;j++)
 {
  gotoxy(35,j);
  printf("|       |");
 }
 gotoxy(28,11);
 printf("-----------------------");
 gotoxy(28,14);
 printf("-----------------------");

 for(j=1;j<10;j++)
 {
  if(board[j] == 3)
   put_X_O('X',j);
  else
  if(board[j] == 5)
   put_X_O('O',j);
 }
}

void put_X_O(char ch,int pos)
{
 int m;
 int x = 31, y = 10;

 m = pos;

 if(m > 3)
 {
  while(m > 3)
  {
   y += 3;
   m -= 3;
  }
 }
 if(pos % 3 == 0)
  x += 16;
 else
 {
  pos %= 3;
  pos--;
  while(pos)
  {
   x+=8;
   pos--;
  }
 }
 gotoxy(x,y);
 printf("%c",ch);
}

Simple quiz in C

#include<stdio.h>
#include<conio.h>
#include <windows.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>

void displayscore()
 {
 char name[20];
 float s;
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&name,&s);
 printf("\n\n\t\t ");
 printf("\n\n\t\t %s has secured the Highest Score %.2f",name,s);
 printf("\n\n\t\t ");
 fclose(f);
 getch();
 }



void help()
 {
 system("cls");
 printf("\n\n\n\tThis game is very easy to play. You'll be asked some general");
 printf("\n\n\tknowledge questions and the right answer is to be chosen among");
 printf("\n\n\tthe four options provided. Your score will be calculated at the");
 printf("\n\n\tend. Remember that the more quicker you give answer the more");
 printf("\n\n\tscore you will secure. Your score will be calculated and displayed");
 printf("\n\n\tat the end and displayed. If you secure highest score, your score");
 printf("\n\n\twill be recorded. So BEST OF LUCK.");
 }
void writescore(float score, char plnm[20])
 {
 float sc;
 char nm[20];
 FILE *f;
 system("cls");
 f=fopen("score.txt","r");
 fscanf(f,"%s%f",&nm,&sc);
 if (score>=sc)
   { sc=score;
     fclose(f);
     f=fopen("score.txt","w");
     fprintf(f,"%s\n%.2f",plnm,sc);
     fclose(f);
   }
 }
int main()
     {
     int countq,countr;
     int r,i;
     int pa;int nq[6];int w;
     float score;
     char choice;
     char playername[20];
     time_t initialtime,finaltime;
     system("cls");
     //randomize();
     mainhome:
     system("cls");
     puts("\n\t\t WELCOME TO I.Q. TEST PROGRAM\n\n") ;
     puts("\n\t\t-------------------------------");
     puts("\n\t\t Enter 'S' to start game       ");
     puts("\n\t\t Enter 'V' to view high score  ");
     puts("\n\t\t Enter 'H' for help            ");
     puts("\n\t\t Enter 'Q' to quit             ");
     printf("\n\t\t-------------------------------\n\n\t\t  ");
     choice=toupper(getch());
     if (choice=='V')
 {
 displayscore();
 goto mainhome;
 }
     else if (choice=='Q')
 exit(1);
     else if (choice=='H')
 {
 help();
 getch();
 goto mainhome;
 }
    else if(choice=='S'){
     system("cls");

     printf("\n\n\n\t\t\tEnter your name...");
     printf("\n\t\t\t(only one word)\n\n\t\t\t");
     gets(playername);

     home:
     system("cls");
     initialtime=time(NULL);
     countq=countr=0;
     i=1;
     start:
     srand ( time(NULL) );
     r=rand()%23+1;
     nq[i]=r;
     for (w=0;w<i;w++)
 if (nq[w]==r) goto start;

     switch(r)
  {
  case 1:
  printf("\n\nWhat is the maximum no. of asymptotes of the curve x^4+2x+6=0?");
  printf("\n\nA.4\tB.3\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.4");break;}

  case 2:
  printf("\n\n\nHow many points are possible in a compound pendulum about which");
  printf("time period is same?");
  printf("\n\nA.4\tB.2\n\nC.none\tD.infinite\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         printf("\n\nWrong!!! The correct answer is A.4");
  break;

  case 3:
  printf("\n\n\nWho was the first US President?");
  printf("\n\nA.Richard Nikson\tB.Abraham Linkon\n\nC.John F. Kennedy\tD.George Washington\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.George Washington");break;}


  case 4:
  printf("\n\n\nWho was awarded the 'Man of the Tournament' of ICC WORLD CUP 2007?");
  printf("\n\nA.Glen Magrath\tB.Mahela Jawardan\n\nC.Mathew Hayden\tD.Sachin Tendulkar\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Glen Magrath");break;}


  case 5:
  printf("\n\n\nWhich country won the Fifa World Cup 1998?");
  printf("\n\nA.France\tB.Brazil\n\nC.Italy\tD.England\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.France");break;}

  case 6:
  printf("\n\n\nWhich syllabe is stressed in the word 'democracy'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='B' )
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.2nd");break;}


  case 7:
  printf("\n\n\nWhich country was the winner of Cricket World Cup 1987?");
  printf("\n\nA.West Indies\tB.India\n\nC.Australia\tD.England\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Australia");break;}


  case 8:
  printf("\n\n\nWhat is the height of Mount everest in feet?");
  printf("\n\nA.8648\tB.6648\n\nC.8884\tD.8848\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.8848");break;}


  case 9:
  printf("\n\n\nWhat is the capital of Denmark?");
  printf("\n\nA.Copenhagen\tB.Helsinki\n\nC.Rome\t\tD.Madrid\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Copenhagen");break;}


  case 10:
  printf("\n\n\nWhich syllabe is stressed in the word 'instanteneous'?");
  printf("\n\nA.1st\tB.2nd\n\nC.3rd\tD.4th\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.3rd");break;}


  case 11:
  printf("\n\n\nWho was the only player to score 6 successive sixes in an over?");
  printf("\n\nA.Adam Gilchrist\tB.M.S.Dhoni\n\nC.Herschel Gibbs\tD.Sanath Jayasurya\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Herschel Gibbs");break;}

  case 12:
  printf("\n\n\nWho was the only player to take 4 successive wickets?");
  printf("\n\nA.Malinga Bandara\tB.Lasith Malinga\n\nC.Bret Lee\tD.Murali Daran\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lasith Malinga");break;}

  case 13:
  printf("\n\n\nWhich country is hosting the Fifa World Cup 2010?");
  printf("\n\nA.South Africa\tB.Italy\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.South Africa");break;}

  case 14:
  printf("\n\n\nWho is the author of 'Pulpasa Cafe'?");
  printf("\n\nA.Narayan Wagle\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\tD.Khagendra Sangraula\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");break;}

  case 15:
  printf("\n\n\nWhich country is Maria Sarapova from?");
  printf("\n\nA.Russia\tB.Switzerland\n\nC.Argentina\tD.Spain\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Russia");break;}

  case 16:
  printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?");
  printf("\n\nA.Wayne Rooney\tB.Lucas Podolski\n\nC.Lionel Messi\tD.Christiano Ronaldo\n\n");
  countq++;
  if (toupper(getch())=='B')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski");break;}


  case 17:
  printf("\n\n\nWhat is the smallest district of Nepal?");
  printf("\n\nA.Lalitpur\tB.Karnali\n\nC.Bhaktapur\tD.Gulmi\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Bhaktapur");break;}

  case 18:
  printf("\n\n\nWhat is the headquarter of Western Development Region?");
  printf("\n\nA.Dhankuta\tB.Kathmandu\n\nC.Dhangadhi\tD.Pokhara\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Pokhara");break;}

  case 19:
  printf("\n\n\nWhich place is called 'The Cherrapunji of Nepal'?");
  printf("\n\nA.Dharan\tB.Kathmandu\n\nC.Pokhara\tD.Butwal\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Pokhara");break;}

  case 20:
  printf("\n\n\nWhich city is known at 'The City of Seven Hills'?");
  printf("\n\nA.Rome\tB.Vactican City\n\nC.Madrid\tD.Berlin\n\n");
  countq++;
  if (toupper(getch())=='A')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is A.Rome");break;}

  case 21:
  printf("\n\n\nWho was the F1 racing champion of 2006?");
  printf("\n\nA.Louis Hamilton\tB.Felipe Massa\n\nC.Fernando Alonso\tD.Michael Schumaker\n\n");
  countq++;
  if (toupper(getch())=='C')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is C.Fernanda Alonso");break;}

  case 22:
  printf("\n\n\nWho won the Women Australian Open 2007?");
  printf("\n\nA.Martina Hingis\tB.Maria Sarapova\n\nC.Kim Clijster\tD.Serena Williams\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.Serena Williams");break;}

  case 23:
  printf("\n\n\nName the country where there no mosquito is found?");
  printf("\n\nA.Germany\tB.Spain\n\nC.Japan\tD.France\n\n");
  countq++;
  if (toupper(getch())=='D')
   {printf("\n\nCorrect!!!");countr++; break;}
  else
         {printf("\n\nWrong!!! The correct answer is D.France");break;}



  }
 i++;
 if (i<=5) goto start;
 finaltime=time(NULL);
 score=(float)countr/countq*100-difftime(finaltime,initialtime)/3;
 if (score<0) score=0;
 printf("\n\n\nYour Score: %.2f",score);
 if (score==100) printf("\n\nEXCELLENT!!! KEEP IT UP");
 else if (score>=80 && score<100) printf("\n\nVERY GOOD!!");
 else if (score>=60 &&score<80) printf("\n\nGOOD! BUT YOU NEED TO KNOW MORE.");
 else if (score>=40 && score<60) printf("\n\nSATISFACTORY RESULT, BUT THIS MUCH IS MUCH SUFFICIENT.");
 else printf("\n\nYOU ARE VERY POOR IN G.K.,WORK HARD");
 puts("\n\nNEXT PLAY?(Y/N)");
 if (toupper(getch())=='Y')
  goto home;
 else
  {
  writescore(score,playername);
  goto mainhome;
  }
 }
     else
 {
 printf("\n\n\t\t  Enter the right key\n\n\t\t  ");
 Sleep(700);
 goto mainhome;
 }
 return 0;
}