Pages

Monday, 15 April 2013

#3 Operators in C++ and your first practical program - a simple calculator!

                        Today we are gonna talk a little bit about different "Operators" in C++. Operators are anything, which are coded to do something. We already have talked about one operator : the output operator. Actually, the output ( cout ) operator, is the part of a set of operators called input-output (I/O) operators, which also contains many other similar operators.
           
           Next important operator we are gonna learn from I/O operator is the basic input operator. Similar to "cout", the code for input operator is "cin". The header file needed for cin is <iostream.h> . The general format of this operator is :



'a' can be any variable you want to insert from the user. This can be a bit difficult to digest. But this is very simple... Lets do a practical. Suppose you want to insert a number from the user. First thing you want to do is to declare that a variable (a number which is yet to be known) is present in the program.

Declaration of a variable means, letting the compiler know that a variable is present in the program, so as to run it. To declare anything in C++, you want to inform the program it's datatype.
Now a datatype means the type of the thing you want to add to the program. There are two types of datatypes. They are Basic Datatypes and Derived datatypes.  Any program which involves integer operations, should have the "int main()" function. i.e. we have to replace the "void main()" function of the last program with "int main()".

We will learn more datatypes later. Now all you have to know is, an integer number (eg: 0, 2, 13, 63, -4, -7, -10) is of the datatype "int". The second thing to know about variable declaration is that, a variable has to be given a name. Since it is an unknown number, it is appropriate to name it an alphabet like 'x', or a, just like in algebra, where we name unknowns 'x'. This pseudo-name we give to unknown things like a character, or a number is called Identifiers Now lets name our number to be input by our user 'u'. (An identifier need not to be of a single character, we may also name our number 'unknownnumber' or something, but note that white spaces are not allowed in between the text of an identifier, and also it is for simplicity, we are naming our number 'u'). To letting the program know that a variable 'u' exists, you should insert this code just after opening the braces of the main() function:



Now that your program knows it involves an unknown number, next thing you will need to do to input a number from user, is, you should inform the user that the program is expecting a number from him/her. To do this, we just have to output a message saying to input the number, just like this:

Now as the user reads the message he will try to enter the number, but will fail miserably, because *tadaaa* there is no input operator. This is where "cin" comes into play. Now you should enter this code just after the message to user:



Now the user will be able to enter the number, and as soon as he presses enter, the  value he types get stored under the identifier 'u'. If we call 'u' again, the value of 'u' will be used. To understand this let us include this code to output 'u'.:



Let us look at the final code, and what happens when we run it:

The value entered was 34, and  when 'u' is output, 34 is displayed...

UPDATE : Dev C++ is much better than Turbo C++ if you want to learn updated C++. Here is a review of Dev C++ and variations of Dev from Turbo++, and its advantages over other compilers!

That is it for today guys...
Happy coding... :)



Saturday, 13 April 2013

How to resume cancelled Chrome downloads using .crdownload file


The one and only thing I dont like about Chrome is its download system. It can be extremely frustrating sometimes, if you are downloading huge (>500 MB) files. It automatically stops sometimes. The common misconception is that, if this error happens, we have to download the file from the beginning. Easy enough, if you have not reached that far in your download. But what if it happens when you are on 90% or above? Here is an easy trick to resume a cancelled download of Chrome, using leftovers of the dead download…

Step 1 : Go to your download location and locate your file. It will have an extension “.crdownload” (eg : if you are downloading a file named “name.extension”, what you have to locate is “name.extension.crdownload”). Now rename your file by removing the “.crdownload” extension. (eg: rename “name.extension.crdownload” to  ”name.extension”)
Step 2 : Download “wget” from here and copy the .exe file into the same directory as that of your unfinished download.
Step 3 : Open command prompt inside your download folder. To do this easily in Windows 7/8, just hold Shift Key and press left mouse button, and select “Open command prompt here”.
Step 4 : Now a new black window will appear. Type in the command ” wget -c <URL> “








>> You will need to type the place you are downloading the file from in the place of <URL>. You can obtain this from Chrome Downloads page, or the website you are downloading the file from. (eg: http:// webpage.com/ file.extension)
Step 5 : Now your download will RESUME!! After completion, you just need to go to your download folder, and find your file,, completely downloaded! Neat huh?




Kindly take a moment to say Thanks. That will be really appreciated. And it will be a motivation for me. Subscribe for more tricks n’ tips..
~ RaMaN, Spectracoder   B-)