Wednesday

View Stack data structure source code from CodeBlocks and g++

View Stack data structure source code from CodeBlocks and g++

Open CodeBlocks

Create a CodeBlocks project
Menu > File > New > Project > Console application > Go button
Follow on-screen instructions

Replace all the main.cpp content with the below code.
{{{{{
#include <iostream>
#include <stack>
using namespace std;

int main(int argc, char* argv[])
{
    stack<int> mystack;

    mystack.push(1);
    mystack.push(2);
    mystack.push(3);

    cout << "stack size: " << mystack.size() << endl;

    cout << "stack content in LIFO context: ";
    while(!mystack.empty())
    {
        cout << mystack.top() << " ";
        mystack.pop();
    }
    cout << endl;

    return 0;
}
}}}}}

Right-click at the push() method of the mystack object on the line “mystack.push(1);”, select “Find implementation of: push”

The stack data structure source code from the g++.exe compiler is at:
“C:\program files (x86)\codeblocks\MinGW\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_stack.h”
File name: stl_stack.h
Both the stack class declaration and implementation are coded in this header file.

You can view the push() method implementation of the stack class as shown below:
{{{{{
      /**
       *  @brief  Add data to the top of the %stack. //documentation comments
       *  @param  __x  Data to be added.
       *
       *  This is a typical %stack operation.  The function creates an
       *  element at the top of the %stack and assigns the given data
       *  to it.  The time complexity of the operation depends on the
       *  underlying sequence.
       */
      void                                         
      push(const value_type& __x)  //call by reference
      { c.push_back(__x); }
}}}}}

Right-click on the “deque” word on top of the “class stack” line as shown below and select “Find declaration of: deque”.
{{{{{
  template<typename _Tp, typename _Sequence = deque<_Tp> >
    class stack
    {
        . . .
}}}}}

The g++ stack class is implemented as a container adapter. It uses the standard deque data structure.
The stl_deque.h is at:
C:\program files (x86)\codeblocks\MinGW\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_deque.h
Press Ctrl+F and search for the “push_back” method.
The push_back() method implementation for the deque data structure is shown below:
{{{{{
      void
      push_back(const value_type& __x)
      {
    if (this->_M_impl._M_finish._M_cur
        != this->_M_impl._M_finish._M_last - 1)       // deque capacity is not full
      {                                                                      // add data to the end of the deque
        this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
        ++this->_M_impl._M_finish._M_cur;
      }
    else                                                                    // else add data to the end of the auxiliary deque
      _M_push_back_aux(__x);
      }
}}}}}

Due to the nature of the deque data structure, this push_back() operation can be done in constant time.

Sunday

How to debug your C++ code in CodeBlocks?

How to debug your C++ code in CodeBlocks?

You have to create a C++ project in CodeBlocks before you can start using the CodeBlocks debugger.

Use the following code.
File name: main.cpp
File content:
{{{{{
01 #include <iostream>
02 using namespace std;
03
04 int add(int a, int b);
05
06 int main(int argc, char* argv[])
07 {
08    int x=5, y=2, z;
09
10    z = add(x,y);
11
12    cout << "z value is " << z << endl;
13
14    return 0;
15 }
16
17 int add(int a, int b)
18 {
19    int c;
20
21    c = a + b;
22
23    return c;
24 }
}}}}}

Open the Watches window to watch certain variables during the execution of the program:
Menu > Debug > Debugging windows > Watches

You can start debugging at any line of your code:
-- Put the mouse cursor on line 8 which is the initialization values of variables
-- Press F4 to run to cursor
-- Press F7 to debug next line which is the add() function "z = add(x,y)"
-- While debugging, check all the variable values in the Watches window. You can see that x=5, y=2, and z is set to a random value
-- Press Shift+F7 to step into the body of the add() function
-- Press F7 to debug next line
-- In the watches window, you can know the local variable values of add() function where a=5, b=2, and c=7
-- Click on the "Toolbar > Debug > Step out" to step out from the add() function
-- Press F7 to debug next line
-- In the watches window, you can see that z=7
-- Press F7 to debug next line
-- Check out the command prompt window, you will get the program output "z value is 7"
-- Press F8 to continue debugging and your program will run to completion. Try not to select from the Debug menu "Break debugger" because you want your program to end naturally rather than aborting.

You can debug your program at multiple lines from all your marked out breakpoints:
-- Click on line 10 "z = add(x,y);" and press F5 to insert a breakpoint.
-- Click on line 21 "c = a + b;" and press F5 to insert a breakpoint.
-- Press F8 to start debugging. The debugger will pause at line 10 as the first breakpoint
-- In the watches window, you can see that x=5, y=2, and z is set to a random value
-- Press F8 to continue debugging at line 21 as the second breakpoint
-- Click on the "Toolbar > Debug > Step out" to step out from the add() function
-- Press F7 to debug next line
-- Press F7 to debug next line
-- Check out the command prompt window, you will get the program output "z value is 7"
-- Press F8 to continue debugging and your program will run to completion.

Saturday

How to download and run LibreOffice Portable version from your flash drive

How to download and run LibreOffice Portable version from your flash drive:

Download to flash drive and double-click to install LibreOffice Portable version from

https://www.libreoffice.org/download/portable-versions/

Direct link to the executable file is at

http://download.documentfoundation.org/libreoffice/portable/5.0.2/LibreOfficePortable_5.0.2_MultilingualStandard.paf.exe

Why do you choose LibreOffice software as your office suite?
** LibreOffice is an open source software
** LibreOffice is available for a variety of computing platforms including Microsoft Windows, Mac OS X, Linux, LibreOffice Viewer for Android
** Has portable version
** Most importantly, LibreOffice includes the all familiar pull-down menus, customizable toolbars, and buttons as default

Android Phone: How to enable Child mode by allowing only education apps to be played by your child

Android Phone: How to enable Child mode by allowing only education apps to be played by your child:
-- Home screen > Settings > Child mode

Thursday

DiGi Super Long Life RM38 (365 days) Activation Year 2015, Free Credit Balance Retrieval

DiGi Super Long Life is a feature where you can extend your talktime validity to 1 year for just RM38. Indirectly, the subscription fee is RM3.17 per month to stay connected

If you can’t activate DiGi Super Long Life RM38(365 days), change your DiGi Best Prepaid v3 or v4 current prepaid plan to the DiGi’s latest plan which is DiGi New Best Prepaid. RM3 will be charged from your account

To change DiGi plan from DiGi Best Prepaid v3 to DiGi New Best v1 via *128#:
Step 1: Dial *128# and then press call
Type faster else you will get error message that: Your active session is expired. Please try again.
Step 2: Send 1 for My Account
Step 3: Send 4 for Call Plan
Current Call Plan: DiGi Best Prepaid v3
Step 4: Send 1 to Change Plan
Step 5: Send 1 for Digi New Best v1
Digi New Best v1: RM3:00 will be charged. Press 1 to confirm.
Step 6: Send 1 to Confirm
Your request is in progress. Pls dial *128# and access My Account to check if the change is successful.
Step 7: Press the OK button
Step 8: Wait for the sms
First sms, You have subscribed/purchased to FN_Digi_NewBest_v1 (FN is Full Name), Pay-As-You-Use PAYU NEW BEST v1, Daily Max Cap DMC RM3.
Second sms, You have unsubscribed FN_DiGi_NewBest, PAYU Pay-As-You-Use Best.
Third sms, You have changed your rate plan to Digi New Best v1. This transaction was charged with RM 3.00 excl GST.
Step 9: Dial *128*1*4# and then press call to check your current prepaid plan
Current Call Plan: Digi New Best v1
Step 10: Press the OK button

What are the unique selling points of Digi New Best Prepaid?
Digi Smart Prepaid gives you.
-- Affordable lowest rates to call/sms 10 Kawan(Friends) from all local mobile networks.
-- Worry free high speed Internet. (Daily Max Cap RM3 charged if you are not on the DiGi Internet subscription plan)
-- Guaranteed lowest IDD rates.

What are the tariffs and SIM pack price of Digi New Best Prepaid?
New Best “Affordable”
SIM SKU
(stock keeping unit)
RRP (recommended retail price)
RM8
Preloaded
RM5
Validity
30-days
Tariffs
Voice (all-network)
10sen (30-sec)
SMS (all-network)
6sen
PAYU
(Pay-As-You-Use)
5sen/MB,
DMC (Daily Max Cap) RM3,
Forced hard stop after DMC
(Daily Max Cap)
Best 10 Kawan
(Best 10 Friends)
Voice (all-network)
5sen (30sec)
SMS (all-network)
2sen SMS

To activate DiGi Super Long Life via *128#:
Step 1: You must have at least RM43 in your account.
Step 2: Dial *128# and then press call.
Step 3: Send 1 for My Account.
Step 4: Send 7 for Talktime Services.
Step 5: Send 3 for Super Long Life.
Step 6: Send 2 for Super Long Life RM38 (365 days). Be careful. Do not send 1 unless you really want RM5 for 30 days only.
Super Long Life: You have selected RM38.00 with 365 days validity. Press 1 to confirm your selection.
Step 7: Send 1 to confirm that you have selected RM38.00 with 365 days validity.
Thank you for choosing Super Long Life. You now have one less thing to worry about
for the next 365 days! Press the OK button
Notes:
You will not receive a confirmation SMS from Digi 2900. Your validity purchase of 365 days for RM38.00 is successful. Your new date of expiry is XX/XX/2016.
This feature is available for DiGi New Best Prepaid v1 subscribers only.

Free Credit Balance Retrieval
-- Dial *126# and then press call to find out how much talktime you have
-- Reload before: XX/XX/2016. 1 GB Internet at only RM5! Dial *116*4# now

90 Days Incoming Calls
-- Receive incoming calls for 90 days even though your reload validity has expired.

DiGi Helpline contact is +6016 2211 800.

Try not to receive any call while travelling overseas. You will incur expensive roaming charges.
Using your mobile phone in places other than its home area is called roaming.

The Digi New Best Prepaid v1 allows you to enjoy lowest 5sen call rate and 2sen SMS rate via Best 10 Kawan(Friends).
The New Best v1 also allows you to enjoy worry free Internet from 5sen/MB, which has a maximum charge per day of RM3 only, so that you don’t get credit loss with high PAYU pay-as-you-use rate if you are not on our Internet subscription plan.

How to remove Adobe Acrobat PDF plug-in manually from the Firefox browser?

Do the following steps:

Type about:plugins in the address bar

Find the Adobe Acrobat section to get the following information:
File: nppdf32.dll, nppdf32.dll
Path:
C:\Program Files (x86)\Adobe\Reader 11.0\Reader\browser\nppdf32.dll,
C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AIR\nppdf32.dll

Rename and move the following files out to a different location:
C:\Program Files (x86)\Adobe\Reader 11.0\Reader\browser\nppdf32.dll,
C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AIR\nppdf32.dll

By clicking on the "Firefox Menu > Tools > Add-ons > Plugins", you will notice that the "Adobe Acrobat" plugin is successfully removed

Sunday

Thursday

LibreOffice Writer: Generate random text

Steps:

Download and install LibreOffice's Main Installer from
www.libreoffice.org/download/

Open LibreOffice Writer

Type "dt"
dt stands for dummy text or random text

Press F3.

Dummy text output:
````
He heard quiet steps behind him. That didn't bode well. Who could be following him this late at night and in this deadbeat part of town? And at this particular moment, just after he pulled off the big time and was making off with the greenbacks. Was there another crook who'd had the same idea, and was now watching him and waiting for a chance to grab the fruit of his labor? Or did the steps behind him mean that one of many law officers in town was on to him and just waiting to pounce and snap those cuffs on his wrists? He nervously looked all around. Suddenly he saw the alley. Like lightning he darted off to the left and disappeared between the two warehouses almost falling over the trash can lying in the middle of the sidewalk. He tried to nervously tap his way along in the inky darkness and suddenly stiffened: it was a dead-end, he would have to go back the way he had come. The steps got louder and louder, he saw the black outline of a figure coming around the corner. Is this the end of the line? he thought pressing himself back against the wall trying to make himself invisible in the dark, was all that planning and energy wasted? He was dripping with sweat now, cold and wet, he could smell the fear coming off his clothes. Suddenly next to him, with a barely noticeable squeak, a door swung quietly to and fro in the night's breeze. Could this be the haven he'd prayed for? Slowly he slid toward the door, pressing himself more and more into the wall, into the dark, away from his enemy. Would this door save his hide?
````

LibreOffice: How to position picture correctly?

To position the picture correctly in LibreOffice:

1. Insert a picture on a blank line

2. Right-click on the image > Anchor > As Character

Tuesday

Getting started with C++ 2011 in Eclipse IDE

Download Eclipse IDE for C/C++ Developers Windows 32-bit at
http://www.eclipse.org/downloads/
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/luna/SR2/eclipse-cpp-luna-SR2-win32.zip

Extract the zip file to
C:\eclipse-cpp-luna-SR2-win32
Don't name the folder as eclipse only

Create the following executable file shortcut on the desktop
C:\eclipse-cpp-luna-SR2-win32\eclipse.exe
Name the shortcut link as eclipse-cpp-luna-SR2-win32

Download and install CodeBlocks v13.12
http://www.codeblocks.org/downloads/
http://sourceforge.net/projects/codeblocks/files/Binaries/13.12/Windows/codeblocks-13.12mingw-setup.exe

Copy MinGW folder from
C:\Program Files (x86)\CodeBlocks\MinGW
to
C:\MinGW

Open Eclipse C++ IDE
Workspace: D:\my_cpp_2011
Tick the box "Use this as the default and do not ask again"
Click button OK
Click the Workbench curve down icon to start C++ programming

Eclipse Menu > Window > Preferences

Left menu > General > Editors > Text Editors
Tick the box "Insert spaces for tabs"
Tick the box "Show line numbers"
Click the button Apply

Left menu > C/C++ > Editor > Folding
Tick the box "Enable folding of preprocessor branches (#if/#endif)"
Tick the box "Enable folding of control flow statements (if/else, do/while, for, switch)"
Untick the box "Header Comments"
Click the button Apply

Left menu > C/C++ > New C/C++ Project Wizard
Check if you are on "Preferred Toolchains" tab
Go to "Project type" section box
Select "Empty Project" under Executable
Go to Toolchains section box
Select MinGW GCC row
Click the button "Make toolchain(s) preferred"
Click the button Apply

Click the button OK

Eclipse Menu > New > C++ Project
Project name: prjCpp3
Project type: Hello World C++ Project
Toolchains: MinGW GCC
Click button Finish

Go to Project Explorer frame
Right-click the prjCpp3 project folder > select "Build Project"
Right-click the prjCpp3 project folder > Run As > "1 Local C/C++ Application"

You can view the C++ code output in the Console frame

Replace the entire file content of prjCpp3.cpp with the following.
File name: prjCpp3.cpp
File content:
/**********/
/*
Output:
6 7 8
8
123
*/

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib> //for atoi
#include <sstream> //for sringstream

using namespace std;

int main(int argc, char* argv[])
{
    //vector initialization list
    vector<int> vec = {6, 7, 8};

    //auto data type, range-based for loop using colon
    for(auto elt : vec)
    {
        cout << elt << " ";
    }
    cout << endl;

    //convert from int to string
    //error: 'to_string' function is not available yet
    //string s1 = to_string(vec[2]);
    stringstream ss;
    ss << vec[2];
    string s1 = ss.str();
    cout << s1 << endl;

    //convert from string to int
    //error: 'stoi' function is not available yet
    string s2 = "123";
    //int i = stoi(s2);
    int i = atoi(s2.c_str());
    cout << i << endl;

    return 0;
}
/**********/


Go to Project Explorer frame
Right-click the project and go to Properties
Left menu > C/C++ Build > Settings > Tool Settings tab
Left menu > GCC C++ Compiler > Miscellaneous
Textfield: Other Flags: put "-std=c++11" at the end
Click button OK

Toolbar > click Run button

Close Eclipse C++ IDE

Monday

Getting Started with C++ 2014

Steps are as follows:

Download gcc v5.1.0 32-bit from
ftp://ftp.equation.com/gcc/gcc-5.1.0-32.exe
Install gcc v5.1.0 32-bit to "C:\gcc-5.1.0-32"

Download and install Notepad++ from
https://notepad-plus-plus.org/download/

The Path environment variable to run C++ 2014 on Windows 7 is configured automatically.
If not, open the Environment Variables frame through "Control Panel\System and Security\System".
Hit the end key to scroll to the end of the variable value textbox of variable name Path.
Then, type a semicolon at the end of the existing path, followed by the gcc executable binary directory, which is as follows:
;C:\gcc-5.1.0-32\bin;C:\gcc-5.1.0-32\libexec\gcc\i686-pc-mingw32\5.1.0

Restart your computer because of the installation of gcc v5.1.0 32-bit.

Open Notepad++
Save the new file as "cpp2014_no1.cpp"

File name: cpp2014_no1.cpp
File content:
/**********/
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    //binary literal
    auto binary_literal = 0b0001'1111;
    cout << binary_literal << endl;
   
    //digit separators
    auto integer_literal = 1'000'000;
    cout << integer_literal << endl;
   
    //generic lambda function
    auto lambda = [](auto x, auto y) {return x + y;};
    auto sum = lambda(1.2, 3.4);
    cout << sum << endl;
   
    return 0;
}
/**********/

Output:
C:\my_folder_path>g++ -std=c++14 cpp2014_no1.cpp -o a.exe

C:\my_folder_path>a
31
1000000
4.6

Step to uninstall GCC downloaded from 
http://www.equation.com/servlet/equation.cmd?fa=fortran
- Open the system path of Environment Variables frame
- Delete the system variable name EQ_LIBRARY_PATH which contains the following variable value
c:\gcc-5.1.0-32\i686-pc-mingw32\lib;
- Edit to delete only the following two system paths from the variable name Path:
--- c:\gcc-5.1.0-32\bin;
--- c:\gcc-5.1.0-32\libexec\gcc\i686-pc-mingw32\5.1.0;
- Delete the folder at C:\gcc-5.1.0-32

Tuesday

LaTeX: Mathematical operations using pgfmath and pgffor packages

Input file name: mathematics1_pgfmath_pgffor.tex
{
\documentclass[12pt,a4paper]{article}
\usepackage{pgfmath,pgffor}

\begin{document}

1 $+$ 2 $\times$ 3 = \pgfmathparse{int(1+2*3)}\pgfmathresult

2.0 $+$ 3.0 $\times$ 4.0 = \pgfmathsetmacro{\result}{2+3*4}\result

(1.0 $+$ 2.0) $\times$ 3.0 = \pgfmathparse{(1.0+2.0)*3.0}\pgfmathresult

%r to convert from radians to degrees, pi radians is 180 degrees
sin(pi/2 radians) = \pgfmathparse{round(sin(pi/2 r))}\pgfmathresult

sin(90 degrees) = \pgfmathparse{sin(90)}\pgfmathresult

$15^{3}$ = \pgfmathparse{int(15^3)}\pgfmathresult

15 power of 3 = \pgfmathparse{int(pow(15,3))}\pgfmathresult

$\sqrt{2}$ = \pgfmathparse{sqrt(2)}\pgfmathresult

pi = \pgfmathparse{pi}\pgfmathresult

pi radians to degrees = \pgfmathparse{int(round(pi r))}\pgfmathresult

radian(180 degrees) = \pgfmathparse{rad(180)}\pgfmathresult

degree(pi radians) = \pgfmathparse{int(round(deg(pi)))}\pgfmathresult

% generate a pseudo-random number between 0 and 1
rnd(0,1) = \pgfmathparse{rnd}\pgfmathresult

% generate a pseudo-random number between -1 and 1
rand(-1,1) = \pgfmathparse{rand}\pgfmathresult

\foreach \x in {1,2,...,10} {\x \hspace{5pt}} %\linebreak[4]

\pagebreak

{
\noindent
\foreach \i in {1,2,...,30}
{
$\i^{2}$ = \pgfmathparse{int(\i^2)}\pgfmathresult \\
}
}

\pagebreak

{
\noindent
\foreach \i in {1,2,...,15}
{
$\i^{3}$ = \pgfmathparse{int(\i^3)}\pgfmathresult \\
}
}

\end{document}
}

Output:
1 + 2 × 3 = 7
2.0 + 3.0 × 4.0 = 14.0
(1.0 + 2.0) × 3.0 = 9.0
sin(pi/2 radians) = 1.0
sin(90 degrees) = 1.0
15^{3} = 3375
15 power of 3 = 3375
2 = 1.41421
pi = 3.141592654
pi radians to degrees = 180
radian(180 degrees) = 3.14159
degree(pi radians) = 180
rnd(0,1) = 0.28926
rand(-1,1) = -0.79707
1 2 3 4 5 6 7 8 9 10


1^2 = 1
2
^2 = 4
3
^2 = 9
4
^2 = 16
5
^2 = 25
6
^2 = 36
7
^2 = 49
8
^2 = 64
9
^2 = 81
10
^2 = 100
11
^2 = 121
12
^2 = 144
13
^2 = 169
14
^2 = 196
15
^2 = 225
16
^2 = 256
17
^2 = 289
18
^2 = 324
19
^2 = 361
20
^2 = 400
21
^2 = 441
22
^2 = 484
23
^2 = 529
24
^2 = 576
25
^2 = 625
26
^2 = 676
27
^2 = 729
28
^2 = 784
29
^2 = 841
30
^2 = 900

1^3 = 1
2
^3 = 8
3
^3 = 27
4
^3 = 64
5
^3 = 125
6
^3 = 216
7
^3 = 343
8
^3 = 512
9
^3 = 729
10
^3 = 1000
11
^3 = 1331
12
^3 = 1728
13
^3 = 2197
14
^3 = 2744
15
^3 = 3375

If a hater attacked your age and not the goodness of you

Whether young or old, I've always been known what endures. I've known the very idea of people that were all created equal and deserv...