<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rocker &#187; C++</title>
	<atom:link href="http://www.shishirsharma.com/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shishirsharma.com</link>
	<description>Everything bloggable around Shishir Sharma.</description>
	<lastBuildDate>Fri, 06 Jan 2012 09:47:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Desktop Calculator</title>
		<link>http://www.shishirsharma.com/2008/08/13/desktop-calculator/</link>
		<comments>http://www.shishirsharma.com/2008/08/13/desktop-calculator/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 06:38:27 +0000</pubDate>
		<dc:creator>Shishir Sharma 'criss'</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[Calculator]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[GNU General Public Licence]]></category>
		<category><![CDATA[Standard C++]]></category>

		<guid isPermaLink="false">http://shishirsharma.com/?p=118</guid>
		<description><![CDATA[I always appreciate coding in standard C++. Desktop Calculator is a application coded in Standard C++. It is a application based on the example 6.1 in the book &#8220;The C++ Programming Language&#8221;, Third Edition by Bjarne Stroustrup. Desktop Calculator is &#8230; <a href="http://www.shishirsharma.com/2008/08/13/desktop-calculator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I always appreciate coding in standard C++. Desktop Calculator is a application coded in Standard C++. It is a application based on the example 6.1 in the book &#8220;The C++ Programming Language&#8221;, Third Edition by <strong>Bjarne Stroustrup</strong>. Desktop Calculator is a GPL software.</p>
<p>To download full code click here.<br />
<span id="more-118"></span><br />
<code></p>
<pre class="brush: cpp">
/*
 *    This file is part of Desktop Calculator.
 *
 *    Desktop Calculator is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    Desktop Calculator is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 * Standard
 *    You should have received a copy of the GNU General Public License
 *    along with Desktop Calculator.  If not, see < http://www.gnu.org/licenses/ >.
 *
 *	   Shishir Sharma criss < mail AT DOMAIN shishirsharma DOT com >
 */
//////////////////////////////////////////////////////////
//                                                      //
//  File name   :   dc                                  //
//  Comments    :   desk calculator                     //
//  Versions    :   Saturday, September 23, 2006        //
//  Coded by    :   Shishir Sharma 'C R I I S'          //
//                  mail.mastermind@gmail.com           //
//                                                      //
//////////////////////////////////////////////////////////

#include <iostream>
#include <string>
#include < map>
#include <cctype>
#include <cmath>

using namespace std;

enum Token_value
{
  FUNCTION, NAME, NUMBER, END,
  PLUS = '+', MINUS = '-', MUL = '*', DIV = '/',
  PRINT = ';', ASSIGIN = '=', LP = '(', RP = ')',
  EXPO = '^', MLP = '[', MRP = ']', COMMA = ','
};

Token_value curr_tok = PRINT;

double number_value;
string string_value;
int no_of_errors;

map < string, double >table;

double error (const string &#038; s);
double message (const string &#038; s);
Token_value get_token ();
double prim (bool get);
double term (bool get);
double expr (bool get);

const char help[] = "DC: Desk Calculetor\n\npress ctrl+Z to quit\n";

int
main (int argc, char *argv[])
{
  // Standard variables
  table["pi"] = 3.1415926535897932385;
  table["e"] = 2.7182818284590452354;
  // Default help message
  message (help);

  // Main loop
  while (cin) {
    get_token ();
    if (curr_tok == END)
      break;
    if (curr_tok == PRINT)
      continue;
    cout < < expr (false) << '\n';
  }

  return no_of_errors;
}

double
message (const string &#038; s)
{
  cout << s << '\n';
  return 0;
}

double
error (const string &#038; s)
{
  no_of_errors++;
  cerr << "Error:" << s << '\n';
  return 1;
}

double
expr (bool get)
{
  double left = term (get);
  for (;;)
    switch (curr_tok) {
    case PLUS:
      {
	left += term (true);
	break;
      }
    case MINUS:
      {
	left -= term (true);
	break;
      }
    default:
      return left;
    }
}

double
term (bool get)
{
  double left = prim (get);
  for (;;)
    switch (curr_tok) {
    case MUL:
      {
	left *= term (true);
	break;
      }
    case DIV:
      {
	if (double d = prim (true)) {
	  left /= d;
	  break;
	}
	return error ("divide by 0");
      }
    case EXPO:
      {
	left = pow (left, prim (true));
	break;
      }
    default:
      return left;
    }
}

double
prim (bool get)
{
  if (get)
    get_token ();

  switch (curr_tok) {
  case MINUS:
    {
      return (-expr (true));
    }
  case NUMBER:
    {
      double v = number_value;
      get_token ();
      return v;
    }
  case NAME:
    {
      //help
      if (string_value == "help" || string_value == "Help"
	  || string_value == "HELP") {
	return message (help);
      }
      else if (string_value == "clear" || string_value == "Clear"
	       || string_value == "CLEAR") {
	cout.flush ();
	return message (help);
      }
      else
	//trignometry functions
      if (string_value == "sin") {
	if (get_token () == LP)
	  return sin (expr (true));
      }
      else if (string_value == "cos") {
	if (get_token () == LP)
	  return cos (expr (true));
      }
      else if (string_value == "tan") {
	if (get_token () == LP)
	  return tan (expr (true));
      }
      else if (string_value == "asin") {
	if (get_token () == LP)
	  return asin (expr (true));
      }
      else if (string_value == "acos") {
	if (get_token () == LP)
	  return acos (expr (true));
      }
      else if (string_value == "atan") {
	if (get_token () == LP)
	  return atan (expr (true));
      }
      // exponential functions
      else if (string_value == "exp") {
	if (get_token () == LP)
	  return exp (expr (true));
      }
      else if (string_value == "log") {
	if (get_token () == LP)
	  return log (expr (true));
      }
      else if (string_value == "log10") {
	if (get_token () == LP)
	  return log10 (expr (true));
      }
      else if (string_value == "sum") {
	get_token ();
	if (curr_tok == LP) {
	  double sum = 0;
	  sum += expr (true);
	  while (curr_tok != RP) {
	    if (curr_tok == COMMA)
	      sum += expr (true);
	  }
	  return sum;
	}
      }
      // new variables
      else {
	double &#038;v = table[string_value];
	if (get_token () == ASSIGIN)
	  v = expr (true);
	return v;
      }
    }
  case LP:
    {
      double e = expr (true);
      if (curr_tok != RP)
	return error ("')' expected");
      get_token ();
      return e;
    }
  default:
    return error ("primary expected");
  }
}

Token_value
get_token ()
{
  char ch;

  do {
    if (!cin.get (ch))
      return curr_tok = END;
  } while (ch != '\n' &#038;&#038; isspace (ch));

  switch (ch) {
  case '\n':
  case ';':
    return curr_tok = PRINT;
  case '^':
  case '*':
  case '/':
  case '+':
  case '-':
  case '(':
  case ')':
  case '[':
  case ']':
  case ',':
  case '=':
    return curr_tok = Token_value (ch);
  case '0':
  case '1':
  case '2':
  case '3':
  case '4':
  case '5':
  case '6':
  case '7':
  case '8':
  case '9':
  case '.':
    cin.putback (ch);
    cin >> number_value;
    return curr_tok = NUMBER;
  default:
    if (isalpha (ch)) {
      string_value = ch;
      while (cin.get (ch) &#038;&#038; isalnum (ch))
	string_value.push_back (ch);
      cin.putback (ch);
      return curr_tok = NAME;
    }
    error ("bad token");
    return curr_tok = PRINT;
  }
}

/* eof */
</cmath></cctype></string></iostream></pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.shishirsharma.com/2008/08/13/desktop-calculator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows GUI example code</title>
		<link>http://www.shishirsharma.com/2008/07/31/windows-gui-example-code/</link>
		<comments>http://www.shishirsharma.com/2008/07/31/windows-gui-example-code/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 03:06:19 +0000</pubDate>
		<dc:creator>Shishir Sharma 'criss'</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[GDI]]></category>
		<category><![CDATA[windows gui]]></category>
		<category><![CDATA[windows programming]]></category>

		<guid isPermaLink="false">http://shishirsharma.com/wp/?p=39</guid>
		<description><![CDATA[Windows GUI programming code with GDI. <a href="http://www.shishirsharma.com/2008/07/31/windows-gui-example-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Windows GUI example code. To download the Full code in one file click <a href="http://shishirsharma.com/files/winexample.cpp" target="_blank">here</a>.<br />
<span id="more-39"></span></p>
<pre lang="cpp" lineno=1>#include < windows.h >

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsExApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&#038;wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&#038;messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&#038;messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&#038;messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hDC;
    PAINTSTRUCT Ps;

    switch (message)                  /* handle the messages */
    {
        case WM_PAINT:
            hDC = BeginPaint(hwnd, &#038;Ps);
            MoveToEx(hDC, 160, 120, NULL);
            LineTo(hDC, 364, 222);
            MoveToEx(hDC, 60, 20, NULL);
            LineTo(hDC, 60, 122);
            LineTo(hDC, 264, 122);
            LineTo(hDC, 60, 20);
            EndPaint(hwnd, &#038;Ps);
            break;
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
            break;
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.shishirsharma.com/2008/07/31/windows-gui-example-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows programing with Dev-C++</title>
		<link>http://www.shishirsharma.com/2008/07/29/windows-programing-with-dev-c/</link>
		<comments>http://www.shishirsharma.com/2008/07/29/windows-programing-with-dev-c/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 07:35:13 +0000</pubDate>
		<dc:creator>Shishir Sharma 'criss'</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Dev-C++]]></category>
		<category><![CDATA[gcc gnu]]></category>
		<category><![CDATA[gnu compiler collection]]></category>
		<category><![CDATA[open source development]]></category>
		<category><![CDATA[windows program]]></category>
		<category><![CDATA[wxDev-C++]]></category>

		<guid isPermaLink="false">http://shishirsharma.com/wp/?p=14</guid>
		<description><![CDATA[Dev-C++ is good IDE for programming in C++. Considering it supports MinGW and MSVC (Rarely used with MSVC). It has syntax highlighting, debugger, profiler,  to do lists and many more. It is best for small and medium size project development. <a href="http://www.shishirsharma.com/2008/07/29/windows-programing-with-dev-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Dev-C++ is good IDE for programming in C++. Considering it supports MinGW and MSVC (Rarely used with MSVC). It has syntax highlighting, debugger, profiler,  TO DO lists and many more. It is best for small and medium size project development.</p>
<h2>Basic requirements</h2>
<h3>Personal Computer</h3>
<p><a href="http://www.google.co.in/search?hl=en&amp;client=firefox-a&amp;rls=org.mozilla%3Aen-GB%3Aofficial&amp;hs=SjO&amp;q=Personal+Computer+Download&amp;btnG=Search&amp;meta=">Download </a>( ?? )<br />
23. Just don&#8217;t talk about it.<br />
<span id="more-14"></span></p>
<h3>Microsoft Windows</h3>
<p><a href="http://www.google.co.in/search?hl=en&amp;client=firefox-a&amp;rls=org.mozilla%3Aen-GB%3Aofficial&amp;hs=JjO&amp;q=Microsoft+Windows+Xp+Download&amp;btnG=Search&amp;meta=">Download </a>(Are you nuts !!)<br />
If you have option for Operating System. Windows XP must be the last one, so stop here and turn off this tutorial and switch to any operating systems designed for humans.</p>
<h3>MinGW</h3>
<p>Download <a href="http://sourceforge.net/project/showfiles.php?group_id=2435">Direct Link (SourceForge)</a><br />
MinGW is a open source development suit for Microsoft Windows.  It stands for MINimalist Gnu for Windows. It is Windows port of famous GCC ( Gnu Compiler Collection ) development suit. It supports many languages like C/C++/Objective C/Java/Fortran77/Ada.</p>
<h3>Dev-C++ (4.9.9.2) /wxDev-C++ (6.10.2)</h3>
<p><a href="http://sourceforge.net/project/showfiles.php?group_id=10639">Download </a>(4.9.9.2)<br />
<a href="http://sourceforge.net/project/showfiles.php?group_id=95606">Download </a>(6.10.2)<br />
It comes WITH MinGW or Without MinGW. You can always download latest MinGW or even compile its source from older compiler. You have to download both Dev-C++ 4.9.9.2 and wxDev-C++ 6.10.2 as wxDev is just an Executable file which runs on the old 4.9.9.2 base.</p>
<h2>Tutorial</h2>
<p>All optionals are recommended.</p>
<h4>Assuming we have a PC and it has a windows.</h4>
<p>To know how to install Dev-C++ <a href="http://">Click Here</a></p>
<h4>Extract Dev-C++ 6.10.2.</h4>
<p>Extract it to Dev-Cpp/bin and rename the devcpp.exe to olddevcpp.exe and rename devcpp</p>
<h4>Install MinGW (only if you have installed the Dev-C++ without MinGW).</h4>
<p>Click Here</p>
<h4>[optional] Install/set the path of MinGW/bin or Dev-Cpp/bin in user path variable.</h4>
<p><a href="http://support.microsoft.com/kb/310519">Click Here</a></p>
<h4>[optional] Create a C++ Development Command Prompt.</h4>
<p><em>coming soon</em></p>
<h4>Start Dev-C++</h4>
<p>Now click on File -&gt; New -&gt; Project.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/a.jpg" rel="lightbox[14]" title="windows programming a"><img class="aligncenter size-medium wp-image-22" title="windows programming a" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/a-300x207.jpg" alt="windows programming a" width="300" height="207" /></a></p>
<p>Select the langauge C++ most probable. Type the name of the project. Select the type as Windows Project.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/b.jpg" rel="lightbox[14]" title="windows programming b"><img class="aligncenter size-medium wp-image-23" title="windows programming b" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/b-300x207.jpg" alt="windows programming b" width="300" height="207" /></a></p>
<p>Enter the path to save the project.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/c.jpg" rel="lightbox[14]" title="windows programming c"><img class="aligncenter size-medium wp-image-24" title="windows programming c" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/c-300x215.jpg" alt="windows programming c" width="300" height="215" /></a></p>
<p>Now you will get a template of windows program. Save the unsaved main.cpp file. If you don&#8217;t know what to write in it. Click <a href="http://">here </a>to get a template program.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/d.jpg" rel="lightbox[14]" title="windows programming d"><img class="aligncenter size-medium wp-image-25" title="windows programming d" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/d-300x207.jpg" alt="windows programming d" width="300" height="207" /></a></p>
<p>Before compiling the project you must include the library path of gdi32 in project. for this Right click on project name in project inspector -&gt; Project Options.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/e.jpg" rel="lightbox[14]" title="windows programming e"><img class="aligncenter size-medium wp-image-26" title="windows programming e" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/e-300x207.jpg" alt="windows programming e" width="300" height="207" /></a></p>
<p>In the linker section type -lgdi32</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/f.jpg" rel="lightbox[14]" title="windows programming f"><img class="aligncenter size-medium wp-image-27" title="windows programming f" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/f-300x207.jpg" alt="windows programming f" width="300" height="207" /></a></p>
<p>Now compile it or Build the project.</p>
<p><a href="http://shishirsharma.com/wp/wp-content/uploads/2008/07/g.jpg" rel="lightbox[14]" title="windows programming g"><img class="aligncenter size-medium wp-image-28" title="windows programming g" src="http://shishirsharma.com/wp/wp-content/uploads/2008/07/g-300x205.jpg" alt="windows programming g" width="300" height="205" /></a></p>
<p>We get a beautiful output.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.shishirsharma.com/2008/07/29/windows-programing-with-dev-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

