The usefulness of Google is not very surprising to many...however, for me its one of the greatest democratizing tools...it has democratized the concept that is called knowledge which was once a well guarded property in the hands of a few...
let me elaborate it a bit...i think whatever little related to technology i have learnt so far, is simply by means of Googling... even these days to remove the programming errors i take the help of mighty Google...to elaborate it more, for example, today i became curious about the way WiFi can be used in the industrial automation domain... so i googled it and got a fair amount of idea which includes ZigBee to Cisco's Wireless Plant Solution...I became curious about whether the data collected by sensors in a plant can be processed via cloud...i am interested in this topic because of its social implication...think about it that if the plant's data can be processed across the continent, then no one will have to do night shift duty... So i googled about that and got some idea about Helios platform from Eurotech... when i want to know if the 802.11n has been officially released, i just google that...when i want to know if there is anything similar or dissimilar between new(noThrow) of C++ and new(ELeave) of Symbian C++, i simply google that...when i want to know about the smart pointers in boost, i just google that...
the google doc or the other tools like picasa and google map have come recently... but i am an ardent fan of Google from its inception because i think its only because of google i did not have to depend on anybody to learn about my technological area...
Tuesday, February 23, 2010
Thursday, February 18, 2010
My First Experience with Ubuntu QT
I had installed Ubuntu quite sometimes back. I had also installed QT. However, i got my hands dirty in QT programming in the Ubuntu environment for the first time today. Let me share my experience with you.
First i opened the QTCreator from the Applications->Programming menu. Then went to File->New. And followed the steps as shown in the pictures.





After the project is created, i opened the mainwindow.ui and dragged a PushButton to the center of the main window. From the property, i changed the display text of the button as Hello World. its name is changed to HelloWorldBtn.

Then i added a private slot in the mainwindow.h file as follows:
private slots:
void on_HelloWorldBtn_clicked();
It means the signal connection is automatic.
Then i added the following handler function in the mainwindow.cpp file:
void MainWindow::on_HelloWorldBtn_clicked()
{
QMessageBox::information(this,"Som", "Hello World");
}
And its done... Of course to compile this code, i had to do #include (QMessageBox) in the mainwindow.cpp file...
i ran the application... And when i clicked the button it showed the messagebox as the following picture...
First i opened the QTCreator from the Applications->Programming menu. Then went to File->New. And followed the steps as shown in the pictures.





After the project is created, i opened the mainwindow.ui and dragged a PushButton to the center of the main window. From the property, i changed the display text of the button as Hello World. its name is changed to HelloWorldBtn.

Then i added a private slot in the mainwindow.h file as follows:
private slots:
void on_HelloWorldBtn_clicked();
It means the signal connection is automatic.
Then i added the following handler function in the mainwindow.cpp file:
void MainWindow::on_HelloWorldBtn_clicked()
{
QMessageBox::information(this,"Som", "Hello World");
}
And its done... Of course to compile this code, i had to do #include (QMessageBox) in the mainwindow.cpp file...
i ran the application... And when i clicked the button it showed the messagebox as the following picture...
Monday, January 25, 2010
Android Graphics
I was curious about the graphical programming in Android... Fortunately i have found the library aChartEngine... As i was trying to play around with it, i came up with few trigonometric graphs... Hope this would give some pointers to the new comers about graphical programming in Android...
The application looks like the following...

And the graphs are like the following:
Sin Curve

Cosine Curve

Tangent Curve

Sinc Curve

Damped Sin Curve
The application looks like the following...
And the graphs are like the following:
Sin Curve
Cosine Curve
Tangent Curve
Sinc Curve
Damped Sin Curve
Tuesday, January 19, 2010
Android HomeScreen Management
As i was trying to play around with Android HomeScreen, i came up with this application to add any application to the HomeScreen. I think it can work as a good project for the beginner of Android programming.
The home screen looks like the following after i added two of the applications to the HomeScreen -one is my own KeyPadDialer and the other is the AlarmClock.

And the HomeScreen Management Application looks like the following in the beginning:

And after clicking the Spinner it looks this:

The complete source code for my application can be found here.
The manifest file for this application can be found here.
And the layout of the application is given here.
Hope this idea helps others...
The home screen looks like the following after i added two of the applications to the HomeScreen -one is my own KeyPadDialer and the other is the AlarmClock.
And the HomeScreen Management Application looks like the following in the beginning:
And after clicking the Spinner it looks this:
The complete source code for my application can be found here.
The manifest file for this application can be found here.
And the layout of the application is given here.
Hope this idea helps others...
Saturday, January 2, 2010
My first experience with Java
As most of my experience lies in C++, when i started gaining interest in Java/J2SE i started looking at it from a C++ programmers point of view. Hence the first thing i googled was how to create a canonical class in Java. And i was astonished to find out that the way we do Assignment operator in C++ is not the same in Java. After some more googling i came to know about the clonable interface in Java. And it gave me the right direction...
Then i googled about the String class in Java and found out that a String object in Java is immutable... i became curious and opened the String class of Java... And voila... no wonder... the character array that holds the contents of the String object is final... hence it is immutable... So i asked myself what happens when we do String newString = oldString in Java. And i got the answer... As the String class is not implementing the Clonable interface, when we do String newString = oldString, the oldString's contents get a new reference in newString... We loose any reference to oldString.
But then i wondered how String S1 = oldString + "abc" would work. Because as i was googling i found out that Java does not support operator overloading... so how come the + operator is working fine for the String class? my first stumbling block... fortunately i found out the document at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1 and my doubts were gone...
So i wondered if Strings are immutable in Java, are not there any way to change the contents of a String object without creating a new object? i googled a little more and came to know about StringBuffer and StringBuilder classes and their mutable char array which will store that data... i delved into the classes a little more and found out about their append function.
So far my investigation into the Java source code is fruitful...
Hopefully i will be able to delve more into it and find out the nitty-gritties about the Java language...
Then i googled about the String class in Java and found out that a String object in Java is immutable... i became curious and opened the String class of Java... And voila... no wonder... the character array that holds the contents of the String object is final... hence it is immutable... So i asked myself what happens when we do String newString = oldString in Java. And i got the answer... As the String class is not implementing the Clonable interface, when we do String newString = oldString, the oldString's contents get a new reference in newString... We loose any reference to oldString.
But then i wondered how String S1 = oldString + "abc" would work. Because as i was googling i found out that Java does not support operator overloading... so how come the + operator is working fine for the String class? my first stumbling block... fortunately i found out the document at http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.18.1 and my doubts were gone...
So i wondered if Strings are immutable in Java, are not there any way to change the contents of a String object without creating a new object? i googled a little more and came to know about StringBuffer and StringBuilder classes and their mutable char array which will store that data... i delved into the classes a little more and found out about their append function.
So far my investigation into the Java source code is fruitful...
Hopefully i will be able to delve more into it and find out the nitty-gritties about the Java language...
Tuesday, November 17, 2009
Experimentation with Design Pattern
I am yet to study the book Pattern Hatching. However, i tried to accumulate all my knowledge on Design Pattern and solved a problem of Accountancy. i would like to share it with you. Let me, first of all, state the problem.
The Problem :
Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions. Also the Sales Tax should be rounded off to the nearest 0.05.
This being the problem, we need to come out with a solution for this problem.
Now let me tell you how my thought process went into it to think it at an abstract level.
First of all, i thought to make two top level classes. One that will define the Items having different benchmarks for Sales Tax and Import Duty; i.e.
1. Food, Medical and Book items which are not imported and hence exempted from both sales tax and import duty
2. Non Food Book and Medical items which are not imported and hence will have just the Sales Tax
3. Food Book and Medical items which are imported and hence will have only import duty
4. Non food book and medical items which are imported and hence will have both Sales Tax and Import Duty
And the other for the Tax Calculation algorithm for different items.
Then i thought this is a perfect match for Strategy Pattern that i had studied in the GoF book. I thought about that pattern keeping in mind for the future expansion of the Tax Calculation Algorithm. What i mean is that for the present problem, the calculation is simple. And hence it does not need any other Strategy. However, for the future purpose if the Tax Calculation Algorithm is changed to some complicated one, then we can just Subclass the Tax Calculation class and attach that strategy to the Item Class.
Next i thought, won't it be nice to get a Factory Class through which the client can create different Items on the fly. Hence i have decided to create an ItemCreator class which is nothing but a parameterized factory class for creating different Items on the fly.
And i came out with the following solution.
The Item class Hierarchy:
File: Item.h
//This class represents the Items which have only Import Duty
//This class represents the Items which have only Sales Tax but no Import Duty
//This class represents the Items which have got both Import Duty as well as sales Tax
As you can see the four classes solve the hierarchy for different items having different benchmark for Sales Tax and import Duty.
The Item.cpp file looks like the following:
File: Item.cpp
Now let us concentrate on the Sales Tax class
file: SalesTax.h
And the implementation of the Sales tax is as follow:
file: SalesTax.cpp
As you can see the the data for calculation are being passed from the Item class.
Hence we can say this is in abstract form an implementation of the Strategy Pattern where the Item class is working as the Context and the Sales Tax class is acting as the sole Strategy interface.
Now lets concentrate on the creation of the Items.
As i have already mentioned, this is done through a Parameterized factory class called ItemCreator.
This class looks like the following:
File: ItemCreator.h
And the implementation of this ItemCreator is as follow:
file: ItemCreator.cpp
And the client program will look like the following:
-
Thus the problem is solved using two common design pattern concepts - Strategy Pattern and Parameterized Factory Pattern.
This is the way i am trying to move from the problem domain to the solution domain using design pattern concepts.
Hope this helps others who are studying Design Pattern.
The Problem :
Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable on all imported goods at a rate of 5%, with no exemptions. Also the Sales Tax should be rounded off to the nearest 0.05.
This being the problem, we need to come out with a solution for this problem.
Now let me tell you how my thought process went into it to think it at an abstract level.
First of all, i thought to make two top level classes. One that will define the Items having different benchmarks for Sales Tax and Import Duty; i.e.
1. Food, Medical and Book items which are not imported and hence exempted from both sales tax and import duty
2. Non Food Book and Medical items which are not imported and hence will have just the Sales Tax
3. Food Book and Medical items which are imported and hence will have only import duty
4. Non food book and medical items which are imported and hence will have both Sales Tax and Import Duty
And the other for the Tax Calculation algorithm for different items.
Then i thought this is a perfect match for Strategy Pattern that i had studied in the GoF book. I thought about that pattern keeping in mind for the future expansion of the Tax Calculation Algorithm. What i mean is that for the present problem, the calculation is simple. And hence it does not need any other Strategy. However, for the future purpose if the Tax Calculation Algorithm is changed to some complicated one, then we can just Subclass the Tax Calculation class and attach that strategy to the Item Class.
Next i thought, won't it be nice to get a Factory Class through which the client can create different Items on the fly. Hence i have decided to create an ItemCreator class which is nothing but a parameterized factory class for creating different Items on the fly.
And i came out with the following solution.
The Item class Hierarchy:
File: Item.h
#ifndef ITEM_H #define ITEM_H class SalesTax; //This represents the Items which don't have an Import duty or any sales tax class Item { public: //Constructors Item(); Item (SalesTax* aSalesTax); //Interface Functions for Item //To calculate the price after tax and import duty virtual void CalculateTotalPrice(); //To calculate the total tax and import duty virtual void CalculateTotalTax(); //To set the price of the Items void SetPrice(double aPrice); //To get the price of the Items before tax double getPrice(); //To get the price of the items after tax double getTotalPrice(); //To get the total tax and import duty of the items double getTax(); //Data protected: //Works as the Strategy of the Sales Tax problem. //If in future the tax calculation becomes more complicated for different Items //we will just have to change this Strategy. We can also subclass this Strategy class //for future expansion of the tax calculation strategy SalesTax* iSalesTax; //Data protected: //These are the basic properties of any Item. //Hence these are made protected members so that the subclasses of Item can inherit //these properties double iPrice; double iTotalPrice; double iTotalTax; };
//This class represents the Items which have only Import Duty
class ImportedItem : virtual public Item { public: //Constructors ImportedItem(); //This constructor helps to create Items having only Import duty ImportedItem(SalesTax* aSalesTax, double aImportDuty); //Override virtual void CalculateTotalTax(); protected: double iImportDuty; };
//This class represents the Items which have only Sales Tax but no Import Duty
class NonFoodBookMedicalItem : virtual public Item { public: //Constructors NonFoodBookMedicalItem(); //This constructor helps to create Items having only Sales tax NonFoodBookMedicalItem(SalesTax* aSalesTax, double aRate); //Override virtual void CalculateTotalTax(); protected: double iRate; };
//This class represents the Items which have got both Import Duty as well as sales Tax
class NormalItem: public ImportedItem, public NonFoodBookMedicalItem { public: NormalItem(); //This constructor helps to create Items having both Sales tax and Import duty NormalItem(SalesTax* aSalesTax, double aRate, double aImportDuty); //Override virtual void CalculateTotalTax(); }; #endif
As you can see the four classes solve the hierarchy for different items having different benchmark for Sales Tax and import Duty.
The Item.cpp file looks like the following:
File: Item.cpp
#include "SalesTax.h" #include "Item.h" Item::Item(){} Item::Item(SalesTax* aSalesTax):iSalesTax(aSalesTax),iPrice(0),iTotalPrice(0),iTotalTax(0) { } void Item::CalculateTotalPrice() { iTotalPrice = iPrice + iTotalTax; } double Item::getTotalPrice() { return iTotalPrice; } void Item::CalculateTotalTax() { iTotalTax = iSalesTax->ComputeSalesTax(iPrice, 0, 0); } void Item::SetPrice(double aPrice) { iPrice = aPrice; } double Item::getPrice() { return iPrice; } double Item::getTax() { return iTotalTax; } ImportedItem::ImportedItem(){} ImportedItem::ImportedItem(SalesTax* aSalesTax, double aImportDuty):Item(aSalesTax) { iImportDuty = aImportDuty; } void ImportedItem::CalculateTotalTax() { iTotalTax = iSalesTax->ComputeSalesTax(iPrice, 0, iImportDuty); } NonFoodBookMedicalItem::NonFoodBookMedicalItem(){} NonFoodBookMedicalItem::NonFoodBookMedicalItem(SalesTax* aSalesTax, double aRate):Item(aSalesTax) { iRate = aRate; } void NonFoodBookMedicalItem::CalculateTotalTax() { iTotalTax = iSalesTax->ComputeSalesTax(iPrice, iRate, 0); } NormalItem::NormalItem() {} NormalItem::NormalItem(SalesTax* aSalesTax, double aRate, double aImportDuty):Item(aSalesTax) { iRate = aRate; iImportDuty = aImportDuty; } void NormalItem::CalculateTotalTax() { iTotalTax = iSalesTax->ComputeSalesTax(iPrice, iRate, iImportDuty); }
Now let us concentrate on the Sales Tax class
file: SalesTax.h
//This class works as the Strategy of the Sales tax problem class SalesTax { public: //Default constructor SalesTax(); //This function helps to compute the Sales Tax virtual double ComputeSalesTax(double aPrice, double aRate, double aImportduty); private: //This is an helper function which will round off the sales tax double RoundOff(double aTax); };
And the implementation of the Sales tax is as follow:
file: SalesTax.cpp
#include "SalesTax.h" SalesTax::SalesTax(){} double SalesTax::ComputeSalesTax(double aPrice, double aRate, double aImportduty) { double tx = (aPrice*aRate/(double(100))) + (aPrice*aImportduty/(double(100))); return RoundOff(tx); } //private: double SalesTax::RoundOff(double aTax) { int taxTemp = (int)aTax; double decimaltaxTemp = (double)(aTax - (int)taxTemp); int tempy = (int)(1000*decimaltaxTemp)/100; int tempz = (int)(1000*decimaltaxTemp - tempy*100); int temp = (int)(tempz/10); int t = tempz%10; if (t >= 5) temp+=1; return (double)(taxTemp + tempy*(0.1) + temp*(0.01)); }
As you can see the the data for calculation are being passed from the Item class.
Hence we can say this is in abstract form an implementation of the Strategy Pattern where the Item class is working as the Context and the Sales Tax class is acting as the sole Strategy interface.
Now lets concentrate on the creation of the Items.
As i have already mentioned, this is done through a Parameterized factory class called ItemCreator.
This class looks like the following:
File: ItemCreator.h
#include "Item.h" const int ITEM_WITH_NOSALESTAX_AND_IMPORTDUTY = 1; const int ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY = 2; const int ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY = 3; const int ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY = 4; const double SALES_TAX_RATE = 10; const double IMPORT_DUTY_RATE = 5; class Not_A_Standard_Item_Type_Exception { public: void printerrormsg(); }; class ItemCreator { public: virtual Item* Create(int aItemId); };
And the implementation of this ItemCreator is as follow:
file: ItemCreator.cpp
#include "ItemCreator.h" #include "Item.h" #include "SalesTax.h" using namespace std; void Not_A_Standard_Item_Type_Exception::printerrormsg() { cout <<"Not the right Item Type..." <<endl; } Item* ItemCreator::Create(int aItemId) { SalesTax* st = new SalesTax(); switch(aItemId) { case ITEM_WITH_NOSALESTAX_AND_IMPORTDUTY: return new Item(st); break; case ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY: return new ImportedItem(st,IMPORT_DUTY_RATE); break; case ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY: return new NonFoodBookMedicalItem(st,SALES_TAX_RATE); break; case ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY: return new NormalItem(st,SALES_TAX_RATE,IMPORT_DUTY_RATE); break; default: throw Not_A_Standard_Item_Type_Exception(); } }
And the client program will look like the following:
#include "SalesTax.h" #include "Item.h" #include "ItemCreator.h" #include <vector> using namespace std; void main() { typedef vector<Item*> listOfItem; listOfItem::iterator theIterator; listOfItem Basket; char answer = 'n'; double totalprice = 0; double totaltax = 0; do { int type_of_item; cout <<"Enter the type of Item...1,2,3,4" <<endl; cout <<"1 for ITEM_WITH_NOSALESTAX_AND_NOIMPORTDUTY" <<endl; cout <<"2 for ITEM_WITH_NOSALESTAX_ONLY_IMPORTDUTY"<<endl; cout <<"3 for ITEM_WITH_ONLY_SALESTAX_AND_NOIMPORTDUTY"<<endl; cout<<"4 for ITEM_WITH_BOTH_SALESTAX_AND_IMPORTDUTY" <<endl; cin>>type_of_item; ItemCreator* itemCreator = new ItemCreator(); try { Item* item = itemCreator->;Create(type_of_item); cout <<"Enter the price of the Item" <<endl; double price; cin >>price; item->SetPrice(price); Basket.push_back(item); } catch(Not_A_Standard_Item_Type_Exception& e) { e.printerrormsg(); } cout<<"Do you want to continue... Y/N" <<endl; cin>>answer; } while (answer =='y'); theIterator = Basket.begin(); int pos = 0; while (theIterator != Basket.end()) { Basket.at(pos)->CalculateTotalTax(); totaltax+=Basket.at(pos)->getTax(); Basket.at(pos)->CalculateTotalPrice(); double price = Basket.at(pos)->getPrice(); double price_after_tax = Basket.at(pos)->getTotalPrice(); totalprice+=price_after_tax; cout<<"Item" <<pos+1 <<" price " <<price <<endl; theIterator++; pos++; } cout<<"------------" <<endl; cout<<"Toal tax " <<totaltax <<endl; cout<<"Total price "<<totalprice<<endl; }
Fig : The Class Diagram
This is the way i am trying to move from the problem domain to the solution domain using design pattern concepts.
Hope this helps others who are studying Design Pattern.
Monday, November 9, 2009
My first experience with Ubuntu Karmic kola
I felt very excited after I read the review comments about Ubuntu 9.1, the Karmic Kola distribution of Ubuntu... However, with over-enthusiasm, I could not wait for the official release... I downloaded the release candidate a few days before the official release of Ubuntu 9.1...
As I have used only Windows so far, I was a bit worried about my transition to Ubuntu... However, so far it was smooth...
After downloading the release candidate of the Ubuntu 9.1, i had to burn the CD... I used ImgBurn to do that... What one needs is a blank 700 MB writable CD... The burning process did not take much time...
Then with caution, I inserted the CD for the installation... The installation got started... And it hardly took 20 minutes to completely install it...
I restarted my computer... There were two options to boot up - one for my old Windows XP and the other was Ubuntu... I chose the second one... The login screen came in no time... I entered my password... And voila... The system came up within a flash... I thought I needed to do a lot of configuration for my internet connection... To test it I just clicked the Firefox menu on the top of the desktop... And no wonder, the Ubuntu Google came up in a flash...
I was delighted...
With a little help through Googling, I found that for a developer, the build-essential package is a must... After that, I did some research and found the Synaptic Package Manager Under System... I opened it... Searched for build-essential... Marked it... And installed it...
Then I installed Git... And Eclipse... And yesterday I installed QTCreator IDE... And the development environment is ready...
So far my experience with Ubuntu is very good... its update manager is working for me...The synaptic package manager is fantastic...
I can say that for me it's been a smooth transition to Ubuntu...And the best part is that neither I had to install SpyBot... nor do I have to scan with SpyWare Doctor every time I start my PC... of course, I don't have to care about Malwarebytes to fight against Virtumunde...
Linux desktop share in Bharat in 2024
As I have used only Windows so far, I was a bit worried about my transition to Ubuntu... However, so far it was smooth...
After downloading the release candidate of the Ubuntu 9.1, i had to burn the CD... I used ImgBurn to do that... What one needs is a blank 700 MB writable CD... The burning process did not take much time...
Then with caution, I inserted the CD for the installation... The installation got started... And it hardly took 20 minutes to completely install it...
I restarted my computer... There were two options to boot up - one for my old Windows XP and the other was Ubuntu... I chose the second one... The login screen came in no time... I entered my password... And voila... The system came up within a flash... I thought I needed to do a lot of configuration for my internet connection... To test it I just clicked the Firefox menu on the top of the desktop... And no wonder, the Ubuntu Google came up in a flash...
I was delighted...
With a little help through Googling, I found that for a developer, the build-essential package is a must... After that, I did some research and found the Synaptic Package Manager Under System... I opened it... Searched for build-essential... Marked it... And installed it...
Then I installed Git... And Eclipse... And yesterday I installed QTCreator IDE... And the development environment is ready...
So far my experience with Ubuntu is very good... its update manager is working for me...The synaptic package manager is fantastic...
I can say that for me it's been a smooth transition to Ubuntu...And the best part is that neither I had to install SpyBot... nor do I have to scan with SpyWare Doctor every time I start my PC... of course, I don't have to care about Malwarebytes to fight against Virtumunde...
In 2022, in Bharat, the share of Linux desktop was 8.05% and in 2024 it is 15%.
See below...
Linux desktop share in Bharat in 2022
Once the Government of Bharat adopts it everywhere, the ecosystem will be built around Linux.
I am happy to see that Bharat has indigenously developed #maya OS, a Linux-based OS (DRDO project - 2021) and the Government of Bharat is eagerly supporting the deployment of this OS across defense and government offices. Once the schools and colleges adopt #Linux and the government offers a green signal for public use of Linux, there won't be any looking back.
#JaiHind...
Enjoy...
Subscribe to:
Posts (Atom)



