Posts

Showing posts with the label coding

Blackjack Console game program in Python

Image
Console Games Games that can be played using the console. Here is the program for the Blackjack Game of the cards. BlackJack Game Blackjack  is the American variant of a globally popular  banking game  known as  Twenty-One. in this game, one player has to make the total sum of their hands to lower than 21 to win while another player has the total sum is 21 or more, All the cards greater than 10 are considered as the 10 and Ace is considered as the 11 or 1 depending on conditions. The person who has less total of the cards is the winner (one player should have scored more than 21). import random class blackJack: player1Hand = 0 player2Hand = 0 deck ={'Ace of Spades':1, '2 of Spades':2, '3 of Spades':3, '4 of Spades':4, '5 of Spades':5, '6 of Spades':6, '7 of Spades':7, '8 of Spades':8, '9 of Spades':9, '10 of Spades':10, 'Jack of Spades':10, 'Queen of Spades':10, 'King of

File Handling in C (Reading a file line by line)

Image
In this tutorial, we are working with the files in the C. File handling in any language requires Three main steps to follow Open the file in Read/Write mode. Do various operation that you want to do. Close the file. We are using fopen(file stream). there is some modes to open a file. Read mode  opens file into the read mode if file not found returns -1. Write mode opens file into the write mode if the file does not present creates a new file if there is previous data it will be overwritten. Append mode opens the file in the append mode and append data to it Without wasting much time lets start working. Create a New C file of whatever name you want mine is files.c. create the basic schema of C language. #include <stdio.h> int main(int argc, char const *argv[]) { /* code */ return 0; } Read From the file Create a FILE pointer to point a stream and open a file into the read mode using "r". you may need to include the string.h to your headers. the data of the file is #in

Basics of Pointers In C

Image
Pointers in C A pointer is a variable which contains the address of the variable specified. for example:  int x = 100; int *data; data = &x; this variable data contains the address of the block in the memory which contains the value 100. * specifies that this is the pointer variable. & gives the address. that is the what I am doing here assigning the address of the integer variable x to the pointer variable data. to get the data from the pointers we have to use the * sign. for the previous example to get the data of the memory block of the printf("%d\n",*data );  this should print the output like the image. Further digging into deep for the pointers. we can use them for the array. if we change content in the memory block pointed by the data, then this change should reflect the in the content of the x. Because variable x has the content of that memory block. (this is the great advantage of the using the pointers) we can read, change anything without copying the data fr

How to Get the length of an Array in C

Image
Array in C an array is a collection of a variable of a fixed number of the same data type in a sequential memory. an array can be declared in various ways. one of them is given below int x[] = {200,300,522,655}; char y[] = {'x','s','r'}; int n[10],j; // first declaring the array // then assigning the value. for ( j = 0; j < 10; j++ ) { n[ j ] = j + 100; } indexing in C array starts from the 0. so if you want to access the 4th element then you have to use x[3]. that's enough intro about the array. Getting Length of the Array in C to get the length of the array first we divide the size of the full array by the size of the one element of the array. Please note there is another way of getting the length of the char array (you can use strlen). you can see this in the given program. #include <stdio.h> int main(){ int x[] = {200,300,522,655}; char y[] = {'x','s','r'}; // determining the size of the array // getting the

C/C++ program to check the Palindrome string.

Image
Palindrome string: A string or word which are same from the start and end means word or program which look like same as original and reversed. To do that we have to first reverse the string. Check out our post on the String reverse in C/C++. To write the program of the Palindrome steps used are. Get the input from the user. convert the string to the Lower case to avoid any case sensitivity. apply the logic of the reverse the string. compare the reversed and original string, if same then the string is a palindrome. if different string is not a palindrome. print the result to the user. without wasting much time lets start. First of all the C schema. #include <stdio.h> #include <string.h> #include <ctype.h> int main(int argc, char const *argv[]) { return 0; } ctype.h is used to get the advantage of the function tolower() later in the program. Now take the input from the user. char name[150],rev[150] ; int l=0; printf("Enter a string to check palindrome\n");

C/C++ program to Reverse a String

Image
String In C language string is an Array of the Char variable. to write a program of the string reverse we have to break this program into steps as always. Take input from the user. Reverse the string using the for loop print the final answer to the user. First of All, create a schema for the program. #include <stdio.h> #include <string.h> int main(int argc, char const *argv[]) { return 0; } Now write some code for the Taking input from the user. scanf is fine here but keep in mind it can take input up to first space. char name[150],rev[150] ; int l=0; printf("Enter a string to reverse\n"); // taking input from the user // string should not have the space in between scanf("%s",&name); This code will take a string from the user, now implement the main logic. what we are doing here is that first, we are counting the length of the string and then storing the last variable into the first element of another variable. l = strlen(name); // main logic

How to Use For Each loop in JavaScript

Image
For Each Loop In JavaScript Hello Guys, Having trouble in understanding the concept of the for each loop in javascript. or having trouble finding the correct source code. Then don't worry this post is for you. What is For Each Loop: this is the loop which automatically iterates through all the elements of an array, it helps in the working with the dynamic array. Let's start working. In javascript for-each loop works in a different way. Here we have to create a function which will be passed to the foreach function of the array. Enough discussion. Start working. First, create an array of names of the actor. var heros = ["Tony","Captain","Batman","SuperMan"] Now create the function with the logic that has to be passed in the for each loop. function myfunc(item){ console.log(item + " is a very good superhero"); }  Now call the function in the foreach function of array // running the foreach loop 4 times heros.forEach(myfunc); You c

String Splitting in C++ (using find and substr)

Image
String Splitting in C++ Hello guys, you all have known the string splitting. Basically, string splitting is nothing but dividing the string based on a Delimiter or special character.  For example, example@gmail.com by the delimiter looks like [example,gmail.com]   use of string splitting is very broad as we can use this to tokenize thing in the web crawlers, data analysis in the data to extract useful things etc. without wasting much time let's start splitting. First of all create a schema for the c++ file. #include <iostream> #include <string> using namespace std; int main() { return 0; } Now let's take a string that is to be split. I took "codeincafeinweb". take a delimiter, for example, I took "in". and one more string variable for tokens. string.find() method returns the starting position of the delimiter, if it founds nothing then it will return -1. That is why we are using the while with terminating condition of -1. string name = "

TCP Socket Programming in Python (server/client)

Image
Socket Programming in Python What is Socket :  A  socket  is one end of a two-way communication link between two programs/software running on the network. A socket is bound to a port (also known as process id) number so that the TCP/UDP layer can identify the application that data to be transferred to. What to do? in order to create a server first, we need to create a socket in the program and put this socket into the listen mode. to that in the python is very easy, as you all know python is a very easy and powerful language. Socket Creation Create a New python file named as the server.py keep in mind that to work with socket we need to import socket into the file. import socket TCP_IP = '127.0.0.1' TCP_PORT = 15710 s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.bind((TCP_IP,TCP_PORT)) TCP_IP is the IP of this machine you are working on, and TCP_PORT is the port to be connected. socket.AF_INET is the protocol to work with the TCP protocol. Listening to connection and a

Easy File handling in C++ (working with files, fstream)

Image
In this tutorial, we are working with the files in the C++ or you have known to work with files as the file handling.  File handling in any language requires Three main step to follow Open the file in Read/Write mode. Do various operation that you want to do. Close the file. So In CPP, you can also use the traditional approach of C using FILE pointer and etc. We are using fstream (file stream). Without wasting much time lets start working. Create a New CPP file of whatever name you want mine is files.cpp. create the basic schema of cpp. #include <iostream> using namespace std; int main() { return 0; } To work with file add two more header first is #include<fstream>  , and second is #include<string> #include <fstream> #include <string> Now, let's start working with the writing into the files, to write into the file we need to open the file into the Write mode.  Which can be done by the ofstream class of cpp from the fstream header. string

PHP Connecting to MYSQL Database (creating the simple search box with database)

Image
PHP Connecting to Database In this tutorial, we are working with PHP and MySQL database. We are going to create a simple PHP page that will search for the name entered by the user in the database. NOTE: Full code is in the last of the post.  In order to work with the PHP and MySQL database, you should have installed both in your machine.  check my post for installing the PHP into the Machine. I hope you have installed PHP and MySQL. without wasting much time let's dive to create the page. First, create a file named searchpage.php into your local server directory.  local server directory is a specific folder, which can be accessed by the web server locally or globally. Create the HTML schema which is  And create a form in the body tag. you can try doing this your own. In the form create one input field with the name attribute "name" and create one submit button using the input tag with the name of "submit" and Value of "Search" . now HTML work

Java Console Games Tutorial (number guessing by human)

Image
Java Console Gaming Welcome to the tutorial, this tutorial is all about the small console game which is small to play and write. suppose this program as the practice program, and try doing this on your own, this is highly recommended. if you are stuck somewhere or having any trouble you are free to look here on the page. Features and Rule of the game: Computer asks for a number in variable max number. Computer randomly generates a number and put this number as the guessed number. The computer asks the user to give a number between 0 to max number and reply back with the suitable answer like whether the entered number is lower or higher than the guessed number. you should also assign a variable for the max guess allowed which are 6 per game. When the user wins or lost the game a check for play again will be asked. The game is broken in two files GuessingGame.java and GuessingGameTester.java. GuessingGame.java holds mostly main logic for the game. And GuessingGameTester.java contains the

Unity Tutorials For Absolute Beginners Making of AA (part 1 creating project)

Image
Unity For Beginners Source: Google.com Hello and welcome guys on my new unity tutorials series Unity For Beginners. In this post, we are going to learn Unity Game Engine by Making Easy games. Actually in my perspective unity is Very easy to learn ( In comparison to other Game Engines ). We all know Developing game is not easy, it is hard and time-consuming work to do. .....But we are going to adopt a strategy called Progressive learning to Learn Unity super easily. Plan : >>>  So what's the plan sir ????  :: Yes the plan is that I am going to give you Idea about the game engine with a small game. First Game we are going to make is AA. To make a game we have to break this into the small sections,  Working with the mechanics with placeholder art. Creating a Game manager and implementing scores. changing the placeholder  art to the Real art (if we have) Final polishing. Now without discussing much let's dive into the work. we will discuss this later. Let's Do this  Fi