Showing posts with label How to. Show all posts
Showing posts with label How to. Show all posts

Tuesday, 28 February 2012

How Hard Drives Work?

Hard drives have one, two, or more platters that stack together and spin in unison.
Read/write heads are controlled by an actuator and move in unison across the disk surfaces as the disks rotate on a spindle.

Figure below shows a hard drive with four platters:-

A hard drive with four platters.


1. All eight sides of these four platters are used to store data, although on some hard drives the top side of the first platter just holds information used to track data and manage the disk.

2. Each side (surface), of one hard drive platter is called a head. (Don’t confuse this with read-write head)

3. The four platters in the figure above has eight heads.

4. Each head is divided into tracks and sectors. Eight tracks (one on each head) make one cylinder.

5. As with floppy disks, data is written to a hard drive beginning at the outermost track.

6. The entire first cylinder is filled before the read/write heads move inward and begin filling the second cylinder.

7. A hard drive requires a controller board filled with ROM programming to instruct the read-write heads how, where and when to move across the platters and write and read data. 

8. Hard drive controller mounts on a circuit board or inside the drive housing and is an integral part of it. The controller and drive are permanently attached to one another.


Reference:-
A+ GUIDE TO Managing and Maintaining Your PC, by Jean Andrews

Thursday, 27 October 2011

cin.get() not pausing??

As I wrote in one of my post - why you should use cin.get() when you test a program (apply to IDE that wont wait as you test a code and as soon as the code finished the window closes, leaving you without a glance on the result =p).

Let's look at this example:
#include <iostream>
using namespace std;
main()
{
    for(int x=0;x<20;x++)
    {
            cout<<x<<endl;
    }
    cin.get();
}

But sometimes, cin.get() might refuses to work, as in this example here:-
#include <iostream.h>
    main()
    {
        int hours, minutes, seconds;
       
        cout <<"Input hours: ";
        cin  >> hours;
        cout <<"Input minutes: ";
        cin  >> minutes;
       
        seconds=hours*3600+minutes*60;

        cout << "Time in seconds : "<<seconds<<endl; 
        cin.get();
        return 0; 
      }

The window closes taking all the data with it, and you not even get a chance to see the result.

What happen here actually? 
Why cin.get() works in the first example but not in the second?
In the second example, after the program read the value using cin, a \n is left in the buffer. Thus the cin.get() that you meant for pausing consumes that \n.

What you can do??
You may use two cin.get(). Which the first call to cin.get() is used to consumes that \n left in the buffer and the second cin.get() to pause your windows from closing.

Or, you may flush the \n from the buffer by using cin.ignore()

#include <iostream.h>
    main()
    {
        int hours, minutes, seconds;
       
        cout <<"Input hours: ";
        cin  >> hours;
        cout <<"Input minutes: ";
        cin  >> minutes;
       
        seconds=hours*3600+minutes*60;

        cout << "Time in seconds : "<<seconds<<endl; 
        cin.ignore();
        cin.get();
        return 0; 
      }

Why you should avoid system("pause") in C++

In windows, the system() function is used to execute any operating system command, like dir, ls, rename, etc. However, it is not encourage to use system("pause") to pause command windows from closing in C++. There are two main reasons why:-
  1. A call to system("pause") will pause the programs execution and make a system call and thus allocate unnecessary resources.
  2. Another reason it should be avoided is because it isn't portable. It works only on systems that have the PAUSE command at the system level, like DOS or Windows.
system("pause") is pretty popular and usually introduced to new beginners. It provides a clean and perfect pausing action. Also commonly used in debugging.

That means, when you do system("pause"), it does: Press any key to continue...

Just ANY key on your keyboard! Even an arrow or a space bar will do. 

Unlike cin.get(), it didn't show anything, or what you suppose to press to exit. Until you figure it out, you probably hit almost every key on your keyboard, and finally accidentally hit on the RETURN key. 

Of coz, both code: system("pause") and cin.get() does the same job, but quoting from a friend, using system("pause") is like using a bulldozer to open your front door. It works, but you can open your front door in an easy way, do you? So, why would you want to waste the unnecessary resources?

In spite of all the bad things most programmer would said about system("pause"), and how you shouldn't mix an operating system command with a C++ programming code, I reckon system("pause") is introduced to new beginner to make their life easier in learning  and exploring programming language. Just like how we were taught that gravity is equal to 10 when we were in primary school, and then few years later they told us that actually we should calculate gravity as 9.81.You wouldn't tell a little boy that he should calculate gravity as 9.81 while he is still struggling with multiplication involving decimal, would you??

So, it's your call if you wanna be a beginner and stay as a beginner, or evolve and be a professional =)

Tuesday, 18 October 2011

MinGW - Getting Started

What is MinGw??
MinGW (Minimalist GNU for Windows), formerly mingw32, is a native software port of the GNU Compiler Collection (GCC) and GNU Binutils for use in the development of native Microsoft Windows applications; 

MinGW can function either as a cross compiler targeting Windows or as a native toolchain run on Windows itself. It is deployed along with a set of freely distributable import libraries and header files for the Windows API.

Source : Wikipedia


First you have to be familiar with basic DOS command. Go here for basic cmd.
Before continue, make sure you have installed MinGW.


Open up an elevated command prompt window and set the current directory to where your *.cpp file is.

Example:
For the file calculator.cpp in the folder C:\doc, change your directory using the following command:

cd c:\doc

This is the compile command:

g++ calculator.cpp -o calculator.exe

The -o switch defines the name of the output file.
Now you can run your program by typing the name of the executable file:

calculator.exe


Monday, 17 October 2011

Change the Title Tags in Blogger

  1. Go to Design>edit HTML in your Blogger dashboard.
  2. Search for tag: <title><data:blog.pageTitle/></title>
  3. Replace the tag with the following code:
  4. <b:if cond='data:blog.pageType == &quot;index&quot;'> <title><data:blog.title/></title> <b:else/> <title><data:blog.pageName/> | <data:blog.title/></title> </b:if>
  5. Save your new template.
  6. View your blog. You should see the results in your web browser as shown below.







Wednesday, 12 October 2011

C++ in Bloodshed tips & shortcuts

In Bloodshed
To compile: ctrl + F9
To run: ctrl + F10
To compile & run: F9

To get your command prompt screen to stay open..
cin.get();
Click here for More about cin.get ();

system("pause");
Click here for Why you should avoid system("pause")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As you are trying to test several small scripts (that related to each other) ,some ppl tend to open new source file (ctrl+N) for every small scripts. Here is something you can try, run and test all the small scripts under one source file and isolate each scripts by using the block comment.


MATLAB SIMULINK tips & shortcut

Connecting blocks:
  1. Right-click on signal and drag to create several connections emerging from same block
  2. Left-click and drag to reroute lines
  3. Shift-left-click to create breakpoint
  4. Left-click on breakpoint to move breakpoint
  5. Alt+Ctrl+left-click to connect 2 blocks
Viewing model:
  1. Hot key r to zoom in
  2. Hot key v to zoom out
  3. Spacebar to see whole model in window

Basic DOS command tricks

Basically these are just simple cmd.exe commands for beginner to get started. Actually most people don't even know what is cmd and as soon as you open it, they're like 'oh no! what's this?? where is the icon, color and everything??' (the GUI stuff). But once you get used to the environment, you will find it useful especially when your computer get stuck with the heavy-beautifully-designed-colourful-GUI at the back =p


1. To open cmd
win+R > cmd


2. Manipulating directory

To change directory. (If you are unsure on the exact spelling of a folder, press TAB and use the up and down arrows to scroll through the folders that finish what you started typing.
cd c:\doc


To go up 1 level
cd ..


To list all of the directories
dir


3. New look for your cmd
Sometimes you may want to impress your girlfriend. How about a different look of cmd from everyone else??

C:\Users\angelKeshet>color y

C:\Users\angelKeshet>color 0a

Check on the list of color listed. The first number represents the background color, and the second character represents text color. Now you can play as Keanu Reeves in the The Matrix =p


4. ping
This is a famous command that allow you to check if the host you pinging is 'alive'. A simple check of your internet connection.
C:\Users\angelKeshet>ping google.ca

5. ipconfig
This command will show your IP address, gateway, DNS in use etc.
C:\Users\angelKeshet>ipconfig

6. Others
Clear screen

cls

To quit cmd
exit