Saturday, March 28, 2020

Quiz Game in C Part 3: Final Game Play and score

In previous articles, we created functions, multi-dimensional character array to store questions, options, and answers. Up to this point, we have everything ready to finish gameplay.
Here we will use the following techniques:

  • Create for loop to display question one by one
  • Create another infinite loop inside for loop to check the answer given by the user. The loop breaks only if the user-provided an answer is within options (a, b, c and d)  otherwise it will loop infinitely. 
  • Calculate the score for the correct answer provided.
  • Use gotoxy to manage text indentation.

Quiz game in C Part 2: Multi-dimensional C array

In this article, we will discuss the gameplay() function but not all only the usages of one dimension, two-dimension, and third dimension character array. Choosing the correct dimension of the array is very important to store information effectively. We have to display a question, four options and store the correct answer to compare the answer provided by the user. Remember these three information are connected to each other if we mismatch the order then the game will go wrong. 
Here, we will declare three character array to store questions, four options, and answer in the same order of the array index.

Question is a string which is an array of character and we will ask 10 questions in total. We create a two-dimension character array, the first index is a total number of questions i.e 10 and the second index is the length of a string.
    char question[10][250];
    strcpy(question[0], "This is question no 1");
    strcpy(question[1], "This is question no 2");
    strcpy(question[2], "This is question no 3");
    strcpy(question[3], "This is question no 4");
    strcpy(question[4], "This is question no 5");
    strcpy(question[5], "This is question no 6");
    strcpy(question[6], "This is question no 7");
    strcpy(question[7], "This is question no 8");
    strcpy(question[8], "This is question no 9");
    strcpy(question[9], "This is question no 10");
We can't assign string using "=" to the two-dimension array and correct way to use it is strcpy() function.

Quiz Game in C part 1 - Flow Chart and Main Menu

Application Flow Chart:

Start: Quiz program start
Main Menu: Program display menu to the user to start the game or to quit.
User Input: The application stops to get user input.
Decision Tree: If user input is S then Quiz game start else if user input is Q then the program will quit.
Quiz Game: User gets 10 questions one by one and each correct score is marked as 1.
Display Score: It display final score after ending the game and the user is directed to the main menu.
Stop: End of the game.

Wednesday, December 11, 2013

Basic .Net Socket Class Implementation in C#


The .Net Framework provides a Socket class which has the all properties of TcpClient , TcpListener and UdpClient and plus its own methods. For details of .Net Socket class you can see here. In my previous articles I have shown you the basic implementation of TcpClient, TcpListener and UdpClient class. Here we are going to use the Socket class. Many things are same as previous articles so I like to discuss only Socket class implementation and ignore other things

Downloading the source code

Download complete source code from below:

Basic UDP socket echo client server program in C#


This program is same as previous chapter TCP Echo client server only difference is implementation of UDP socket. This chapter highlight the difference between TCP and UDP connection. TCP is analogous to telephone communication but UDP is analogous to mail box communication. TCP socket is required to establish a connection before data transfer where as UDP does not required to establish a connection before communication but we have to specify the destination address for each one i.e message called a datagram carries its own address information and is independent of all others. Message send through UDP can lost but in TCP doesn't. Data transfer rate is faster in UDP connection rather than TCP connection. So, UDP socket is used in such area where higher Data transfer rate is important rather than accurate data transfer for example live video telecast.

Download Source code

You can download the complete source code below:

Basic TCP socket echo client server program in C#


Here we will create a simple echo client and echo server program where client send the message string to the server and server echoed back the same message string to the client. Download the both client and server source code compile it and run both in command window. IP address , port and message are passed through command line argument.

Download Source Code

You can download the complete source code form below.

Saturday, August 31, 2013

OpenGL with Qt tutorial Creating OpenGL Widget with Qt Creator

In this articles, we will discuss about using the OpenGL with Qt GUI application. We just create the OpenGL window with Qt GUI application using Qt creator. In upcoming tutorials series I will show rendering the 3D object , event handling and other with OpenGL and Qt GUI application.

Download Qt creator

Qt 5.1.0 for Windows 32-bit (MinGW 4.8, OpenGL, 666 MBform


This tutorial provides basic implementation of OpenGL with Qt GUI application. It shows how to integrate the OpenGL with Qt GUI application. Qt provides a widget called QGLWidget for rendering graphics which enables you to easily integrate OpenGL with Qt. This tutorials only includes OpenGL widget and related class to integrate with Qt. It doesn’t include the details of OpenGL rendering pipeline and Qt GUI. To learn and understand this tutorial you must have basic knowledge of Qt GUI and OpenGL rendering pipeline.  In this tutorial, we will use modern OpenGL version 3.2 and GLSL 1.5 as a shader language.