tag:blogger.com,1999:blog-80901448506361302352024-02-21T03:14:45.053+08:00Code Doppler Programming TutorialsFree Programming Tutorials, Hints, Tips, and Source Codes in JAVA and C++.Anonymoushttp://www.blogger.com/profile/07066895039511761792noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-8090144850636130235.post-20682403699116421222012-10-18T10:05:00.001+08:002012-10-18T10:05:44.333+08:00Code Doppler Programming Tutorials: Welcome to Codedoppler<a href="http://codedoppler.blogspot.com/2012/09/welcome-to-codecage.html?spref=bl">Code Doppler Programming Tutorials: Welcome to Codedoppler</a>: Code Doppler is a newborn community for newbie to professional developers in JAVA and C++ programming languages. Our purpose is to prov...Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-10188480993942599882012-10-18T09:47:00.000+08:002012-10-18T09:47:50.899+08:00C++ Loops<div dir="ltr" style="text-align: left;" trbidi="on">
The purpose of loops is to repeat the execution of codes a number of time while the condition is still <i>true.</i><br />
<br />
<b>while loop:</b><i> </i><br />
The form:<br />
<br />
<span style="color: blue;">while</span>(condition)<br />
{<br />
statement(s); <br />
}<br />
<br />
<b>do while loop:</b><br />
The form:<br />
<br />
<span style="color: blue;">do</span><br />
{<br />
statement(s); <br />
}<span style="color: blue;">while</span>(condition);<br />
<br />
The difference of the <i>do while</i> is that, it will first execute the statements first then check if the condition is still true then if it is still true, it will iterate or loop (executes the statement(s) again).<br />
<br />
<b>for loop:</b><br />
The form:<br />
<span style="color: blue;">for</span> (initialization; condition; increment/decrement)<br />
{<br />
statement(s); <br />
} <br />
<br />
<br />
<b>Examples:</b><br />
<br />
<span style="color: blue;">int</span> x=10;<br />
<span style="color: blue;">int</span> i = 0;<br />
<span style="color: blue;">while</span> (i<x)<br />
{<br />
cout<<i<<": Hi"<<endl;<br />
i++;<br />
}<br />
<br />
<span style="color: blue;">do</span><br />
{<br />
cout<<i<<": Hi"<<endl; <br />
i++; <br />
}<span style="color: blue;">while</span>(i<x)<br />
<br />
<span style="color: blue;">for</span> (int a=0;a<10;a++)<br />
{<br />
cout<<a<<": Hi"<<endl;<br />
}<br />
<br />
Try it and see the difference.<br />
<b> </b></div>
Anonymousnoreply@blogger.com1tag:blogger.com,1999:blog-8090144850636130235.post-88788889511376519482012-10-18T09:37:00.000+08:002012-10-18T09:59:17.772+08:00switch case statements<div dir="ltr" style="text-align: left;" trbidi="on">
Switch case statements do a similar job like if else statements. The form is:<br />
<br />
<span style="color: blue;">switch</span> (variable)<br />
{<br />
<span style="color: blue;">case</span> value1:<br />
statement(s);<br />
break;<br />
<span style="color: blue;">case</span> value2:<br />
statement(s);<br />
break;<br />
<span style="color: blue;">default</span>:<br />
break;<br />
}<br />
<br />
<b>Example:</b><br />
int x = 0;<b> </b><br />
<span style="color: blue;">switch</span> (x)<br />
{<br />
<span style="color: blue;">case</span> 0:<br />
cout<<"X is 0"<<endl; //you can have like this code for newline<br />
break;<br />
<span style="color: blue;">case</span> 1:<br />
cout<<"X is 1";<br />
cout<<endl; //or you can separate like this.<br />
break;<br />
<span style="color: blue;">default</span>:<br />
cout<<"X is neither 0 nor 1"; <br />
break;<br />
}<br />
<br />
Remember that you can have multiple numbers of case statements not just two like the above example.<br />
<br />
Next: <a href="http://codedoppler.blogspot.com/2012/10/c-loops.html">C++ Loops</a> </div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-21801558971766494132012-10-18T09:27:00.002+08:002012-10-18T09:58:48.240+08:00if, if else<div dir="ltr" style="text-align: left;" trbidi="on">
<b>if:</b><br />
<br />
if statement is used to execute a code or a series of codes if and only if the <i>condition</i> is met. The form is:<br />
<br />
<span style="color: blue;">if</span> (condition)<br />
statement;<br />
<br />
The condition is the expression that is being evaluated. If it is true, statement is executed. If it is false, statement is not executed.<br />
<br />
If you want to execute a series of statements/codes, you should use curly braces { }. The form is:<br />
<br />
<span style="color: blue;">if</span> (condition)<br />
{<br />
statements;<br />
statements; <br />
}<br />
<br />
<b>Examples:</b><br />
<br />
int x=0;<br />
<b> </b><br />
<span style="color: blue;">if</span> (x==0)<br />
cout<<"X is "<<x<<endl;<br />
<br />
<span style="color: blue;">if</span> (x==1)<br />
cout<<"X is 1";<br />
cout <<"X is not 1";<br />
<br />
<span style="color: blue;">if </span>(x==0)<br />
{<br />
cout<<"X is 0";<br />
cout<<"X is not 1";<br />
}<br />
<br />
<br />
<b>if else:</b><br />
if else control structure is very similar to if statements. We will just add the else keyword if the condition is false. The form is:<br />
<br />
<span style="color: blue;">if </span>(condition)<br />
statement;<br />
<span style="color: blue;">else</span><br />
statement;<br />
<br />
If the condition is false, the statement in the else will be executed. Again, if you want to execute a series of statements/codes, you should use curly braces { }.<br />
<br />
<b>Example:</b><br />
<br />
<span style="color: blue;">int</span> x = 0;<b> </b><br />
<br />
<span style="color: blue;">if</span> (<b> </b>x==1)<br />
cout<<"X is 1";<br />
<span style="color: blue;">else</span><br />
cout<<"X is not 1";<br />
<br />
Next: <a href="http://codedoppler.blogspot.com/2012/10/switch-case-statements.html">switch case statements</a> </div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-62350306350893918402012-10-03T16:35:00.000+08:002012-10-18T09:58:01.482+08:00C++ Variables<div dir="ltr" style="text-align: left;" trbidi="on">
Variables are memory locations where you will store a data. There are several data types a variable can contain. Among the following in C++ are: int, char, float, double and bool.<br />
<b>int </b>- are for integer data types. It is used to contain whole number integers.<br />
<b>char</b> - are for characters. You will see examples later.<br />
<b>float</b> - for integers with decimals.<br />
<b>double</b> - for integers with decimals.<br />
<b>bool</b> - for boolean. True or False; <br />
<br />
<b>To declare a variable in C++</b>, this is the format: <span style="color: blue;">data_type</span> <i>name</i><br />
<span style="color: blue;">int</span> x;<br />
<span style="color: blue;">float</span> y;<br />
<span style="color: blue;">bool </span>tf;<br />
<br />
You can also declare multiple variables with the same data type:<br />
<span style="color: blue;">int</span> x,y,z;<br />
<br />
<br />
The name of the variable is <i>case sensitive</i>. Var1 is different from var1.<br />
<br />
<b>To Initialize a variable:</b><br />
<span style="color: blue;">int</span> x=0;<br />
<br />
or declare then initialize:<br />
<span style="color: blue;">int</span> x;<br />
x=0;<br />
<br />
Next: <a href="http://codedoppler.blogspot.com/2012/10/if-if-else.html">if, if else statements</a> </div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-49108614710618176342012-09-11T19:14:00.001+08:002012-09-11T19:14:47.401+08:00Quick Sort in JAVA<div dir="ltr" style="text-align: left;" trbidi="on">
Quick Sort is one of the fastest sorting algorithms.<br />
Here is the code snippet for Java.<br />
<br />
<br />
<span style="color: blue;">public static int</span> divide(<span style="color: blue;">int</span> array[], <span style="color: blue;">int</span> left, <span style="color: blue;">int</span> right)<br /> {<br /> <span style="color: blue;"> int</span> i = left, j = right;<br /> <span style="color: blue;">int</span> tmp;<br /> <span style="color: blue;"> int</span> pivot = array[(left + right) / 2];<br /> <br /> <span style="color: blue;"> while</span> (i <= j) {<br /> <span style="color: blue;">while</span> (array[i] < pivot)<br /> i++;<br /> <span style="color: blue;">while</span> (array[j] > pivot)<br /> j--;<br /> <span style="color: blue;"> if</span> (i <= j) {<br /> tmp = array[i];<br /> array[i] = array[j];<br /> array[j] = tmp;<br /> i++;<br /> j--;<br /> }<br /> }<br /> <span style="color: blue;">return</span> i;<br /> }<br /> <span style="color: blue;"> public static void</span> q_srt(<span style="color: blue;">int</span> arr[],<span style="color: blue;"> int</span> left,<span style="color: blue;"> int</span> right) {<br /> <span style="color: blue;">int</span> i = divide(arr, left, right);<br /> <span style="color: blue;"> if </span>(left < i - 1)<br /> q_srt(arr, left, i - 1);<br /> <span style="color: blue;">if </span>(i < right)<br /> q_srt(arr, i, right);<br /> }<br /> /**<br /> * @param args the command line arguments<br /> */<br /> <span style="color: blue;">public static void</span> main(String[] args) {<br /> // TODO code application logic here<br /> <span style="color: blue;"> int</span> []sample = {13,21,36,0,32,54,1,3};<br /> <span style="color: blue;">for</span>(<span style="color: blue;">int</span> x=0;x<sample.length;x++){<br /> System.out.print(sample[x]+":");<br /> }<br /> System.out.println("\n-=Sorted Array=-");<br /> q_srt(sample,0,7);<br /> <span style="color: blue;"> for</span>(<span style="color: blue;">int</span> x=0;x<sample.length;x++){<br /> System.out.print(sample[x]+":");<br /> }<br /> }<br />
<br /></div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-30338178348182595492012-09-11T12:38:00.000+08:002012-09-11T12:38:03.115+08:00Methods to read excel files in C#<div dir="ltr" style="text-align: left;" trbidi="on">
Useful C# methods in order to read cell values in excel.<br />
Remember to add a .NET reference for Microsoft.Office.Interop.Excel and use it in your program via the statement <i><span style="color: blue;">using</span> Microsoft.Office.Interop.Excel;</i><br />
<br />
<span style="color: blue;">private static</span> Microsoft.Office.Interop.Excel.ApplicationClass appExcel;<br />
<span style="color: blue;">private static</span> Workbook newWorkbook = null;<br />
<span style="color: blue;">private static</span> _Worksheet objsheet = null;<br />
<br />
<b>Method to initialize excel connection:</b><br /> static void excel_init(String path)<br /> {<br /> appExcel = new Microsoft.Office.Interop.Excel.ApplicationClass();<br /><br /> if (System.IO.File.Exists(path))<br /> {<br /> // then go and load this into excel<br /> newWorkbook = appExcel.Workbooks.Open(path, true, true);<br /> objsheet = (_Worksheet)appExcel.ActiveWorkbook.ActiveSheet;<br /> }<br /> else<br /> {<br /> MessageBox.Show("Unable to open file!");<br /> System.Runtime.InteropServices.Marshal.ReleaseComObject(appExcel);<br /> appExcel = null;<br /> System.Windows.Forms.Application.Exit();<br /> }<br /> <br /> }<br />
<br />
<b>Method to read a cell's value:</b><br />
static string excel_getValue(string cellname)<br /> {<br /> string value = string.Empty;<br /> try<br /> {<br /> value = objsheet.get_Range(cellname).get_Value().ToString();<br /> }<br /> catch<br /> {<br /> value = "";<br /> }<br /><br /> return value;<br /> }<br />
<br />
<b>Method to safely close excel connection:</b><br />
static void excel_close()<br /> {<br /> if (appExcel != null)<br /> {<br /> try<br /> {<br /> newWorkbook.Close();<br /> System.Runtime.InteropServices.Marshal.ReleaseComObject(appExcel);<br /> appExcel = null;<br /> objsheet = null;<br /> }<br /> catch (Exception ex)<br /> {<br /> appExcel = null;<br /> MessageBox.Show("Unable to release the Object " + ex.ToString());<br /> }<br /> finally<br /> {<br /> GC.Collect();<br /> }<br /> }<br /> }<br />
<br />
To use it in your program, you need to initialize the excel connection first via this method:<br />
<b><i>excel_init(Path_to_your_excel_file);</i></b><br />
make sure that your slash \ are double slashes \\. E.g. C:\\excel_file.xls<br />
<br />
To read a cell value:<br />
<b><i>excel_getValue("A1");</i></b> this will return the value of the cell.<br />
<br />
Safely close the connection with<br />
<i><b>excel_close();</b></i> to prevent memory problems.<br />
<br />
Thanks for reading! I hope you gain additional knowledge.<br />
<br />
If you have questions and or problems using it, please comment on this article.<br />
<br />
Thanks,<br />
<i>Administrator</i><br />
<br /></div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-23086817118889593962012-09-11T10:26:00.000+08:002012-10-18T09:56:56.672+08:00First C++ Program<div dir="ltr" style="text-align: left;" trbidi="on">
Start your preferred IDE for C++ and create a new Console Application or a new project. Name it as you desired. For Visual C++ and Visual Studio, <i>Create a new Project->Other Languages->Visual C++->Win32->Win32 Console Application</i>. Next Next...Check the check box for <i>empty project.</i><br />
<br />
<br />
For Visual C++/Visual Studio,<br />
<ol style="text-align: left;">
<li>In the Solution Explorer tab, right click the source files (folder icon), <i>add->new item</i></li>
<li>Select C++ File, name it <i>main</i> or a name that you desire.</li>
</ol>
Try to code this and run your program. For Visual C++ or Visual Studio Pressing F5 will run the program.<br />
Please post your comments if you have problems doing it. Thanks!<br />
<br />
<span style="color: blue;">#include</span> <iostream><br />
<br />
<span style="color: blue;">using namespace</span> std;<br />
<br />
<span style="color: blue;">int</span> main()<br />
{<br />
cout<<"Hello World!";<br />
cin.get();<br />
<span style="color: blue;"> return</span> 0;<br />
}<br />
<br />
<br />
<i>#include <iostream></i> - #include is a preprocessor directive, #include <iostream> tells the compiler to include the file iostream that contains functions/method declarations for standard input/output that will be used like cout (System.out.println in JAVA).<br />
<br />
<i>using namespace std;</i> - the elements/functions/methods in the iostream are declared in a namespace with the namespace <i>std.</i> To access its functionality we will use this entities. This line is a frequently used line for Console apps in C++.<br />
<br />
<i>int main()</i> - like in JAVA, it is the starting point of a program. Open curly brace { indicates the beginning of the function main() and Close curly brace indicated the end of the function main(); <br />
<br />
<i>cout<<"Hello World!";</i> - cout is the standard output stream in C++, it is declared in the iostream. << is an insertion operator telling that the string "Hello World!" will be the output. cout is like System.out.print in JAVA.<br />
<br />
<i>semicolon ;</i> - it is a very important character in C++ in order to end a command statement. This is a common error among programmers.<br />
<br />
<i>cin.get();</i> - is a function to accept a character input from the user. This is used here so that the console app will not close immediately after displaying Hello World!.<br />
<br />
<i>return 0;</i> - the method main will return a value of 0. This is a common use to indicate a successful program exit or execution.<br />
<br />
Done!<br />
If you have problems, please comment. Thanks!<br />
<br />
Next: <a href="http://codedoppler.blogspot.com/2012/10/c-variables.html">C++ Variables</a></div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-67650096691781444852012-09-11T09:49:00.000+08:002012-09-11T10:31:09.154+08:00Getting Started with C++ (cplusplus)<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
Hi,<br />
In this series of tutorials, you will learn the basic programming of C++ language. You may also return back from the table of contents to search topics that you want to learn.<br />
You will learn by examples and simple explanations. This will be a <i>quick</i> tutorial for fast learners.<br />
<br />
<b>Setting up the IDE:</b><br />
You may use the following IDE's for this tutorial:<br />
<ol style="text-align: left;">
<li>Visual Studio or Visual C++ only, you may download at <a href="http://www.microsoft.com/en-us/download/details.aspx?id=20682" target="_blank">here</a></li>
<li>Code Blocks at <a href="http://www.codeblocks.org/">http://www.codeblocks.org/</a></li>
<li>NetBeans with C++ at <a href="http://netbeans.org/downloads/index.html">http://netbeans.org/downloads/index.html</a></li>
</ol>
</div>
These are some of the popular easy to install and use Integrated software development tools. You may refer to their documentations if you have problem installing or ask us by posting your comments.<br />
<br />
In these tutorials, I will use Visual Studio 2010 Ultimate, but note that you can also use other IDE's.<br />
<br />
Comments/Suggestions/Questions are well accepted.<br />
<br />
Thank you very much,<br />
<i>Administrators</i><br />
<br />
Next: <a href="http://codedoppler.blogspot.com/2012/09/first-c-program.html">First C++ program</a><i><a href="http://codedoppler.blogspot.com/2012/09/first-c-program.html"> </a></i></div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-59592039292420935572012-09-10T20:23:00.001+08:002012-09-10T20:23:38.252+08:00Code Doppler Programming Tutorials: Learn JAVA<a href="http://codedoppler.blogspot.com/p/learn-java.html?spref=bl">Code Doppler Programming Tutorials: Learn JAVA</a>: You will learn JAVA language in the quickest possible way! A series of tutorial will teach you the Basic of JAVA programming and one of it...Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-8090144850636130235.post-80711076261900875692012-09-05T13:41:00.002+08:002012-09-10T11:26:20.521+08:00Welcome to Codedoppler<div dir="ltr" style="text-align: left;" trbidi="on">
<i><b><span style="color: orange;">Code Doppler</span></b></i> is a newborn community for newbie to professional developers in <b><i>JAVA</i></b> and<i> <b>C++</b></i> programming languages. Our purpose is to provide <i>free tutorials, hints, tips and sample source codes</i>. These tutorials will be the <i>quickest</i> tutorials for newbie programmers that wants to learn programming the quickest way! Also, we will try our best to answer all your questions regarding programming!
Thank you very much,
<i>Administrators</i></div>
Anonymousnoreply@blogger.com0