## Least and Greatest Common Factors

I like building calculators, there fun and easy to do. Here is a calculator which will determine the Greatest Common Divisor and Least Common Multiple. You need two Numericupdown , Button and two Textboxes. Here is a picture of design. Code :

```Public Class Form1
Public Function GCD(ByVal a As Integer, ByVal b As Integer) As Integer
Dim Remainder As Integer

While (b <> 0)

Remainder = a Mod b
a = b
b = Remainder
End While

Return a
End Function
Private Sub btnCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCal.Click

If (nupdnValue1.Value = 0 Or nupdnValue2.Value = 0) Then
MsgBox("You can not have zero as a compare number!")
Else
tbGCD.Text = GCD(nupdnValue1.Value, nupdnValue2.Value)
tbLCM.Text = ((nupdnValue1.Value * nupdnValue2.Value) \ tbGCD.Text)
End If
End Sub
End Class```

The NumericUpDown widgets are nupdnValue1 and nupdnValue2. Button is called btnCal and the textboxes are called tbGCD for GCD and tbLCM for LCM. Both formulas use the GCD function the guts of the program. Here is a link to demonstrate Greatest Common Factor(Divisor) and Least Common Multiple. Click Here

## Wallpaper Calculator

Spring is here and home improvements are in the works. Here is a Wallpaper Calculator made using Visual Basic. You will need 3 Numerical up/dn box and 3 textboxes. Here is picture of design. Code :

```Public Class Form1

Private Sub bntCal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntCal.Click

If (nupdnHeight.Value = 0 Or nupdnLength.Value = 0 Or nupdnWidth.Value = 0) Then
MsgBox("You must have value for height, length and width!")
Else
Dim strips_per_roll As Double = CInt(rolllength.Text) \ nupdnHeight.Value
Dim perimeter As Integer = 2 * (nupdnLength.Value + nupdnWidth.Value)
Dim strips_reqd As Double = perimeter \ CInt(rollwidth.Text)
'Number of Rolls with 5% watse
nrolls.Text = CInt((((0.05 * strips_reqd \ strips_per_roll) + strips_reqd) \ strips_per_roll))
End If

End Sub
End Class```

The NumericUpDown widget’s are nupdnHeight. nupdnLength and nupdnWidth. The Texboxes are rollwidth and rolllength. You will need a Button called bntCal too. You always have waste for wallpaper jobs so I added 5% waste in calculation.  All calculations are  made in inches. Default common values are inputed for  roll width and roll length. You can change values but try to keep everything in inches.

## Compile QT program in Mint Linux

First you need a few QT4 tools.  Type

`sudo apt-get install qt4-dev-tools libqt4-dev libqt4-core libqt4-gui g++`

I needed g++ because on Mint Linux version 3.5.0-17-generic it was not installed. Now to test out a program. Copy this code below to file slider.cpp. This QT program demonstrates three widgets label,spin-box and slider which will all change together.

```//slider.cpp
#include <QApplication>
#include <QVBoxLayout>
#include <QLabel>
#include <QSpinBox>
#include <QSlider>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
QVBoxLayout* mainLayout = new QVBoxLayout(&window);
QLabel* label = new QLabel("0");
QSpinBox* spinBox = new QSpinBox;
QSlider* slider = new QSlider(Qt::Horizontal);
QObject::connect(spinBox, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
QObject::connect(spinBox, SIGNAL(valueChanged(int)),
slider, SLOT(setValue(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
label, SLOT(setNum(int)));
QObject::connect(slider, SIGNAL(valueChanged(int)),
spinBox, SLOT(setValue(int)));
window.show();
return a.exec();
}```

You should copy above file under your Home directory.  Open up Terminal and type

`mkdir qtslider`

Change to new directory

`cd qtslider`

Create QT project which will make pro file. Make sure the slider.cpp is in qtslider directory.

`qmake -project`

Create Makefile Type

`qmake`

Compile Type

`make`

If everything went well you can now run file. You should get a dialog like the picture below.

`./qtslider` List files Type

`ls`

Here are all files made with all the above commands.

`Makefile  qtslider  qtslider.pro  slider.cpp  slider.o`