A simple square pattern in C++

Here’s a small C++ program which outputs a square pattern according to the size entered. Code is given below :


/*
* sqpattern.cpp
*
* Copyright 2010 Ershad K ershad92@gmail.com
* Licensed under GPL Version 3
*
* To compile - g++ -o sqpattern sqpattern.cpp
* To execute - ./sqpattern
*/

#include <iostream>
using namespace std;

int main()
{
  int size;
  cout << "Enter size: ";
  cin >> size;

  int count = 1;
  cout << " ";
  while (count++ < size) cout << " _";

  for (int i = 1; i < size; i++)
    {
      int numOfCharsPerLine = 0;
      cout << "\n";
      for (int j = 0; j < i; j++)
        {
          cout << " |";
          numOfCharsPerLine += 2;
        }

      cout << "_";
      numOfCharsPerLine += 1;

      int k = 1;
      while (k++ < (size*2) - numOfCharsPerLine )
      cout << " ";
      cout << "|";
    }

  count = 1;
  cout << "\n ";
  while (count++ <= (size)-1 ) cout << "|_";

  cout << "|\n";

return 0;
}

Output:

The programs draws  squares of any size entered. The code needs improvement, please feel free to give suggestions. Click here for ‘experiments’ git repo. Thank you 🙂

Configure Gmail in Mutt easily!

It’s always wonderful to play with terminal. Last week, I tried to configure my Gmail account in mutt, a powerful console based mail client, using this tutorial. I had to create some configuration files for various related applications and executed some commands. Hence I thought it would be nice if there is any script/program to configure mutt easily by simply entering the Gmail ID and password. Here is such an application, written in C++, which will help you to configure mutt very easily. All that you need to do is install mutt and follow these steps :

1. Download this file
2. Exctract it to your home directory
3. Execute the following commands :

$cd muttgconf
$./muttgconf

VERY IMPORTANT: THE PROGRAM CREATES / MODIFIES MANY CONFIGURATION FILES. I WILL NOT BE RESPONSIBLE FOR ANY DAMAGE OR LOSS CAUSED BY THIS APPLICATION. USE IT UNDER YOUR RISK.

Get its source from git://github.com/ershad/Mutt-Gmail-Conf.git    Good luck 🙂

Salt Analysis Simulator V1.0 – Released!

For the past few weeks, I have been coding to bring out a program to do salt analysis lab work virtually. We have salt Analysis as a part of plus two academics and it is a process of finding the anion and cation which the salt contain through a systematic procedure. We add many reagents / acids throughout the labwork and analyse the result to identify the anion and cation. I hope this program would help students to practice salt analysis at their home and would feel confident!

The program is completely written in C++ and is intended to work on M$ DO$ platform, becuase more students are using M$ Platform including Biology-science group students. Another techincal reason is that, I have used clrscr(), gotoxy() and getchar() many times which is a troublesome work to implement in ANSI standard.

The program works based on a new algorithm which I name it as “IntMatchReact” since the reaction process is done through a matching of integer values. While developing this software, I had a notion to implement anti-piracy for fun which was left on the way. The software is licensed under GPL and I would like you to go through the code and help in improving.

Please post your valuable comments and improvement tips. Thank you 🙂

Get SAS V1.0 (here)

Bug: i forgot to add exit function for ‘e’ key stroke, have exams now – will upload SAS with minor corrections soon 🙂

C++ Program to tweet

It’s very interesting to play with C++ and if it is in GNU/Linux, lots of tools like ‘wget’, ‘grep’,etc. are there to help us in time. Here is a simple C++ snippet which tweets directly to your time line. Feel free to add more features and would be great if you could share it with me too 🙂

/*
 *      shell-tweet.cpp
 *
 *      Copyright 2009 Ershad K  ershad92@gmail.com
 *      Licensed under GPL Version 3
 *
 *      Please change USERNAME, PASSWORD and compile with g++
 *      To compile - g++ shell-tweet.cpp
 *      To execute - ./a.out
 */

#include <iostream>
#include <string.h>
#include <stdlib.h>

using namespace std;

int main()
{
char name[] = “username”, password[] = “password”, status[500], cmd[500];

char sym[] = {char(34),”};

again: cout << “\n Status: “;
fgets (status,140,stdin);

cout << “\n Length = ” << strlen(status);

if (strlen(status) > 139)
{
cout << ” Exceeds 140 character limit, Type again \n”;
goto again;
}
else
{

strcpy(cmd,”wget -nv –keep-session-cookies –http-user=”);

strcat(cmd,name);
strcat(cmd,” –http-password=”);
strcat(cmd,password);
strcat(cmd,” –post-data=”);
strcat(cmd,sym);
strcat(cmd,”status=”);
strcat(cmd,status);
strcat(cmd,sym);
strcat(cmd,” http://twitter.com:80/statuses/update.xml&#8221;);

system(cmd);

cout << “\n Done”;
}
return 0;
}

Easy Clarity – Connect Easily!

‘Disconnection’ is a routine process in dial up internet. Here is an C++ snippet which dials BSNL WLL Clarity without asking for password again and again. It automatically closes on disconnection with a beep sound.

/*
 *      easyclarity.cpp
 *
 *      Copyright 2009 Ershad K  ershad92@gmail.com
 *      Licensed under GPL Version 3
 *
 *      Please change USERNAME, PASSWORD and compile with g++
 *      To compile - g++ easyclarity.cpp
 *      To execute - ./a.out
 */

#include <iostream>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

int main ()
{
	char username[] = "USERNAME";
	char password[] = "PASSWORD";
	puts("\n EasyClarity - Connect wisely!  www.ershadk.wordpress.com\n\n");
	ofstream myfile;
	system("sudo wvdialconf");
	myfile.open ("/etc/widial.conf");
        myfile << "[Dialer Defaults]\nInit1 = ATZ\nInit2 = ATQ0 V1 E1 S0=0 "
               << "&C1 &D2 +FCLASS=0\nInit3 = at+crm=1;+cmux=1;+cps=33;+cta=0"
               << "\nModem Type = Analog Modem\nISDN = 0\nPhone = #777\nModem"
               << " = /dev/ttyUSB0\nUsername = "<<username<<"\nPassword = "
               <<password<<"\nBaud = 460800\nStupid Mode = 1\nAuto DNS\nCheck"
                <<" Def Route";
	myfile.close();
	system("sudo wvdial");
	cout << "\a";
	return 0;
}

e-FLAMES Beta now in GNU/Linux :)

Hello friends,

I’m glad to present the Beta version of e-FLAMES for GNU/Linux before you. Thanks to Jesse, for his valuable header file with  getch() function in GNU/Linux.  I have made minor changes in this version and now, it’s licensed under GPL V3. The  program still has some errors when strings with special characters are given as input. Please help me correct those and make this program bug-free.  I expect to release the final version before the end of this month. Till then, please try this program and give me your valuable comments.

(Click here to download GNU/Linux executable)

Here are the screenshots :

The source code is written in C++ using Geany as IDE. The source code is given below …

/*
*      e-FLAMES.cpp
*
*      Copyright 2009 Ershad K <ershad92@gmail.com>
*
*      This program 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 2 of the License, or
*      (at your option) any later version.
*
*      This program 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.
*
*      You should have received a copy of the GNU General Public License
*      along with this program; if not, write to the Free Software
*      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
*      MA 02110-1301, USA.
*/

//Including header files..
#include <iostream>
#include <string.h>
#include <stdlib.h> //for system() function
#include “jesse_conio.h”

char name1[30], name2[30]; //declaring global name variables

using namespace std; // dunno what’s this, please tell me..

void message(); // for general headings and texts

void getnames(); // for names input

void copyright(); //print copyright notice

void changecase( char names[]); //change case function

void removespecial(char name_1[]); //remove spaces

(Click here to view full source) (Click here to download GNU/Linux executable)

This source code can be used in windows also with a few changes in headers and can be succesfully compiled. Please add more features and it would be better if any one works to bring out a GUI version of e-FLAMES. Hope you would like this one and feel free to add your suggestions and opinions as comments. Best Wishes