Latest News:2013
@ Java Object Orinted Programming Running @
Information Syestem for all: February 2013

Find me facebook

Thursday, February 28, 2013

8 Common Programming Mistakes

1. Undeclared Variables

int main()
{
  cin>>x;
  cout<<x;
}
"Huh? Why do I get an error?"

Your compiler doesn't know what x means. You need to declare it as a variable.
int main()
{
  int x;
  cin>>x;
  cout<<x;
}

2. Uninitialized variables

int count;
while(count<100)
{
  cout<<count;
}
"Why doesn't my program enter the while loop?"

In C++ variables are not initialized to zero. In the above snippet of code, count could be any value in the range of int. It might, for example, be 586, and in that situation the while loop's condition would never be true. Perhaps the output of the program would be to print the numbers from -1000 to 99. In that case, once again, the variable was assigned a memory location with garbage data that happened to evaluate to -1000.

Remember to initialize your variables.

3. Setting a variable to an uninitialized value

int a, b;
int sum=a+b;
cout<<"Enter two numbers to add: ";
cin>>a;
cin>>b;
cout<<"The sum is: "<<sum;
When Run:
Enter two numbers to add: 1 3
The sum is: -1393
"What's wrong with my program?"

Often beginning programmers believe that variables work like equations - if you assign a variable to equal the result of an operation on several other variables that whenever those variables change (a and b in this example), the value of the variable will change. In C++ assignment does not work this way: it's a one shot deal. Once you assign a value to a variable, it's that value until you reassign the values. In the example program, because a and b are not initialized, sum will equal an unknown random number, no matter what the user inputs.

To fix this error, move the addition step after the input line.
int a, b;
int sum;
cout<<"Enter two numbers to add: ";
cin>>b;
cin>>a;
sum=a+b;
cout<<"The sum is: "<<sum;

4. Using a single equal sign to check equality

char x='Y';
while(x='Y')
{
  //...
  cout<<"Continue? (Y/N)";
  cin>>x;
}
"Why doesn't my loop ever end?"

If you use a single equal sign to check equality, your program will instead assign the value on the right side of the expression to the variable on the left hand side, and the result of this statement is the value assigned. In this case, the value is 'Y', which is treated as true. Therefore, the loop will never end. Use == to check for equality; furthermore, to avoid accidental assignment, put variables on the right hand side of the expression and you'll get a compiler error if you accidentally use a single equal sign as you can't assign a value to something that isn't a variable.
char x='Y';
while('Y'==x)
{
  //...
  cout<<"Continue? (Y/N)";
  cin>>x;
}

5. Undeclared Functions

int main()
{
  menu();
}
void menu()
{
  //...
}
"Why do I get an error about menu being unknown?"

The compiler doesn't know what menu() stands for until you've told it, and if you wait until after using it to tell it that there's a function named menu, it will get confused. Always remember to put either a prototype for the function or the entire definition of the function above the first time you use the function.
void menu();
int main()
{
  menu();
}
void menu()
{
  ...
}

6. Extra Semicolons

int x;
for(x=0; x<100; x++);
  cout<<x;
"Why does it output 100?"

You put in an extra semicolon. Remember, semicolons don't go after if statements, loops, or function definitions. If you put one in any of those places, your program will function improperly.
int x;
for(x=0; x<100; x++)
  cout<<x;

7. Overstepping array boundaries

int array[10];
//...
for(int x=1; x<=10; x++)
  cout<<array[x];
"Why doesn't it output the correct values?"

Arrays begin indexing at 0; they end indexing at length-1. For example, if you have a ten element array, the first element is at position zero and the last element is at position 9.
int array[10];
//...
for(int x=0; x<10; x++)
  cout<<array[x];

8. Misusing the && and || operators

int value;
do
{
  //...
  value=10;
}while(!(value==10) || !(value==20))
"Huh? Even though value is 10 the program loops. Why?"

Consider the only time the while loop condition could be false: both value==10 and value==20 would have to be true so that the negation of each would be false in order to make the || operation return false. In fact, the statement given above is a tautology; it is always true that value is not equal to 10 or not equal to 20 as it can't be both values at once. Yet, if the intention is for the program only to loop if value has neither the value of ten nor the value of 20, it is necessary to use && : !(value==10) && !(value==20), which reads much more nicely: "if value is not equal to 10 and value is not equal to 20", which means if value is some number other than ten or twenty (and therein is the mistake the programmer makes - he reads that it is when it is "this" or "that", when he forgets that the "other than" applies to the entire statement "ten or twenty" and not to the two terms - "ten", "twenty" - individually). A quick bit of boolean algebra will help you immensely: !(A || B) is the equivalent of !A && !B (Try it and see; you can read more about this rule on Wikipedia: DeMorgan's Law). The sentence "value is other than [ten or twenty]" (brackets added to show grouping) is translatable to !(value==10 || value==20), and when you distribute the !, it becomes !(value==10) && !(value==20).

The proper way to rewrite the program:
int value;
do
{
  //...
  value=10;
}while(!(value==10) && !(value==20))

"The Same Game": A Simple Game from Start to Finish, Part 1 of 5

By Ben Marchant

Foreword to Same Game

In this five part series, we'll be creating a version of a game called SameGame using the Microsoft Foundation Class library from start to finish. We'll include features beyond the simple removing of blocks in the game. We'll implement an undo/redo subsystem and some user configuration dialogs. We'll show you step by step with not only source code but screenshots how to build a fun game from start to finish and how to use Microsoft's MFC classes. Every article comes with complete source code, so you can build and run the game yourself.
The rules to the SameGame are quite simple, you try to remove all of the colored blocks from the playing field. In order to remove a block the player must click on any block that is next to, vertically or horizontally, another with the same color. When this happens all of the blocks of that color that are adjacent to the clicked block are removed. All of the blocks above the ones removed then fall down to take their place. When an entire column is removed, all columns to the right are shifted to the left to fill that space. The blocks aren't shifted individually but as a column. The game is over when there are no more valid moves remaining. The goal is to end with an empty board in as little time as possible. Some versions of the SameGame use a scoring algorithm that can be implemented as an additional exercise for the user.

Prerequisites

You'll need to have a basic C++ knowledge of functions, recursion, classes, and inheritance. The code was written using Visual Studio 2005 on Windows XP although later versions of Visual Studio should be fine although the screenshots will look slightly different from what you will see. You must use the Standard or Professional edition of Visual Studio; Visual Studio Express cannot be used, because it does not come with MFC.
If you are student, you may be able to get the Professional Version of Visual Studio for FREE from Microsoft DreamSpark.
If you are not a student, and you do not have the full version of Visual Studio, can work through this tutorial using a trial version of Visual Studio.

What You'll Learn

First and foremost, you'll learn some basics of how to create your own game. You'll learn about the Microsoft Foundation Class library and some basic usage and the Document/View architecture paradigm.
Here's an outline of the series, with links to each article:

Why MFC?

MFC is an easy-to-use library, especially for a simple game like the one we want to make. It will make it easy to create an application with a true Windows look-and-feel.

Starting the Same Game Project

In this article we'll be using Visual Studio 2005 to create our game. The following instructions can easily be adapted to all other versions of Visual Studio. First start up Visual Studio and create a new project. The type of project is "Visual C++" -> "MFC" -> "MFC Application".
Next the MFC application wizard will appear. If you do not choose the name SameGame, then the names of your classes will be slightly different than those that appear in this article. This allows you to select quite a few options that the resulting generated code will include. For our simple game we can disable quite a few of these options. The following graphics show which options to select in order to get the project just the way we want it.
Selecting "Single document" allows the application to use the document/view architecture when multiple documents aren't necessary. The last setting of interest on this page is "Use of MFC". The two options are for a shared DLL or as a static library. Using a DLL means that your users must have the MFC DLLs installed on their computer, which most computers do. The static library option links the MFC library right into your application. The executable that is produced will be larger in size but will work on any Windows machine.
Advance through the next three pages, taking the defaults until the following page is displayed.
(If you are using Visual 2010, this screen does not have a "None" option for Toolbars. Just choose "Use a Classic Menu" without checking either toolbar.) A thick frame allows the user to resize the window. Since our game is a static size, un-check this option. A maximize box isn't needed, nor is a status bar or a toolbar. Advancing to the next page will bring you to the "Advanced Features" page.
Turn off printing, ActiveX controls and set the number of recent files to zero. Since we won't actually be loading any files, this option won't be necessary. The last page of the MFC Application Wizard presents you with a list of generated classes.
Four classes that will be generated for you are the basis for the game. The first on the list is the view class, here it is called CSameGameView. I will come back to this class in a minute. The next class in the list is the application class. This class is a wrapper for the entire application and a main function is provided for your application by this class. The base class isn't selectable and must be CWinApp.
The next class in the list is the document class, CSameGameDoc based on the CDocument class. The document class is where all of the application data is stored. Again the base class cannot be changed.
The last class is the CMainFrame class. This CFrameWnd based class is the wrapper class for the actual window. The main frame class contains the menu and the client area view. The client area is where the actual game will be drawn.
Now back to the view class. The base class is a dropdown with a list of views that are generally available, each with its own use and application. The default view type is CView, which is a generic view where all of the display and interaction with the user must be done manually. This is the one that we want to select.
I will quickly go down the list and explain what each view type is used for, just for your information. The CEditView is a generic view which consists of a simple text box. The CFormView allows the developer to insert other common controls into it, i.e. edit boxes, combo boxes, buttons, etc. The CHtmlEditView has an HTML editor built into the view. The CHtmlView embeds the Internet Explorer browser control into the view. The CListView has an area similar to an Explorer window with lists and icons. The CRichEditView is similar to WordPad; it allows text entry but also text formatting, colors and stuff like that. A CScrollView is a generic view similar to CView but allows scrolling. Finally the CTreeView embeds a tree control into the view.
Finishing the MFC Application Wizard will produce a running MFC application. Since we haven't written any code yet it is a very generic window with nothing in it, but it is a fully functioning application all the same. Below is a screenshot of what your generic application ought to look like. To build your application, you can go to the Debug menu, and select Start without Debugging. Visual Studio may prompt you to rebuild the project—select "Yes".
Notice it has a default menu (File, Edit and Help) and an empty client area. Before we get to actual coding I'd like to explain a little about the document/view architecture that is used in MFC applications and how we are going to apply it to our game.

New Hard Drive Setup In 2 Minutes


So you just bought a new hard drive and you’re ready to set it up—but you have no idea what to do. Don’t worry! We’ll get you going in no time at all.

Connecting Your New Hard Drive To Your Computer

Before you connect your new hard drive to your computer, see if the drive came with any software or drivers on CD. Most drives don’t need drivers, but the software on the CD can help walk you through some of the steps we’ll describe below. (Note: drives which offer hardware encryption may require the drivers).
After you install any required software from the CD, connect your new hard drive to your computer. Different types of drives have different types of connectors, so here are instructions for the three most common types of drives:

1.   Large external USB or eSATA drives

These large drives require two cords—one for power and one for data. The really large drives have a power cord which plugs into your wall. Other drives have two USB cords, one which transfers data and one which doesn’t—plug both of them into a powered USB hub or into USB ports on your computer. If your computer and your drive support eSATA, connect the eSATA cord to your computer instead of one of the USB cords.

2.   Smaller USB or eSATA drives

These only require one connection. Choose whether you want to use USB or eSATA (eSATA is usually faster) and connect that cord to your computer. USB cords don’t fit eSATA devices and vice versa, so don’t worry about making a bad connection.

3.   Internal hard drives

sata hard drive
Modern drives all use SATA connections and 15-pin power connectors. Make sure your computer is unplugged from the wall before you start. Open up your computer, find a bay for your new hard drive and use the screws which should’ve come with your drive to mount the drive. Then connect one of the power cords inside your computer to the hard drive and use the SATA cord which came with the hard drive to connect the drive to the motherboard. Again, the cords are designed so only a SATA cord fits in a SATA plug and only a power cord fits in a power plug. After connecting everything, plug your computer back in and turn on the power.

New Hard Drive Formatting

External hard drives don’t usually need to be reformatted unless you want to use them for a special purpose. Internal hard drives also don’t usually need to be reformatted—but you can often get a performance boost by reformatting them.
Most hard drives come formatted with the File Allocation Table (FAT) filesystem which works on Windows, Mac, and Linux. But none of these operating systems is optimized to use FAT, so if you switch to a native filesystem for your internal drive, you’ll get extra speed and additional features. The native filesystems for each operating system are:
•     New Technology File System (NTFS) on Windows
•     Hierarchical File System Plus (HFS+) on Mac OS X
•     Extented Filesystem version 3 on Linux (Ext3)
In all three operating systems, you can reformat your drive by opening your file manager, finding the drive, right-clicking on it, and choosing “Format…” or “Format Drive”. A warning message will appear which informs you that all data on the drive will be lost—take a moment to ensure you’re formatting the correct drive before continuing.
In all three operating systems you’ll get to choose which filesystem you want to use. Choose the appropriate one from the list above or choose FAT if you want to use the same drive in multiple computers. Then wait for formatting to finish—as soon as it does, you can start to use your new hard drive.
- See more at: http://tips4pc.com/hardware-2/hard-drive-setup-2-minutes.htm#sthash.dopEFIC6.dpuf

Uses KEY F1 TO F12 in key board

F1: it name is help key. F1 Each program will take ‘Help’ in the.
F2: Usually change a file or folder name (Rename) for it.Alt+Ctrl+F2  If you add a new file is opened with MS Word.Ctrl+F2 Print preview in Word.
F3: It will take a lot of program search facility on the Microsoft windows.Shift+F3 Word by pressing the first letter of each word uppercase and lowercase or uppercase letters at the start of the work, etc.
F4: Word last action performed again (Repeat) key can be pressed it.Alt+F4 The program is activate  by  press.
F5: Microsoft Windows, Internet browsers, etc.Refresh Is F5 Press.PowerPoint slide show can be initiated.Word find, replace, go to and Window is opened.
F6: It places the mouse  web browser address line (address bar) of the.Ctrl+Shift+F6 If you open another Word document is activated.
F7 : Spelling and grammar in Word that is exactly what you said. Firefox Caret browsing Can be started.Shift+F7 Word Press has selected word synonym, antonym, etc., in order to determine the type of dictionary words on the.
F8 : This is useful when the operating system starts.Normally Windows Safe Mode-It is run by pressing.
F9 : Quarks Express 5.0  The key to open the Measurement toolbar.
F10: Web browser or an open window menu bar is selected by pressing the key.Shift+F10 If you have selected text or attachments, right-click the mouse moves over the link or the image of the key.
F11: Can be seen in full-screen web browser.
F12 : Microosoft Word Save as Window is opened by pressing the key.Shift+F12 If you save the file in Microosoft Word.And Ctrl+Shift+F12 Word files can be printed by pressing the key.
if anyone help from this information.my work is Successful.thanks for read it.good bye and take care.