Saturday, June 30, 2018

Why do you need namespace in a C++ program?

All identifiers in C++ must be unique and, if this rule is not observed in naming you end up with what is called 'naming resolution. The C++ compiler faces an ambiguous situation and, will throw up an error message.

Providing namespace is to help the compiler know that the identifier must be associated with a namespace. This is in much the same was as saying someone lives in Washington (Which one the State or D.C?). It is not a problem with small programs and it becomes a problem for larger programs.

In addition to identifier scope (local, global), namespace provides yet another option to reduce the name conflict in programs.

Friday, June 29, 2018

How do you compile and run multiple files in a C++ project?

Projects can be simple, or complex and can run into many lines. You can write your code in multiple files, compile them together and run. You basically have a main program file that will call the other files. However, you need to indicate in the main file that you will be utilizing the other files.

Let us say, you want to calculate the area of a rectangle and the volume of rectangular solid and display them in the console. You can have a code file each, for calculating area and volume. You can display the calculated values in the main program.

This is carried out using Visual Studio Community (free) 2017.

Here is the project file

Here is how add a New CPP file.


A new file area.cpp was added and coded as shown.

Another new file vol.cpp was added as shown.


The AreaVolume project file AreaVolume.cpp is as shown. It calculates the area of a rectangle 5x5 and the volume of the solid with sides 4,5 and 6.

The two following two lines in AreaVoume.cpp reference the area.cpp and vol.cpp files:

int area(int x, int y);
int vol(int x, int y, int z);

If you compile and run this program you should see this in the display:


Note that the following is included in all the files:



Thursday, June 28, 2018

Can you initialize multiple variables in one statement?

Yes. You can initialize multiple variables in the same statement. Refer to the previous post and try out the following in Visual Studio Community 2017 (free) :
        int ix = 5, iy = 6;
  cout << ix << "," << iy;
cout << "\n";

This is also possible:

 int iz(7), izz{ 8 };
 cout << iz << "," << izz;
 cout << "\n";

This one as well possible:

 int a = 100, b(50), c{ 100 };
 cout << "a= " << a << " b= " << b << " c= "<< c;
 cout << "\n";

The result of running this is shown here:


Here is a copy of the code.


Wednesday, June 27, 2018

How do you initialize a variable in C++?

Let us say we are trying to initilaize a variable of type integer, iX. There are three ways you can initialize a variable.

We use the following statement to initialize:

int iX = 100;  This is the syntax for copy initialization.

This is called copy initialization saying that intX's value is 5.

In direct initiization you use the statement:

int iX(100);  This is the syntax for direct initialization but should not be confused with a function.

There is yet another kind of initialization stated this way:

This is called Uniform initizlization used most of the data types.
int  ix{100};

Review the following initialize.cpp file.

The file was created using a Blank C++ project in Visual Studio Community 2017 Version 15.5.7



Tuesday, June 26, 2018

How many days are left to 4th of July using Python?

Normally one is looking forward to a particular day such as birthday, Christmas day, fourth of July etc. Date and time being crucial information every programming language has date and time related data types and related methods.

In Python you need to import datetime and date and the date is in the format (year,month,day).
Here is how find the difference between today and the 4th of July.

In this shell program you get quite a bit of help in coding.



Monday, June 25, 2018

How do you print a Kannda (South Indian Language) word in Python using UTF-8?

Kannada (South Indian language) characters have the Unicode range from 0C80-0CCF 

UTF-8 is Python's default encoding.


 Let us take a simple word:
ಕಲಹ
Which means 'quarrel'. The letters are simple and you could use their Unicode equivalents
using this chunk of code block.

To form the word we concatenate the characters as shown,



What about a word such as this, ಅರಮನೆ? (means Palace)
The first three letters are simple but the fourth letter is a rendering with a diacritic of a simple letter 'ನ'. The fourth letter requires concatenating the two shown above:

In order to form the word à²…ರಮನೆ we need to do the following:




Does Power BI support Microsoft OLE DB provider for ODBC for data access?

Power BI supports only the .NET Framework OLE DB Provider for ODBC and does not support the Micrsoft OLE DB Provider for ODBC (MSDASQL).

If you create a Data Link file such as this one (ExcelNov.udl)  I created from an EXCEL file:

Provider=MSDASQL.1;Persist Security Info=False; Data Source=Excel64Test;Initial Catalog=C:\USERS\OWNER\DESKTOP\BLOG2017\MSSS2017\suiggy.xlsx


You cannot connect to EXCEL file using the Connection string such as the above. First of all, it does not support the attribute, Persist Security Info=false. Even if you remove this attribute, you will not be able to connect.

Review the following screen shots attempting to connect to EXCEL file using its Data Link, ExcelNov.udl.

Accessing the OLDDB option in GetData.



Using the connection string:


Removed the Security Information and trying to connect.


The ExcelNov.udl file is OK and the connection is successful but not for Power BI.




Sunday, June 24, 2018

How do you open a Word document using Power Shell?

You need to create a new COM object, namely a Word.Application in Power Shell.

After creating the new object you call the Documents to open providing a file name for the WORD document. If the intellisense is working you should be able to open the document following the drop-down menus shown here:

Creating a New-Object



$word= New-Object -ComObject Word.Application

$word.Documents:



There are three 'open' options. Open2002 did not work.
$word.Documents.Open


$fileName='C:\Users\Owner\Desktop\June5-7\Schedule.docx '



$word.Documents.Open($fileName)

This when run opens a large XML file in the console as well as the Word document 'Schedule.docx'




I have also encountered problems with the Power Shell interface. I suddenly stopped providing the intellisense drop-downs (for example, it did not provide the Open option but after typing in Open, it did provide intellisense again. This was sporadic).

Also opening was not clean as it also provided an XML with binary of the word document.

The Power shell version used on Windows 10 Pro(x64) was:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      17134  112  
 

Also all of a sudden you get a request for Outlook login(Surprise, surprise)




Saturday, June 23, 2018

How do you mulitply two matrices in R?

The Matrix package need not be loaded as it is readily accessible in Microsoft R Client version 3.3 (x64).

Here are two matrices whose product will be calculated.



Here is the result of matrix mulitplication of two 2x2 matrices showing the procedure
to calculate the product.

MatrixMultiply_2.png

Here is how it is calculated using R. The syntax is (matrix1)%*%(matrix2) where both matrices are square matrices.


MatrixMulitply_3.png

You can multiply a n x m matrix with m x n matrix as shown here to get a n x n matrix.


MatrixMulitply_3.png
Here is an online matrix multiplier:

https://www.mathsisfun.com/algebra/matrix-calculator.html

What is treemap and how do you use it in Power BI?

A treemap represent an entity of items in a rectangle where each item occupies a rectangle and all entities are inside the single rectangle( not unlike a map of a state containing all the counties, a map unlike treemap is not in a rectangle).



This is supported visualization type in Power BI.


Treemap.png

I am using the data from this post  of filtered sales by employees in the Northwind database on SQL Server 2016 using a direct query.

On a new page, click treemap under visualization to add the treemap to the page as shown,


Treemap_0

Drag fields LastName and UnitPrice to the treemap and the treemap changes as shown. Each rectangle now corresponds to an employee with its area in proportion to the sales made by the employee.


Treemap_00

You can add other formatting as shown


Treemap_000
You can add Spotlight to the treemap using the Spotlight menu as shown.


Treemap_2


You can also add tooltip in the Group page.


Treemap_3

Friday, June 22, 2018

How is the exponential function handled in R?

Exponential functions are very important in all branches of physics and mathematics. It is in fact taught in the very beginning when one learns mathematics.

In R programming exp(x) calculates,  'e to the power of x' where e is the Euler's constant.

Let us calculate the values of e raised to power of x, for x=0, 1, 10, and 100 using R.


How about exponential of negative numbers like, e raised to power of y, where y=-1,-10, and -100?

R can also be used to find expm1() which is defined as follows and should be used for small values of x instead of exp():

expm1(x)=exp(x)-1=(2*tanh(x/2))/(1-tanh(x/2))


For small x expm1() is better than exp() - 1



How do you configure Donut labels inside or outside the donut?

Again this feature is available in the June 5, 2018 update of Power BI.

Visual appeal is really important and Power BI now supports labelling inside or outside the Donut and Pie charts.

We use the same data used in the previous example of controlling the inner radius of Donut control used in data visualization described in this post.

Here the labels are outside the Donut.


Here is how you make them move inside the Donut.


You can also have label's text to overflow if it is not contained.

Some labels inside and others outside.


Overflow set to Off.


In the same way PIE Charts are also handled.




Thursday, June 21, 2018

How to control the radius of a Donut chart in Power BI?

Visual appeal is everything for anything. It is also called eye candy, loosely put. It is aesthetics that matters.

For Donut charts this makes a big change. Now you can control the inner radius.

This is a new feature of June 5, 2018 update for Power BI. You need to install this version first before you follow this post.

Get some fields' data into Power Bi by connecting to your datasource as in this post.

Drag and drop a Donut Control to your page as shown.



Donut_00

Place check marks for the data in Query1 as shown.



Donut_0

Click Format shown here:



Donut_1

The default is Inner Radius=60%


The next two figures shows for 28% and 88% inner radii.