Wednesday, June 27, 2012

C++ Project Bus Reservation System in Code::blocks

“Bus Reservation System” project is written in c++. It is very simple project just to show the implement of class and object of C++. You can understand the code easily and learn how to create class and use object in c++ for your C++ project.The tasks that user can perform in this project are listed below:
1.Install the bus record
2.Reservation
3.Show the bus details
4.Show all buses available
This project is console application without GUI. You can add many features in this project.Here data of bus information is not store in file so every run of program previous data is lost so you can implement the file handling to store all the bus details.

Code::blocks Project Bank Management System in C programming

Bank Management System project is design and programmed by Ravi Agrawal, Sagar Sharma and Sawal Maskey student of IOE as a first year mini project in c. This program may not be used as a Banking software but programmer tries to implement all the features of Bank. Program is completely password protected and has a two mode Admin and Staff mode. Bank administrator can login as admin user name is “admin” and password is “ioe” for admin mode. For staff mode three  user name is available which is written in USER.DAT which you can see download this project. The list of user name and passwor for staff mode is given below: 

School Project Personal Diary Management in C programming

This project is similar to the project Contact Management in C. In this project, I am reusing all the code from it. I created this Personal Diary Management project just by renaming printed messages, adding a few functions, and modifying existing functions slightly.

Please go through the Contact Management project if you haven't. In this project, I have explained the techniques of file handling in C.

So, in this project, I will explain the changes that I have made.

Let's start with describing data structure.
// Define Constant Variables
#define ESC 27
#define REF_SZ 10
#define DATE_SZ 64
#define MIN_TEXT_SZ 50
#define MAX_TEST_SZ 500
#define READ_ARRAY_SZ 15
#define DATA_FILE "dataFile.dat"
#define TEMP_FILE "tempFile.dat"

//Define data structure

struct data{
    char refNum[REF_SZ]; //Unique reference number and auto-incremented
    char noteDate[DATE_SZ]; //Auto populated using system date and time
    char eventDate[DATE_SZ]; //Event date
    char location[MIN_TEXT_SZ]; //Location of event happened
    char eventDesc[MIN_TEXT_SZ]; //Event short description
    char notes[MAX_TEST_SZ]; //Notes of the Event
};
I am using 6 variables in a structure. The variable "refNum" will be unique and it is auto-increment. The variable "noteDate" is to store note added date and it is also auto-populated using system date and time. 

Other variables are:
  • eventDate: Event date. It can be any format chosen by the user
  • location: Location of event happened.
  • eventDesc: Event short description.
  • notes: Notes of the event. Maximum character is 500.
Although the variable refNum is auto-incremented, I haven't defined it as an integer. Rather than storing number value only, I decided to add '#R' as an initial character so that the unique reference value will look like "#R10001" instead of "1000".

To achieve this we have to create two separate small functions which I will describe below.

Function: getNextRef()
//Get next reference number

int getNextRef(){

    struct data a;
    int num=0;
    fp = fopen(DATA_FILE,"rb");

    if(fp!= NULL){

        fseek(fp,0,SEEK_END);

        fseek(fp,ftell(fp)-sizeof(a),0);
        fread(&a,sizeof(a),1,fp);

        // converting string to number
        for (int i = 0; a.refNum[i + 2] != '\0'; i++) {
            num = num * 10 + (a.refNum[i + 2] - 48);
        }
        fclose(fp);
        return num;

    } else {

        return 10000;
    }
}
This function will read the last item from the file and read the reference number which is the previous reference number and also the highest value. It will remove the first two characters, convert the remaining numbers into an integer data type, and return it. This function will be executed at the start of the application so if it does not find a file then it will return 1000. 

Function: calRefNum(char *buff, int num)
//Calculate next reference number
static void calRefNum(char *buff, int num){

    char tmpRef[REF_SZ];
    char refNum[REF_SZ] = {'#','R'};
    sprintf(tmpRef,"%d",num);
    strcat(refNum, tmpRef);
    strcpy(buff,refNum);
}
This function converts the reference number into char data type, concatenates with the "#R" initial character, and assigns it to a character pointer which is used while adding notes.

Apart from these changes I have made a few changes in readData(), add(), and view() functions. Once you compile and run it you will understand the changes.

Please download the source code from the GitHub Download Source Code.

You can also watch a video about this project on YouTube.


Telecom Billing Management System in c with source code

This Mini project is compile in gcc compiler with code::blocks IDE. This project can be a good reference for those student who are doing there school project in c.Architecture of this project is very simple and easy to understand the code. Just file handling is used to store the data and corresponding function are made to manipulate the data.
The tasks provide in this program are:-
1. A : for adding new records.
2. L : for list of records.
3. M : for modifying records.
4. P : for payment.
5. S : for searching records.
6. D : for deleting records.
User are provide the above tasks.They can add records,modify and view records. Searching and deleting facilities is also provided.

Download Project from GitHub


Tuesday, May 29, 2012

Simple method for texture mapping on sphere Using gluSphere and gluQuadricTexture in OpenGL

In my previous article [here] I have shown you how to map texture in solid sphere. In that method whole sphere is render using triangles and providing texture co-ordinates which seems difficult to understand. Now in this article I am going to show you simple method to map texture on Sphere. We first draw a sphere using gluSphere and texture co-ordinates are automatically generated by gluQuadricTexture function for Sphere.
gluSphere:
syntax:
void WINAPI gluSphere( GLUquadric *qobj, GLdouble radius, GLint slices, GLint stacks);

Wednesday, May 9, 2012

Creating multiple windows with OpenGL and GLUT

We may need the multiple OpenGL windows for our program for example we can show orthographic view of object (top view, side view,front view)  in separate  windows.
Steps for Creating Multiple Windows:-
1.Initialize drawing context and frame buffer using glutInit(), glutInitDisplayMode(), and glutInitWindowSize().
2.Create first window
3.Register callbacks for first window
4.Create second window
5.Position the second window
6.Register callbacks for second window
7.Register (shared) idle callback
8.Enter the main loop
Note: Callbacks can be shared between windows, if desired



Saturday, April 28, 2012

GLFW Tutorial 4: Texture mapping sample code in OpenGL Framework

If you are new to the GLFW(OpenGL framework) you can follow beginning tutorial here.
On Contrary with GLUT texture mapping is very easy in GLFW . We want to use pre-generated 2D images for surface textures, light maps, transparency maps etc.These images are stored with a standard image format in a file, which requires the program to decode and load the      image(s) from file(s), which can require much work from the programmer.To make programming easier for OpenGL developers, GLFW has built-in support for loading images from files.
In this tutorial I give example for surface textures only. Surface textures are important because it helps to make object realistic.
To load a texture from a file, you can use the function glfwLoadTexture2D:
int glfwLoadTexture2D( const char *name, int flags )
This function reads a 2D image from a Truevision Targa format file (.TGA) with the name given by name, and uploads it to texture memory. It is similar to the OpenGL function glTexImage2D, except that the image data is read from a file instead of from main memory, and all the pixel format and data storage flags are handled automatically. The flags argument can be used to control how the texture is loaded. If flags is GLFW_ORIGIN_UL_BIT, the origin of the texture will be the upper left corner (otherwise it is the lower left corner). If flags is GLFW_BUILD_MIPMAPS_BIT, all mipmap levels will be generated and uploaded to texture memory (otherwise only one mipmap level is loaded). If flags is GLFW_ALPHA_MAP_BIT, then any gray scale images will be loaded as alpha maps rather than luminance maps. To make combinations of the flags, or them together (e.g. like this: GLFW_ORIGIN_UL_BIT |GLFW_BUILD_MIPMAPS_BIT).
Here is the sample program to illustrate the texture mapping with complete source code written in c++ with gcc compile and code::blocks IDE. You can also download the project file.