Wednesday, 27 May 2015

C++ UNIT CONVERTER

Below is the Source Code of a C++ Unit Converter I wrote couple of weeks ago. I use Object-Oriented approach in creating the converter, and it is also not a GUI app it runs on command prompt.

The first source code is the header file; the class that contains all the conversion functions is defined in the header file.


The Header File

class unit_conversion{
public:
double secondToMinute(double x);
double minuteToSecond(double x);
double secondToHour(double x);
double hourToSecond(double x);
double minuteToHour(double x);
double hourToMinute(double x);
double meterToKilometer(double x);
double kilometerToMeter(double x);
double hectToSqmet(double x);
double sqmetToHect(double x);
double acreToSqmet(double x);
double sqmetToAcre(double x);
double celToFah(double x);
double fahToCel(double x);
double kelToCel(double x);
double celToKel(double x);
double meterToYard(double x);
double yardToMeter(double x);
double meterToInch(double x);
double inchToMeter(double x);
double mileToKilometer(double x);
double kilometerToMile(double x);
double literToGallon(double x);
double gallonToLiter(double x);
double literToCube(double x);
double cubeToLitre(double x);
double literToPint(double x);
double pintToLiter(double x);
double literToGill(double x);
double gillToLiter(double x);
double kilogramToTonne(double x);
double tonneToKilogeam(double x);
double kilogramToOunce(double x);
double ounceToKilogram(double x);
double kilogramToPound(double x);
double poundToKilogram(double x);
double kilogramToSlug(double x);
double slugToKilogram(double x);

private:
//double input;

};

double unit_conversion::secondToMinute(double x){
return x/60;
}

double unit_conversion::minuteToSecond(double x){
return x * 60;
}

double unit_conversion::secondToHour(double x){
return x/3600;
}

double unit_conversion::hourToSecond(double x){
return x * 3600;
}

double unit_conversion::minuteToHour(double x){
return x/60;
}

double unit_conversion::hourToMinute(double x){
return x * 60;
}

double unit_conversion::meterToKilometer(double x){
return x/1000;
}

double unit_conversion::kilometerToMeter( double x){
return x * 1000;
}

double unit_conversion::hectToSqmet(double x){
return x * 10000;
}

double unit_conversion::sqmetToHect(double x){
return x/10000;
}

double unit_conversion::acreToSqmet(double x){
return x * 4046.856422;
}

double unit_conversion::sqmetToAcre(double x){
return x/4046.856422;
}

double unit_conversion::celToFah(double x){
return (x * 9/5) + 32;
}

double unit_conversion::fahToCel(double x){
return (x - 32) * 5/9;
}

double unit_conversion::kelToCel(double x){
return x - 273.15;
}

double unit_conversion::celToKel(double x){
return x + 273.15;
}

double unit_conversion::meterToYard(double x){
return x / 0.9144;
}

double unit_conversion::yardToMeter(double x){
return x * 0.9144;
}

double unit_conversion::meterToInch(double x){
return x / 0.0254;
}

double unit_conversion::inchToMeter(double x){
return x * 0.0254;
}

double unit_conversion::mileToKilometer(double x){
return x / 0.62137;
}

double unit_conversion::kilometerToMile(double x){
return x * 0.62137;
}

double unit_conversion::literToGallon(double x){
return x / 4.546; // gallon is in UK conversion
}

double unit_conversion::gallonToLiter(double x){
return x * 4.546;  // gallon is in UK conversion
}

double unit_conversion::literToCube(double x){
return x / 1000;
}

double unit_conversion::cubeToLitre(double x){
return x * 1000;
}

double unit_conversion::literToPint(double x){
return x / 0.568; //pint is in UK Conversion
}

double unit_conversion::pintToLiter(double x){
return x * 0.568; //pint is in UK Conversion
}

double unit_conversion::literToGill(double x){
return x / 0.142;
}

double unit_conversion::gillToLiter(double x){
return x * 0.142;
}

double unit_conversion::kilogramToTonne(double x){
return x / 1000;
}

double unit_conversion::tonneToKilogeam(double x){
return x * 1000;
}

double unit_conversion::kilogramToOunce(double x){
return x / 0.0283495;
}

double unit_conversion::ounceToKilogram(double x){
return x * 0.0283495;
}

double unit_conversion::kilogramToPound(double x){
return x / 0.45;
}

double unit_conversion::poundToKilogram(double x){
return x * 0.45;
}

double unit_conversion::kilogramToSlug(double x){
return x / 14.6;
}

double unit_conversion::slugToKilogram(double x){
return x * 14.6;

}


The Main Program Source File

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

using namespace std;

int user_selection = 99;
double value;

int main(){

unit_conversion converter;

cout << "THE UNIT CONVERTER" << endl;
while (user_selection != 0)
{
cout << "\n";
cout << "Enter 1 For Time Conversion\n";
cout << "Enter 2 For Area Conversion\n";
cout << "Enter 3 For Temperature Conversion\n";
cout << "Enter 4 For Volume Conversion\n";
cout << "Enter 5 For Length Conversion\n";
cout << "Enter 6 For Mass Conversion\n";
cout << "Enter 0 To Exit\n";
cin >> user_selection;

if(user_selection == 1)//Time Conversion Block
{
system("CLS");
cout << '\n';

while(user_selection != 9)
{
cout << "Enter 1 For Second To Minute\n";
cout << "Enter 2 For Minute To Second\n";
cout << "Enter 3 For Second To Hour\n";
cout << "Enter 4 For Hour To Second\n";
cout << "Enter 5 For Minute To Hour\n";
cout << "Enter 6 For Hour To Minute\n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;

if(user_selection == 1) 
{
cout << "Enter The Second(s): ";
cin >> value;
cout << value << " Second(s) is " << converter.secondToMinute(value) << " Minute(s) " << endl;
}
else if(user_selection == 2)
{
cout << "Enter The Minutes(s): ";
cin >> value;
cout << value << " Minute(s) is " << converter.minuteToSecond(value) << " Second(s) " << endl;
}
else if(user_selection == 3)
{
cout << "Enter The Second(s): ";
cin >> value;
cout << value << " Second(s) is " << converter.secondToHour(value) << " Hour(s) " << endl;
}
else if(user_selection == 4)
{
cout << "Enter The Hour(s): ";
cin >> value;
cout << value << " Hour(s) is " << converter.hourToSecond(value) << " Second(s) " << endl;
}
else if(user_selection == 5)
{
cout << "Enter The Minute(s): ";
cin >> value;
cout << value << " Minute(s) is " << converter.minuteToHour(value) << " Hour(s) " << endl;
}
else if (user_selection == 6)
{
cout << "Enter The Hour(s): ";
cin >> value;
cout << value << " Hour(s) is " << converter.hourToMinute(value) << " Minute(s) " << endl;
}
}
}
else if(user_selection == 2) // Area Conversion Block
{
while(user_selection != 9)
{
cout << "Press 1 For Hectare To Square Meter \n";
cout << "Press 2 For Square Meter To Hectare \n";
cout << "Enter 3 For Acre to Square Meter \n";
cout << "Enter 4 For Square Meter To Acre \n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;
if(user_selection == 1)
{
cout << "Enter The Hectare(s): ";
cin >> value;
cout << value << " Hectare(s) is " << converter.hectToSqmet(value) << " Square Meter(s) " << endl;
}
else if(user_selection == 2)
{
cout << "Enter The Square Meter(s): ";
cin >> value;
cout <<  value << " Square Meter(s) is " << converter.sqmetToHect(value) << " Hectare(s) " << endl;
}
else if (user_selection == 3)
{
cout << "Enter The Acres(s): ";
cin >> value;
cout << value << " Acre(s)  " << converter.acreToSqmet(value) << " Square Meter(s) " << endl;
}
else if(user_selection == 4)
{
cout << "Enter The Square Meter(s): ";
cin >> value;
cout << value << " Square Meter(s) is " << converter.sqmetToAcre(value) << " Acre(s) " << endl;
}
}
}
else if(user_selection == 3) // Temperature Conversion Block
{
while(user_selection != 9)
{
cout << "Enter 1 For Celsius To Fahrenheit \n";
cout << "Enter 2 For Fahrenheit To Celsius \n";
cout << "Enter 3 For Celsius To Kelvin\n";
cout << "Enter 4 For Kelvin To Celsius\n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;

if(user_selection == 1)
{
cout << "Enter The Celsius: ";
cin >> value;
cout << value << " Celsius is " << converter.celToFah(value) << " Fahrenheit " << endl;
}
else if(user_selection == 2)
{
cout << "Enter The Fahrenheit: ";
cin >> value;
cout << value << " Fahrenheit is " << converter.fahToCel(value) << " Celsius " << endl;
}
else if(user_selection == 3)
{
cout << "Enter The Celsius: ";
cin >> value;
cout << value << " Celsius is " << converter.celToKel(value) << " Kelvin " << endl;
}
else if(user_selection == 4)
{
cout << "Enter The Kelvin: ";
cin >> value;
cout << value << " Kelvin is " << converter.kelToCel(value) << " Celsius " << endl;
}
}
}
else if(user_selection == 4) // Voluume Conversion Block
{
while(user_selection != 9)
{
cout << "Enter 1 For Liter To Gallon\n";
cout << "Enter 2 For Gallon To Liter\n";
cout << "Enter 3 For Liter To Cube\n";
cout << "Enter 4 For Cube To Liter\n";
cout << "Enter 5 For Liter To Pint\n";
cout << "Enter 6 For Pint To Liter\n";
cout << "Enter 7 For Liter To Gill\n";
cout << "Enter 8 For Gill To Liter\n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;

if(user_selection == 1)
{
cout << "Enter Liter(s): ";
cin >> value;
cout << value << " liter(s) is " << converter.literToGallon(value) << " gallon(s) " << endl;
}
else if(user_selection == 2)
{
cout << "Enter Gallon(s): ";
cin >> value; 
cout << value << " gallon(s) is " << converter.gallonToLiter(value) << " liter(s) " << endl;
}
else if(user_selection == 3)
{
cout << "Enter Liter(s): ";
cin >> value;
cout << value << " liter(s) is " << converter.literToCube(value) << " cube(s) " << endl;
}
else if(user_selection == 4)
{
cout << "Enter Cube(s): "; // Cubic Centimeter
cin >> value;
cout << value << " cube(s) is " << converter.cubeToLitre(value) << " liter(s) " << endl;
}
else if(user_selection == 5)
{
cout << "Enter Liter(s): ";
cin >> value;
cout << value << " liter(s) is " << converter.literToPint(value) << " pint(s) " << endl;
}
else if(user_selection == 6)
{
cout << "Enter Pint(s): ";
cin >> value;
cout << value << " pint(s) is " << converter.pintToLiter(value) << " liter(s) " << endl;
}
else if(user_selection == 7)
{
cout << "Enter Liter(s): ";
cin >> value;
cout << value << " liter(s) is " << converter.literToGill(value) << " gill(s) " << endl;
}
else if(user_selection == 8)
{
cout << "Enter Gill(s): ";
cin >> value;
cout << value << " gill(s) is " << converter.gillToLiter(value) << " liter(s) " << endl;
}
}
}
else if(user_selection == 5) // Length Conversion Block
{
while(user_selection != 9)
{
cout << "Enter 1 For Meter To Kilometer\n";
cout << "Enter 2 For Kilometer To Meter\n";
cout << "Enter 3 For Meter To Yard\n";
cout << "Enter 4 For Yard To Meter\n";
cout << "Enter 5 For Meter To Inch\n";
cout << "Enter 6 For Inch To Meter\n";
cout << "Enter 7 For Mile To Kilometer\n";
cout << "Enter 8 For Kilometer To Mile\n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;

if(user_selection == 1)
{
cout << "Enter Meter(s): ";
cin >> value;
cout << value << " meter(s) is " << converter.meterToKilometer(value) << " kilometer(s)" << endl;
}
else if(user_selection == 2)
{
cout << "Enter Kilometer(s): ";
cin >> value;
cout << value << " kilometer(s) is " << converter.kilometerToMeter(value) << " meter(s) " << endl;
}
else if(user_selection == 3)
{
cout << "Enter Meter(s): ";
cin >> value;
cout << value << " meter(s) is " << converter.meterToYard(value) << " yard(s) " << endl;
}
else if(user_selection == 4)
{
cout << "Enter Yard(s): ";
cin >> value;
cout << value << " yard(s) is " << converter.yardToMeter(value) << " meter(s) " << endl;
}
else if (user_selection == 5)
{
cout << "Enter Meter(s): ";
cin >> value;
cout << value << " meter(s) is " << converter.meterToInch(value) << " inch(es) " << endl;
}
else if(user_selection == 6)
{
cout << "Enter Inch(es): ";
cin >> value;
cout << value << " inch(es) is " << converter.inchToMeter(value) << " meter(s) " << endl;
}
else if(user_selection == 7)
{
cout << "Enter Mile(s): ";
cin >> value;
cout << value << " mile(s) is " << converter.mileToKilometer(value) << " kilometer(s) " << endl;
}
else if(user_selection == 8)
{
cout << "Enter Kilometer(s): ";
cin >> value;
cout << value << " kilometer(s) " << converter.kilometerToMile(value) << " mile(s) " << endl;
}
}
}
else if(user_selection == 6) // Mass Vonversion Block
{
while(user_selection != 9)
{
cout << "Enter 1 For Kilogram To Tonne\n";
cout << "Enter 2 For Tonne To Kilogram\n";
cout << "Enter 3 For Kilogram To Ounce\n";
cout << "Enter 4 For Ounce To Kilogram\n";
cout << "Enter 5 For Kilogram To Pound\n";
cout << "Enter 6 For Pound To Kilogram\n";
cout << "Enter 7 For Kilogram To Slug\n";
cout << "Enter 8 For Slug To Kilogram\n";
cout << "Enter 9 To Go Back\n";
cin >> user_selection;

if(user_selection == 1)
{
cout << "Enter Kilogram(s): ";
cin >> value;
cout << value << " kilogram(s) is " << converter.kilogramToTonne(value) << " tonne(s) " << endl;
}
else if(user_selection == 2)
{
cout << "Enter Tonne(s): ";
cin >> value;
cout << value << " tonne(s) is " << converter.tonneToKilogeam(value) << " kilogram(s) " << endl;
}
else if(user_selection == 3)
{
cout << "Enter Kilogram(s): ";
cin >> value;
cout << value << " kilogram(s) is " << converter.kilogramToOunce(value) << " ounce(s) " << endl;
}
else if(user_selection == 4)
{
cout << "Enter Ounce(s): ";
cin >> value;
cout << value << " ounce(s) is " << converter.ounceToKilogram(value) << " kilogram(s) " << endl;
}
else if(user_selection == 5)
{
cout << "Enter Kilogram(s): ";
cin >> value;
cout << value << " kilogram(s) is " << converter.kilogramToPound(value) << " pound(s) " << endl;
}
else if(user_selection == 6)
{
cout << "Enter Pound(s): ";
cin >> value;
cout << value << " pound(s) is " << converter.poundToKilogram(value) << " kilogram(s) " << endl;
}
else if(user_selection == 7)
{
cout << "Enter Kilogram(s): ";
cin >> value;
cout << value << " kilogram(s) is " << converter.kilogramToSlug(value) << " slug(s) " << endl;
}
else if(user_selection == 8)
{
cout << "Enter Slug(s): ";
cin >> value;
cout << value << " slug(s) is " << converter.slugToKilogram(value) << " kilogram(s) " << endl;
}
}
}
}
}

WHICH PROGRAMMING LANGUAGE SHOULD I LEARN FIRST?

This question is quite difficult to answer, because it depends on many things. It depends on why you want to learn programming, is it for fun? Is it because you want to get some money? It also depends on which field of programming you like Web Development, System Programming, Application Programming, Mobile Applications Development. In this article I summarise details on some programming languages I know, so you can read and make a decision on which programming language you should learn first.
Python is an easy programming language that is frequently recommended for beginners. Don't underestimate this programming language because you heard that it is easy, Python is powerful and many large projects were built with it. Python is a General-Purpose programming language that can be used to build Standalone and Web Applications. You can become a professional python programmer within short time if you devote yourself to learning it.
C is one of oldest programming languages but it is still in use today. It is mostly used for system programming and is easier than C++. Consider learning this language if you are planning to become a system programmer. Some professional programmers also recommend learning C before C++, since C is a subset of C++. Therefore, this will help you immensely before you start learning the very complex C++.
What makes Java so popular is its "Write-Once-Read-Anywhere" slogan. Java applications are only compiled once and you can run them on any platform. Consider learning Java if you want to make Enterprise Applications. In difficulty, Java is quite easier than C++ but more difficult than C.
PHP is a web-scripting language, learn it if you want to get into Web Developing. It is easy and has no strict rules that are found in other programming languages. PHP is mostly used at the back-end of website for example to handle form data or fetch some data from database.
C++ is a superset of C. Hence, any valid C program is also a valid C++ program but not any valid C++ program is a valid C program. C++ is difficult to learn but its difficulty comes with its great power, it is one of the most powerful programming languages. It is general purpose and object-oriented programming that can be used in programming almost everything, ranging from system software, game programming and many variety of application software .C++ is not recommended for beginners who have no programming experience but if you know programming you can go for it.
JavaScript is a front-end web programming language that is used to make browser applications. JavaScript is underestimated, but this programming language is powerful. And I think it is worth noting that JavaScript and Java are two different programming languages that are not related. JavaScript is a must-learn for web developers.
Objective-C is a programming language created by Apple to program devices that are running iOS and OS X Operating Systems. Learn this language if you are targeting apple products.
C# is similar to Java in syntax. It is created by Microsoft to program applications that run on Windows machine. If you know Java you can easily learn this language.
Ruby is a General-Purpose programming language that is getting popular these days. Ruby has a powerful framework called “Ruby On Rails” that is used to build web applications.
Learning new programming languages depends on the zeal one has and why he wants to learn it. When one has the zeal he can learn any programming language with ease.

Sunday, 22 February 2015

HOW TO REDUCE THE NUMBER OF PROGRAMS THAT START AUTOMATICALLY WHEN YOU TURN ON YOUR WINDOWS COMPUTER

You may like to reduce the programs to increase the speed of your system, or you may just want to see the programs that start when your computer has finished booting, Whatever is your reason,below are steps that you can follow if you want to reduce the number programs that start automatically when you turn on your computer.

  • From your desktop screen click on the START (If you are an average Windows user, you must know this), then type "msconfig" without the quotation marks.
  • Click on the programs that appear with name you have typed.
  • A small dialog box will appear with the title "System Configuration". There are five horizontal tabs on top of this dialog box, click on Startup among the tabs.
  • The list of programs that start automatically when you turn on your computer will appear, go ahead and uncheck any unnecessary program, then click apply.
  • Click OK, the system will request you to restart your system, restart the computer and then you are done.

Saturday, 21 February 2015

WHAT A NEW PROGRAMMER MUST KNOW

There are some programming concepts a new programmer must know before he start learning any programming language. These concepts are,

Variable:- You can think of a variable as a container for storing values. Variables are used in programming languages to store data, the data can be in form of characters, numbers or Boolean.

(     Control-Flow/Decision Making:- Decision making is the ability of a program to make a decision during its execution. Without this feature, creation of complex software will not be feasible. Decision Statements like IF, IF-ELSE, SWITCH are used in controlling the flow of program execution or make a decision. For example, your program has a form where user can enter his details, but if the user enter wrong details the program must make a decision on what to do next.

Loop:- Looping is like repeating something, most of the world programming languages have this feature. Looping is used when you want to do something repeatedly for a number of times. For example, if you want your program to print same lines of text let’s say one hundred times, it is a huge waste of time to write one hundred lines of code that print the same text. But you can put your one line that print the text in a loop and make the loop to execute one hundred times. However, you should know that too much loops can slow down your program.

Wednesday, 14 January 2015

HOW TO CREATE ADOBE SHOCKWAVE (.swf) FILE USING MICROSOFT POWER-POINT AND TOTAL VIDEO CONVERTER

I was creating a website and I need software that can create Adobe Shockwave file for me, unfortunately all the software I came accross that are used in creating the swf file are commercial. So I found a clever way that I can use to create the (.swf) file using Microsoft Power-Point and Total Video Converter. You should also know that my version of Microsoft Office is 2010.
Below are the steps:-

1. Open Power-Point and create a slideshow of some few slides, may be 3, 4 or 5 slides.

2. Press CTRL+S or follow whatever procedure you are using when saving a document in Power-Point.

3. When The SAVE Dialog box appears, give your file a name. Below where you type the name is a Select Box, click on it and select Windows Media Video and then click Save to save your file. 

4. You have just created a Video File. Now open Total Video Converter.

5. Import the video file you just create. Normally, when you import a file in Total Video Converter a dialog box will appear that will enable you to select the type of the file format you want to convert your imported file. Now select SWF in the video file section. Look at the image below. 













You have now created your SWF file; you can use it as slideshows on your websites instead of using the hard way of creating slideshow with JavaScript.

Friday, 9 January 2015

STEPS WITH PICTURES ON HOW TO CREATE A DATABASE AND TABLE IN PHPMYADMIN

Login to your phpmyadmin.

There are horizontal tabs at the top of the phpmyadmin page. Database is the first tab from the left side of your screen, click on the database.















The new page that will appear will be similar to the one in the image below, insert the name of your database in the text box indicated in the image below.









After you have written the name of your database, click on the create button to the right of the text box you write your database name.









You have now created your database. Let’s assume that the name of the database you just create is mydata. The database name will appear in the list of databases on the very page you use to create it.















Click on the name of the database you just create.  A page similar to the one below will appear.









Now we are going to create a table. Insert the name of your table and its number of columns in the textboxes accordingly. Let’s say we want to create a table that will contain customers name, email, and address. By looking at the image below, you will see that the table name is customers and the number of columns is 4. You can give the table any name of your choice, but it should be meaningful. You may be wondering why do we put 4 in the column field while we only need three field to accommodate name, email and address, we put the column number to be 4 because we want our table to have an id. You can create a table without an id, id is useful when creating tables like that of users, customers etc. You also don’t have to interact with the id field when inserting data from your CGI script, since ids are always set to AUTO_INCREMENT.











Now click Go.









A page similar to the one below will appear.














Now you give name to your fields in the text boxes below Name, You also use the select boxes to the right of the text boxes you write your field names to select the data type you want your fields to hold. The Length/Values text boxes are where you will give the length of your fields, for instance if you want your field to contain only 10 characters, you have to insert 10 in its length/Values text box. In the image below, you will notice that we have filled all the fields accordingly. The names of our 4 fields are id, name, email and address. The id type is INT because it will hold numbers, the remaining fields all have their types as VARCHAR, by setting the type of these fields to be VARCHAR they can contain combination of characters both numbers and alphabets. The field lengths are also set according to my estimate. You will also notice that I check the id field check box below A_I, this is necessary to make the id field AUTO_INCREMENT.













Click save












Work Done! You have now create your table, and a page with the table name, similar to the one below will appear.