Saturday, May 25, 2013

One Day Workshop on Parikshak - An Online Program Grading System

                             Computer Programming is an important aspect of any computer-science/information-technology course. This is among the most difficult to teach, since being a good programmer is a skill to be acquired coupled with knowledge of many different aspects such as abstraction, analysis, structured programming, debugging, etc. Usually computer programming is taught through a combination of theory classes on concepts and languages, and lab classes on specific languages. Assignments are given, which are manually graded by the instructor. Manual grading of programs is very tedious and time consuming. While evaluating student assignments the teacher has to act as a compiler/interpreter and inspect each line in program and judge whether the overall program would work correctly. While this grading approach works fine for a small number of simple assignments, it gets unwieldy as the complexity and number of the assignment increases. This, in turn, results in inadequate attention to the practical programming skills of students.
                   Parikshak is a web based system which offers a solution to this. A tool like Parikshak, which facilitates automated evaluation of software programs can significantly reduce the load of the faculty, give direct feedback to student, thereby leading to efficient handling of programming assignments/exams. Parikshak allows teachers to define programming assignments systematically, allows registered students to attempt solving them online, and automatically assesses the solution. The feedback is available to the students and the faculty, for follow up and record. Using Parikshak to manage your programming component, clearly offers many advantages.
                    During the workshop, we will demonstrate the system, discussing various ways in which tool can be used in the academic setting, and provide hands-on for faculty. Since we have limited number of seats, we request you to confirm participation from your colleges latest by June 12, 2013, by email or phone call. Teachers from the CS/IT departments are preferred, though others with some programming experience/interest are welcome.



Contact Information
Details of workshop
Phone: 022-27565303, Extn 301
Contact Person: Ms. Mercy Sobhan
Date & Timing: Sat, 15 June, 2013
10:00 AM – 5:00 PM
Venue: CDAC Kharghar
Registration Fees: Rs 600/-
Tea and Lunch will be provided to all participants

Registration fee has to be paid by Demand Draft / Cheque (local or at par) drawn in favour of CDAC payable at Mumbai. Please mention your name, organization and contact no. on the back side of the Demand Draft / Cheque.

Looking forward to your support and participation

Thanking you,


Monday, May 20, 2013

Plotting / Creating Graphs in C / C++

Graph (Chart): A graph is a diagram / picture which is showing a relation between two variable quantities.

In this post,  I am going to show you, how to create or plot a graph(chart) in C / C++ program using gnuplot tool. GNUPLOT is a command line tool to generate 2D and 3D graphs. 

Lets write a small program to create a graph as shown below using C / C++ program with gnuplot tool.

Note: Before running following program make sure you have installed gnuplot. (sudo apt-get install gnuplot)


// File Name: GraphPlotting.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define NO_OF_POINTS 11
#define NO_OF_COMMANDS 4

void main()
{
    // X, Y Co-ordinate values
    double X_Values[NO_OF_POINTS] = {0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0};
    double Y_Values[NO_OF_POINTS] = {0.0 ,0.5, 0.0, 1.0, 0.0, 1.5, 0.0, 1.0, 0.0, 0.5, 0.0};
    register int i=0;
    // Creating & Opening Co-ordicates.txt file in Write mode
    FILE * CO_Ordinates_FILE = fopen("Co-ordicates.txt", "w");
    // Writing Co-Ordinates into Co-ordicates.txt file
    for (i=0; i  <  NO_OF_POINTS;  i++)
    fprintf(CO_Ordinates_FILE, "%lf %lf \n", X_Values[i], Y_Values[i]);
    // List of commannds to run on gnuplot
    char * CMDsFOR_GNUPLOT[] = {"set title \"RENI V/S SAM\"",
                                "set xlabel \"----RENI--->\"",
                                "set ylabel \"----SAM--->\"",
                                "plot \"Co-ordicates.txt\" using 1:2 with lines"
                               };
    // Opening gnuplot using pipe IPC
    FILE * GNUPLOT_Pipe = popen ("gnuplot -persist", "w");
    // Executing gnuplot commands one by one
    for (i=0; i  <  NO_OF_COMMANDS;  i++)
    fprintf(GNUPLOT_Pipe, "%s \n", CMDsFOR_GNUPLOT[i]);
}

To Run: gcc GraphPlotting.c
              ./a.out

Friday, May 10, 2013

Listing Input devices in C / C++

         Without  input devices we can't do anything with our computer / system. Here Input device may be Mouse, Keyboard, Touch screen, External touch pad, Pen tablet, Mic, camera etc.

         When we are programatically dealing with input devices, It is unavoidable to List / scan all input devices to get information about those devices. For this purpose we can use a X function called XListInputDevices.

Syntax:
XDeviceInfo * XListInputDevices(Display *display, int *ndevices)
where
Display *display Specifies the connection to the X server.
int *ndevices Specifies the address of a variable into which the server can return the number of input devices available to the X server.

XListInputDevices allows a client to determine which devices are available for X input and information about those devices. An array of XDeviceInfo structures is returned, with one element in the array for each device. The number of devices is returned in the ndevices argument. The X pointer device and X keyboard device are reported, as well as all available extension input devices. The use member of the XDeviceInfo structure specifies the current use of the device.

Lets write a small C program to list All Xinput devices using XListInputDevices.

//File Name: ListInputDevices.c
#include <stdio.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/XInput.h>

void main()
{
        int n, i=0;
        XDeviceInfo *devList, *curDev;
        // Connecting to XServer
        Display *dpy = XOpenDisplay(0);
        // Getting Input Device list
        devList = XListInputDevices(dpy, &n);
        // Checking for more then 0 devices
       if (!devList)
        printf("\n No Input devices to List");
        // Listing devices ID and NAME
        while(i < n)
        {
                curDev = devList + i;
                printf(" DEVICE ID: %d ",curDev->id);
                printf(" DEVICE NAME: %s \n",curDev->name);
                i++;             
    }
}
To Run: gcc ListInputDevices.c -lX11 -lXi
             ./a.out

Out Put: Your All Xinput Devices


Monday, May 6, 2013

Drawing With Mouse - An Example for Event Handling in X Window System (X11) Programming

What is X Window System?

The X Window System is client/server system for managing a windowed graphical user interface in a distributed network. In general, such systems are known as windowing system.

Event handling in X Window System Programming:

Most applications simply are event loops. They wait for an event, decide what to do with it, execute some amount of code that results in changes to the display, and then wait for the next event. X window system also provides large amount of support for event handling. Here I am going to show you how to draw with mouse as shown in this video, using X window System or X11 events. Watch Video Here: http://www.youtube.com/watch?v=dPVpKHGdi6A
  Screen shot:

// File Name: XEventHandling.c
#include <stdio.h>
#include <X11/Xutil.h>
#include <X11/cursorfont.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/XInput.h>
struct Point{
              int x;
              int y;
             }p1,p2;
void main()
{
 Display *dpy = XOpenDisplay(0);
 char *window_name = (char*)"Drawing window";
 int whiteColor = WhitePixel(dpy, DefaultScreen(dpy));
 Window parent = XCreateSimpleWindow(dpy, RootWindow(dpy, DefaultScreen(dpy)), 0, 0,
                     230, 150, 0, whiteColor, whiteColor);
 XStoreName(dpy, parent, window_name);
 XMapWindow(dpy, parent);
 XSelectInput(dpy, parent, ButtonPressMask| PointerMotionMask| LeaveWindowMask| EnterWindowMask| ButtonReleaseMask );
 Drawable d = parent;
 XGCValues values;
 values.line_width = 4;
 values.line_style = LineSolid;
 GC gc = XCreateGC(dpy, d, GCLineWidth, &values);
 int flag = 0;
 for(;;) {
   XEvent e;
   XNextEvent(dpy, &e);
   if(e.xany.window == parent)
     {
       switch(e.type)
        {
         case EnterNotify: printf("\n POINTER Entered in Window");
                           break;
         case LeaveNotify: printf("\n POINTER Left Window");
                           break;     
         case ButtonPress:if(flag == 0 && e.xbutton.button==1)
                          {
                          printf("\n Button %d Pressed at (%d, %d)", e.xbutton.button, e.xbutton.x, e.xbutton.y);
                          p1.x = e.xbutton.x;
                          p1.y = e.xbutton.y;
                          flag =1;
                          }
                          break;
         case ButtonRelease:if(flag == 1 && e.xbutton.button == 3)
                          {
                           printf("\n Button %d Pressed at (%d, %d)", e.xbutton.button, e.xbutton.x, e.xbutton.y);
                           flag =0;
                           XUnmapWindow(dpy, parent);
                           XMapRaised(dpy, parent);
                           XMoveWindow(dpy, parent, 0, 100);
                          }
                          break;
        case MotionNotify: if(flag ==1)
                          {
                           printf("\n Motion Notified at (%d, %d)", e.xbutton.button, e.xbutton.x, e.xbutton.y);
                           p2.x = e.xbutton.x;
                           p2.y = e.xbutton.y;
                           XDrawLine(dpy, parent, gc, p1.x, p1.y, p2.x, p2.y);
                           p1.x = p2.x;
                           p1.y = p2.y;
                           }                                        
                           break;                     
               }
          }
  }
}

To Run: gcc -lX11 XEventHandling.c 

              ./a.out
Out Put:  To Start drawing Click & release mouse button-1 in Drawing window
                 Move mouse pointer
                 To end drawing Click & release mouse button-3 in Drawing window
              

Thursday, May 2, 2013

Program To Create SVG Icon For A Software

Scalable Vector Graphics (SVG) is an XML-based vector image format. The SVG specification is developed by the World Wide Web Consortium since 1999.

Advantages of using SVG over other image formats (like JPEG and GIF) are:
  • SVG images can be created and edited with any text editor
  • SVG images can be searched, indexed, scripted, and compressed
  • SVG images are scalable
  • SVG images can be printed with high quality at any resolution
  • SVG images are zoomable (and the image can be zoomed without degradation)
  • SVG is an open standard
  • SVG files are pure XML
SVG images are zoomable, without degradation of quality, That's why most of the people use SVG images as their software icon. In this post i am going to show you, how to create SVG icon / image as shown below, for your software using C and Cairo graphics library.
NOTE: Before running the following program, plz make sure that you have already installed cairo library. (sudo apt-get install libcairo2-dev)

To Know How to create PDF files in C programming Click HERE.

 // File Name: SVGCreate.c

 #include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <cairo/cairo.h>
#include <cairo/cairo-svg.h>

void main() {
    // Declaring Variables
    cairo_t *cr;
    cairo_surface_t *surface;
    double x=25.6,  y=128.0;
    double x1=102.4, y1=230.4, x2=153.6, y2=25.6, x3=230.4, y3=128.0;
    surface = (cairo_surface_t *)cairo_svg_surface_create("R.E.N.I.svg", 250.0, 250.0);
    cr = cairo_create(surface);
    // Creating required graphics in SVG file
    cairo_move_to (cr, x, y);
    cairo_curve_to (cr, x1, y1, x2, y2, x3, y3);
    cairo_set_line_width (cr, 10.0);
    cairo_stroke (cr);
    cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
    cairo_set_line_width (cr, 6.0);
    cairo_move_to (cr,x,y);   cairo_line_to (cr,x1,y1);
    cairo_move_to (cr,x2,y2); cairo_line_to (cr,x3,y3);
    cairo_stroke (cr);
    // Typing text in SVG file
    cairo_set_font_size (cr, 15);
    cairo_select_font_face (cr, "Georgia", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_move_to(cr, 140, 150);
    cairo_show_text(cr, "R.E.N.I");
    // Destroying context and surface
    cairo_destroy (cr);
    cairo_surface_destroy (surface);
}

To Run: gcc -lcairo SVGCreate.c
              ./a.out
Out Put: It will create R.E.N.I.svg file in your current directory