Structure of C++ Program

Structure of C++ Program (Click to watch video)

If you are a beginner at c++ then  the first thing you should know is that you need a compiler for compiling and running all your c++ programs. In short a compiler while help you to see the output of your program.  If you want to see a complete list of c++ compilers then click here. I would recommend the Bloodshed dev C++ compiler to you guys, but i am not going to use this compiler in my tutorials. This is because most of the schools or colleges around the world are still using the old and outdated Turbo C++. So even i am going to use the old compiler in all my tutorials. So all my codes will work properly in Turbo C++. Some codes may give error in other compilers because the old functions are simply deprecated in the newer compilers.

Okay, now getting started with C++ programming. First few words about how you should learn programming. According to me, the best way to learn any programming language in this world is by writing a program. If you write and practice then surely you will become perfect and acquire good skills in short time. But if you keep reading the programming books without an practical work then it wont help much. So always practice, make errors, fix them by finding solutions. This way you will become a great programmer.

So we will now write our first program and then we will understand it.

So the above code is a very simple code which will help us to print Hello World text as the output. We will have a look at every part of this code and understand it. The first line is a ‘single line comment’. Any line beginning with two forward slashes (//) is a single line comment in C++ language.

Comments are ignored by the compiler, which means that they are only for the humans. We write comments to tell other human what our program is all about. And in this case i am telling you people that this is my first c++ program. We should add comments to our program to help other programmers understand our program in a better way.

On the second line we have #include <iostream.h>. Now in this line iostream is a header file. We understand that it is a header file by looking at .h file format. And #include is a pre-processor directive. Preprocessor directives give instructions to the preprocessor to do certain task or take a certain action. And in this case we are just telling the preprocessor to include an external file (iostream.h) in our program. You must be wondering why are we including this file in our program, right? So the answer is that this file actually contains some elements or functions which we are going to use in our program. We will see more about this on 5th line of the program.

Third line says void main(). Remember that if a keyword is followed by pair of parenthesis then that is a function. So on this line main is a function in C++ and void is simply the return-type of main function. We will understand functions in the functions tutorial later on. However for now what you have to understand is that main is just the starting point of your program. All program execution begins at main function. No matter how many functions are there in your program or how many functions are above the main function, You have to understand and remember that always the main function will be executed first.

Then comes the opening curly brace. The opening curly brace and closing curly brace forms a block. Remember this to understand my next tutorials. And since this block occurs after main function, it forms the body of the main function. Again don’t worry if you are finding it difficult to understand about functions, since we will understand functions completely in functions tutorial. So inside the main functions body, we have :

This is the line which helps us to print Hello World as the output. This is a very important line in this program. We will read the line from right hand side to left hand side to understand it in a better way.

  • On the right hand side there is a semicolon ( ; ). Semicolon is used to end every statement in C++. Some lines may not have a semicolon at the end just because they are not technically statements.
  • Then there is Hello World in Quotations (” “). Anything between two double quotation marks is considered as string. String is simply group of characters in C++. In this case Hello World is a string.
  • Then after we have two less than signs ( << ). These are called Insertion Operator. They simply insert things on the right hand side to the things on the left hand side.
  • And at last comes cout (Console Out). cout is the standard output stream in C++. In simple terms whatever you pass to it will be displayed on the output screen.

So the meaning of entire statement can be summed up now. The statement means we are putting the string (Hello World) into the standard output stream (cout) using the insertion operator (<<). And in this way Hello World is displayed on screen as the output.

Now the question remains, Why did we include iostream header file in our program? 
The answer is that we have used cout keyword in our program which is defined inside iostream header file.  So if we remove the 2nd line completely then a error will occur. Because the compiler does not understand the meaning of cout.

In our program the compiler approaches cout and says i dont know what is cout ! And then it searches for the meaning of cout inside our program. Then it searches inside the ‘included’ header files. If it finds the meaning then compilation is successful or else error is reported to us.

So our basic code or syntax which we will use in all our beginner programs is as follows :

To fix output issues in Turbo C++

There are 3 more lines which we should add to fix output issues in Turbo C++. These output issues can be understood in a better way by watching the video. Click here to view the video.  The issues which come in Turbo C++ are:

  • Screen is not cleared before showing new output. Hence previous output is shown along with new output.
  • Output screen disappears in less than one second.

To fix these issues add clrscr() function at the beginning of main method and getch() function at the end of main method. clrscr() function helps to clear screen every time before showing new output. And getch() function helps to hold the output window on the screen until we respond by pressing a key on keyboard. But these functions are defined in another header file named conio. So we have to add one more header file in our program just below iostream header file.

So finally our fundamental program code becomes :

So i hope this article was quite informative for you guys. Thanks for reading and visiting my site.

Why do we Refresh our Computer?

Today a thought came in my mind that why do we refresh our computer? What actually happens? You know almost 90% of people around the world keep refreshing not knowing what exactly refreshing does. They keep doing ‘right-click – refresh’ .. ‘right-click – refresh’.. just after their desktop is loaded. And well you can even count me in the list of people who don’t know what refresh does. I just knew that it makes PC faster and more active. But the question is How? How does the computer makes itself faster by refreshing?

So i searched over the internet for an answer. And i couldn’t actually get an official answer from any site. But i found some answers from the internet users and yahoo answers. So grouping together all the information, i will try to answer the question.

What is the meaning of Refresh ( F5 ) in Computers?

Refreshing can be related to Human behavior. Just as we get tired by doing certain task and need to refresh to become active to do other tasks, Even the computer gets tired after running programs for long time. The word tired in technical terms means the computer becomes slow. And after refreshing the computer, it becomes more active.

What happens when we Refresh the Computer? (Technically)

  1. When you run a program it will load on to the memory. It will reside in a certain sector until you end the program. As you kill or terminate a program, the restore point of the process is still in the memory for while. So you when you press F5 or refresh, you are cleaning the loaded (resided sector) on the memory.
  2. Refreshing makes computer to run faster by clearing its previously completed job cycle, thereby reducing response time for each cycle.
  3. Hence in short, it frees up the ram used for various purposes and fasten your PC.

Why to Refresh your Computer?

Although your windows automatically refreshes at the default frequency of 60 Hz, You can manually refresh using F5. Or by right clicking on your desktop and selecting refresh option. The question is why to refresh? The answer is simple. As seen in this post, Refreshing will just help you to make your computer active and thus speed it up. People also use refresh to check whether their PC is working at proper speed or not.

I hope you found this article helpful. 🙂

Blogger vs WordPress

Blogger(Blogspot) and WordPress are the two giant platforms dominating the blogosphere.

And since these two are in great competition, you must be wondering which one to choose or which one suits my requirements.

So in this post i will try to clear the confusion in your mind hopefully.

Since i have used both these platforms for long enough. And currently my blog is based on wordpress CMS.

Paid Blog Hosting

So the very first difference is that WordPress is available as a content management system (CMS) while blogger is NOT. Which means that Blogger is available only through blogspot.com. Therefore you cant host blogger on your own webhost. However you can add your own domain to blogger. In case of wordpress you can either host your blog on wordpress.com or host wordpress CMS on your own web hosting site.

Winner: WordPress
Reason
: Wordpress is available as CMS. Hence full control over forum. 

Free Hosting

WordPress and Blogger both offer free blog hosting. That means you will either get yourblog.wordpress.com or yourblog.blogspot.com from them. In case of free wordpress hosting, they offer very limited accessibility to customize your forum. If you want to customize your forum then you have to pay them. In case of blogger hosting, they offer full template customization for free.

Winner: Blogger
Reason
: Comparing to ‘free wordpress hosting‘, Blogger has more control over template.

Organizing Blog Posts

In case of wordpress there are categories and tags to organize your blog posts. While in blogger there are only labels to organize your blog posts. So in this case wordpress has rich organization compared to Blogger. As per my experience.

Winner: WordPress
Reason
:  Comparatively rich organization of posts in wordpress.

Widgets and Plugins

The add-on scripts or internet gadgets in wordpress are called as plugins and in blogger are called as widgets. Many people think they have equal in this battle. But with experience i can tell. I am much more happier and satisfied with wordpress plugins than with blogger widgets. WordPress plugins are of great quality than blogger widgets.

Winner: WordPress
Reason
: Comparatively quality of plugins is very rich in wordpress.

Static Pages

In blogger you can create upto 20 static pages. But in wordpress you can create as many static pages as you want.

Winner: WordPress
Reason
: No limit on static pages.

Forum Administration and Permissions

In case of blogger, there are Administrators, Authors and Readers. But blogger is less flexible in case of customizing this ranking system. In case of wordpress there are several ranks. Subscriber, Contributor, Author, Editor, Administrator, Super Admin, etc. And wordpress ranking system is flexible.

Winner: WordPress
Reason
: Better administration and permission settings.

Themes

WordPress has very very rich variety of themes as compared to Blogger templates. Get this idea clear that WordPress as Themes and Blogger has templates. In Blogger templates are XML files which means your entire blog look is decided by this one single file. But in WordPress you have themes. These themes are made up of group of php files, images, css files, etc. If you don’t believe me then you can search on the internet and compare blogger and wordpress themes yourself. Maybe you can even try some blogger templates first before believing me. Because i am so much satisfied with wordpress themes, i cant express !

Winner: WordPress
Reason: 
Better quality of themes in wordpress.

Customizing Themes (Free Hosting)

As i said previously, Free wordpress hosting does not allow us to customize the stylesheet or our blog template. However blogger allows us to customize our template. And free blogger templates are also available over the internet which can be customized and uploaded to your blogger site. Even though free wordpress templates are available they cannot be customized by you since wordpress charges you for customizing your template.

Winner: Blogger
Reason
: Freedom to customize template for free in Blogger.

Customizing Themes (Paid Hosting / Using CMS)

In case of paid hosting or using wordpress as content management system, you have full freedom to customize the way you want it. And this is far better than Blogger.

Winner: WordPress
Reason: 
Full customization freedom in WordPress CMS.

Size of Pictures (Free Hosting)

In case of wordpress, 3gb of image storage is provided. And in case of blogger 1gb of image storage is provided which is shared with picasa web.

Winner: WordPress
Reason: 
more image storage space in wordpress.

Conclusion?

If you are are not serious with blogging, If you don’t have time to customize your blog or don’t want to do all the advanced things but just write blogs then Blogger is suitable for you. But if you are serious with blogging and want to do it professionally then wordpress is for you. If you are new to everything, i recommend blogger to you for its ease of use. If you are having some what experience in blogging then you should switch to wordpress.

Note that Blogger is free service. WordPress has 2 types, free and premium/CMS. Comparing Blogger and Free wordpress you should go with Blogger according to me. But comparing Blogger to WordPress premium/CMS, you should go with WordPress.

How to customize your desktop using Rainmeter tool

This is how my desktop looks like today, after customizing it with rain-meter tool. I shared this picture on my facebook profile and all my friends loved it. They all kept me bugging all day to help them get their desktop customized as well. But i can’t help everyone individually because it would take all my day. So i created a simple video on how to use rain-meter tool. This video is just to guide how to use rain-meter tool. And note that this video does not guide you to create the perfect customized desktop as shown in the above pic. You yourself have to experiment with rain-meter to customize to get your desired results.

Click here to view the Video

Remove lock sign over folder in win 7

So you see the lock sign or icon over the folders in the above image? That’s what i am talking about. I don’t know if you have a problem with that or not. Most of us don’t really care about that small icon. But people who are serious with the themes and look of their computer, People who like to keep things neat and tidy would not like to see a lock over the folder. Maybe this sounds stupid that why would anyone be bothered about the small lock sign over the folder. But trust me there are people including me, who don’t like to see all these kind of stuff which makes the screen look kinda dirty you know? .. Well now, we will first lets see how this icon comes into picture.

When you go and right click over the folder and choose share with -> nobody. Then that lock icon appears over the folder to indicate that this folder is completely private. It can only be accessed by authenticated users of your computer. And other computers on the network cannot access this folder alright? So now lets go ahead and see how do we remove this lock icon or lock sign over the folder !

>> How to remove Lock sign over the folder in Windows 7 ?

  1. Go ahead and Right click over the folder having the lock sign/icon.
  2. Click on Properties. Then click on Security tab.
  3. Click Edit > Add > Advanced.  (click on image below to open it and again click to zoom in)
  4. Then click on find now. After that double click on Authenticated users. See below.
  5. Now click on Ok, Ok, Ok, etc. And you are done. Your lock icon over the folder in windows 7 has been removed. Check below. The lock icon over FIFA 08 folder has been removed successfully.

Life without Google

Can you imagine your life without Google? Right now as you are reading this, can you think of how many Google services you are already using? Maybe you found this page right now just by searching on Google? Maybe you are still logged into your Google account? Okay keep that aside. What photo editor do you use? There is 80 to 90 percent chance that you are using Picasa from Google ?  Where do you have your e-mail account? on G-mail?  Uhm.. Lets say what phone platform you are using? Android? .. See you are using Google in one way or another no doubt about it. And of course 99% of us use Google as search engine. There are so many Google services that you use unknowingly, it has just become a habit. Without Google, don’t you think your online life will cease? Well if not cease, lets say it will be considerably slower than usual right? So in this post let us take a look at what products and services we can use to replace Google, and lets compare their qualities as well. And then we will conclude whether we can actually live without Google or not !

First thing is of course the Search Engine. So If Google dies, what will you use as your search engine? There are plenty of them, but I personally always depend on Google for its fast results and clean interface. There was a time when Google wouldn’t respond (rare case, mostly it was my network problem) i would switch to Bing or Yahoo to search. But with time i discovered that there are several search engines which can be helpful. Like DuckDuckGo is somewhat good replacement to Google. Because of its simplicity and its ability to use different search engine platforms as well. So in case you need a replacement, DuckDuckGo is good choice.

Next most of us use G-mail. So if G-mail is not there, what would you use? Maybe we will switch to hotmail or yahoo mail, but there are many e-mail providers out there. One of them is Zoho mail. Its nice clean, and easy to use just like G-mail. Zoho mail has more than 6 million users according to the Zoho Mail’s website.

Third is Google Reader. What is Google reader? well quote from the site itself : “Google Reader helps you find and keep track of interesting stuff on the web. You can subscribe to your favorite websites, and keep up with what’s popular. New content comes to your Google Reader when it’s posted, so you don’t need to visit individual sites”. To replace reader, there is something called as Sage. Sage is a firefox plugin which does the same job as that of Google reader. Just that you will need to switch to Firefox browser.

Fourth is Google Tasks. Google Tasks helps you to keep track of what you do. If you ever wanted to replace Google tasks, there is something called as Todoist (To do list). Since its only job is to keep track of what you do, the quality is superior to Google tasks. I never thought that it could be better than Google tasks, its very impressive and as they say “Todoist is the leading personal task manager that’s useful, fast and easy to use.”

Fifth is Google Docs. Using Google docs you can create your documents or upload your existing documents on the web. You can access those documents from anywhere and you can edit them as well. And third thing is you can even share those documents with anyone you want. You can choose to keep them private or public, its your decision. Now to replace Google docs, there is something called as Dropbox. Dropbox is a free service that lets you bring all your photos, docs, and videos anywhere. This means that any file you save to your Dropbox will automatically save to all your computers, phones and even the Dropbox website. That means you wont lose any data no matter what happens. They say “Dropbox also makes it super easy to share with others, whether you’re a student or professional, parent or grandparent. Even if you accidentally spill a latte on your laptop, have no fear! You can relax knowing that Dropbox always has you covered, and none of your stuff will ever be lost.”

Sixth is Picasa. Almost all of us use Picasa for fast photo editing, because its very simple and easy to use. Picasa is photo viewing / editing tool by Google. It helps us to Organize, Edit, and Share photos effectively. To replace Picasa, there is something called as Flickr. Quote from Flickr’s website, “Flickr is the best online management and sharing application in the world”. And maybe they are, because that’s the only thing they do, They help manage and share photos effectively. So if you don’t like Picasa, you can go for Flickr.

Last is Google Chrome. Users first used to switch browser from Internet explorer to Mozilla Firefox. Now everyone switches to Google Chrome. Why? The answer is simple. Google chrome is made for only one thing. That is Browsing. It is fast, clean, simple and looks good to eyes. The browsing space is bigger, It boots up or executes faster. Also it loads up the web pages faster than any other browser. That’s what makes it better than all others. So if you ever want to switch to some other browser, the only browser which you should use is Mozilla Firefox. Because Google Chrome and Mozilla Firefox these two are the only beasts in the competition. The only difference is firefox has many un-necessary options on screen. Firefox is like made for developers. Chrome is just simple, made for all.

Then there are many services which cannot be replaced. I mean you actually can’t live without these services. Services like Youtube. Youtube is very rich service of Google, it is one of its kind. There are other video sharing sites ofcourse, like Metacafe, Vimeo, etc. But these are nowhere close to Youtube. I personally cannot find any other video sharing site which is as good as Youtube. So now we can ask ourselves, that can we live without Google?

Can we live without Google ?

Yes of course we can, BUT Google makes everything convenient for us. Life without Google will be slow, and we will have to put in a lot of efforts to do a certain task. We will have to use several different platforms for different services. That would be terrible. Google helps us to do all the things that we need to do. When we come online, what are all our needs? We need to search for something, we have Google search. We need to mail, we have G-mail. We need to share documents, we have Google docs. We need to share photos, we have Picasa. We need to share videos, we have Youtube. We need translations, we have Google Translate. We need to find location, we have Google maps. We need to blog, we have Blogger. We need a online Calender, we Have Google calender. We need a social network, we have Google+. And many more services. Yeah most of the people use Facebook. There are around 900 million users on Facebook, while there are 150 million active users on Google+. And Google claims to reach 400 million users by the end of 2012.

So as you can see Google provides us one platform for different services. That’s a great thing for us. But this brings many questions in my mind. What about data security and portability? If you rely on one single platform for different services, then you are providing all your personal information to that platform. Your whole life is stored online. Can you trust a single platform for the security of your data? Well i cant answer this question, because once you post something online, its difficult to erase it off completely. Whatever you post will leave its traces somewhere on the internet. So if you rely on one single platform, you should think twice before posting something. You should always use the privacy feature effectively. And then if you yourself take care of your data, then you can depend on a single platform without worries. So the message is, Google has become essential part of our life. we should use it, take advantage of its services, but responsibly. We should take care of all our data which we store or share online. I personally like Google because Google makes my online life easy, fast and simple. And i just cant live without Google. What about you?