Saturday, June 22, 2013

TIC TAC TOE Game in C lanugage

TIC TAC TOE using C

Again a game, I developed it when I was in my BCA second year.
Compiler I used is Turbo C++ , I know its old one but I used only this.
It is a well known game.......
I have a bug in this game. I am unable to determine the error cause.
Its giving me an error -
"Graphics error : Not enough memory to load driver"

The game runs fine for sometime but after playing 3-4 chances it gives this error and terminates automatically. Try playing the game if you like it please share it or if you have any solution comment below.



Instructions before you run the code:



Set BGI Graphics path in initgraph() function according to your pc's Trubo C BGI library.
Here mine is c:\\turboc3\\bgi



If your compiler's graphic library is not included then you will find many errors in this program.
To avoid this follow the steps:
1. Go to compiler's option menu (ALT+O)
2. Then select Linker option
3. Then select Libraries option
4. Then Mark X to Graphics Library option using space button
5. Then select OK

All done.
If you want to save this changes permanently then do this:
1. Go to Option menu
2. Select Save then select OK



Screen Shots:





Code:

Here is the code of the game copy and paste and follow the instructions and run the game.
Works fine.

Program to find sum of digits of a number

Sunday, June 9, 2013

Program to convert binary number system to decimal number system

How to convert binary to decimal:

To convert any binary number to decimal follow these steps:
1. Take the LSB(Least Significant Bit) and multiply it with 20.
2. Now take next bit and multiply it with 21.
3. Now take next bit and multiply it with 22.
4. Follow this multiplication of next bit and increasing power of 2 until we reach MSB(Most Significant Bit).
5. Now add all the results of the steps above.

We will have the decimal equivalent.

Example:
Here I am converting binary number 1010 to its decimal equivalent.
(1010)2=(?)10

1.     0*20=0
2.     1*21=2
3.     0*22=0
4.     1*23=8
5.     0+2+0+8=10
so binary equivalent of 1010 is 10.

(1010)2=(10)10

This program will calculate binary to decimal for you:

Program to get Armstrong numbers between 1 and 1000

Armstrong number :
An Armstrong number is a number such that sum of cubes of its digits is equal to the number.
For example: 153 is Armstrong number because
13+53+33=153
370, 371 are also Armstrong numbers.

Here is the program code to find Armstrong numbers between 1 and 1000

Thursday, May 9, 2013

Program to overload different operators to function with strings

Program to count word, line and charactors in a file

Program to check palindrom string

Program to check armstrong number

Program to check prime number

Program to print Fibonacci series up to user limit

Program to print table of any number

Program to convert temperature

Program to perform arithmetic operations on complex numbers using operator overloading

Program of friend function

Program of constructor overloading

Program of constructor and destructor

Program of studetn class that has basic information of student fee deposite and attendance of month

Program of this pointer

Program of account class that get information of custormer and do deposite,withdrow and display balance

Program of reverse number

Program to implement inline function

Program for scope of varialbe

Program of call by value and call by reference

Program of a recursive function

Thursday, April 11, 2013

Program to print alphabet patterns

Love to generate different patterns with C or C++ compilers:
Check this program, this program is able to generate all alphabet patterns from A-Z.
A pattern for line I Love BcaStuff.

Pattern for all characters is generated separately, but I merged them all in a single collage to better view.

Try this code to generate pattern for all 26 alphabets and heart shape :

Program of falling colorful characters

One more colorful program:


Program to draw a hut pattern

Want to draw something new ?
Try this:

Program to print colorful heart pattern

Try this code:

Program to print Heart pattern

Have you tried generating different patterns in C or C++ ?
I know its easy but I am sharing what I tried.

Here is simple Heart pattern.
And will look something like this :

Program to understand concept of Class and Object

After getting the basic difference between syntax of C and C++ we can develop almost all C programs in C++ also. C++ also support same conditional statements, loops and the logic for the code.
Here is the list of C programs that can be developed in C++ also with minor changes in syntax as I described in my last post.
Basic C Programs.

Now we will take a look at new concepts introduced in C++ :

Class
Before reading concept of class you should have basic idea of Structure in C.
Structure allows us to store different data types at one place.
Class also follow the same concept but it is advanced so it enables user to define  function with data members. Means user can define different data members in a class as we do in structure and user can also define functions based on those data members.

Object
Object is a run time entity. Object is a variable of a class, that allows user to access class data members and functions.
It is also known as Instance.

A program to understand class and object concept:



In this program we have class named student which contains s_name, s_address, s_marks[5], s_percentage as data members, and we have two function get() and display(). Here we are using get() function to get value for class data members and display() function to print the value of class data members.
we declared an object like this :

student stud;

Above syntax is to declare an object, student is our class name and stud is our object.
Using this object we are calling class functions get() and display() like this :

stud.get();
stud.display();

So here is all we did with the help of object of the class. We accessed class functions outside the class using objects.

Program to print hello word in cpp

Starting with C++

As we started our first program with Hello word in C now we are doing this with C++.
Environment of C++ has some differences then C environment.
In  C language we use stdio.h for basic input output operation with help of printf() and scanf() functions.
Here we will use cout and cin object defined in iostream.h header file.

Cout is used for output.
Cin is used for input.

For detailed study of basic input/output: Read

A Hello word program here :

Program to use Structure to store student information


Before C++ we had a concept of structure in c language. Structure allows us to hold different types of data in one variable.
For example, if we want to store information of a student, we may have different different information, like name, address, percentage, marks etc. And we know that different fields will use different data types, name and address will need character array, percentage will need float type and marks for multiple subjects will need an integer array.

So to combine all these type of different data types at one place, concept of structure is introduced.

struct student
{
  char s_name[20];
  char s_address[50];
  int marks[5];
  float percentage;
};

We use struct  keyword to declare any structure.
And all fields declared inside structure are known as structure members.
now if we want to use these all fields for a single entity then we just need to declare a variable of this type:

struct student stud;

here, a variable stud is able hold all above mentioned information for a student-



To access members of a structure we use  (.) structure reference operator.
For detailed study about structure click here.

Run this program to understand this concept, comment below if you have any query.

Sunday, March 31, 2013

Car race game in c++










Have you played this came before...
I have created this game in C++, Simple and sweet game.






Nice car game in C++ using Borland Turbo C++ Compiler.
Set BGI Graphics path in initgraph() function according to your pc's Trubo C BGI library.
Here mine is c:\\turboc3\\bgi.

Keyboard Controls to play the game ;
Controls
A - Move car left
D - Move car right
Enter/ESC to exit the game.

If your compiler's graphic library is not included then you will find many errors in this program.
To avoid this follow the steps:
1. Go to compiler's option menu (ALT+O)
2. Then select Linker option
3. Then select Libraries option
4. Then Mark X to Graphics Library option using space button
5. Then select OK

All done.
If you want to save this changes permanently then do this:
1. Go to Option menu
2. Select Save then select OK


Still having problem then ask me or comment below.
Enjoy the Game.

A JavaScript Calculator

Copy and paste this code in a notepad and save as a .html or .htm then open this file with any browser to run calculator program.



Output of code will be like this


Powered by Blogger.