Digital Music

Showing posts with label IT. Show all posts
Showing posts with label IT. Show all posts

12/25/2009

Friend Function in C++

any data declared in the class are private, and not accessible outside of class. A function that is not in the class will never be able to access the data in a class that is private. But there are certain cases where we need to access the private data.

Class will give permission to other functions outside the class to read the data, namely by making it a friend function of the class.

• friend function defined outside of the class's scope However the have access to all the members of the class

• once a function declared as a friend, a function that can access private data from these classes.

• Declaration friend funcion dg keyword 'friend'

C++ Tutorial - Friend function sample:
#include
//Declaration of the function to be made as friend for the C++ Tutorial sample
int AddToFriend(int x);
class CPP_Tutorial
{
int private_data;
friend int AddToFriend(int x);
public:
CPP_Tutorial()
{
private_data = 5;
}
};
int AddToFriend(int x)
{
CPP_Tutorial var1;
return var1.private_data + x;
}
int main()
{
cout << "Added Result for this C++ tutorial: "<< AddToFriend(4)<< iostream.h >
class CPP_Tutorial
{
int private_data;
friend class friendclass;
public:
CPP_Tutorial()
{
private_data = 5;
}
};
class friendclass
{
public:
int subtractfrom(int x)
{
CPP_Tutorial var2;
return var2.private_data - x;
}
};
int main()
{
friendclass var3;
cout << "Added Result for this C++ tutorial: "<< var3.subtractfrom(2)<
}

Class and Object in C++

A. A glimpse of the class

Class is made to present a particular object that will assist in the process of solving complex problems. If we observe, the definition of a class that would be the creation of new data types. As an example we can make the types associated with an object such as cars, houses, employees and others.

B. What is the class?

Class is a form of simplification of the problems associated with the object. Classes can also be defined as something that has the data (properties) and funsi (behavior). Abstract class, therefore we must do Instantiation of the class, then instance (or realization of real-life examples) of these classes are also often called the object, As with humans is an example of the class instance or object of man is Irwan, Yana, Eric and others.

C. How do I create a class?

In C + +, the class created using the keyword class. The general form of manufacture, namely:

Class nama_kelas (

Access_specifier1:

Data_members;

Member_functions;

... ... ...

Access_specifier2:

Data_members;

Member_functions;

... ... ...

... ... ...

);

To make the implementation-fungsiyang functions found on a class, we use the operator::. The general form of manufacture, namely:

Tipe_data nama_kelas:: nama_fungsi (daftar_parameter) (

Statemen_yang_akan_dilakukan;

... ... ..

)

Sedangka to access data or funsi contained in these classes, we use a dot. The general form of manufacture, namely:

Nama_instance.data

Or

Nama_instance.nama_fungsi (daftar_parameter)

D. CONTRUCTOR and destructor

1. Constructor Definition

Constructor is a function that automatically called every time do Instantiation of a class. Constructor used to initialize the value of the data contained in the relevant class.

2. Destructor Definition

Destructor is a function which is the opposite of the constructor, which is useful to destroy or dispose of an object (class) of memory. The name of the function is the same as destruktor class name or the name of the constructor, only the tilde sign in front added ('~').

In C + +, there are three access levels are:

1. Private

This access level is useful to provide data access rights only to the respective class only. This means derivative classes or external environment within the program are not allowed to access the data. Here is a picture of defining a class that uses the private access level.

Class EXAMPLE (

Int x; / / By default, the private nature Xakan

Public:

Int Y; / / Y will be public

Private:

Int Z; / / Z will be private
);

1. Public

This access level serves to provide general access rights (public) to the derived classes as well as the external environment within the program. This section usually contains the functions that will serve as a link (interface)

1. Protected

This access level is used to grant access to data in a class so that data can be accessed by derived classes, but the external environment within the program still does not give rights to the mengakasesnya

E. Members of the class is static

In the C + +, the members of a class (data and functions) can be used as static, ie by increasing the static keyword in front of pendeklarasiannya.

1. Static Data

Please note that when we declare a static data, we do not define it. This means that the previous data is not stored in the memory. For that we need to provide a global definition for the data to any location provided that are outside the relevant class.

1. Static Function

Just as data or variables from a class, that functions contained in a class can also dijadiakan static functions. Same way, namely by adding the keyword static in front of him. But in doing this we need to consider all the following things:

a. Static functions contained in the class does not have this pointer

b. Static functions can not be virtual

c. There should not be two (or more) the same function, although that one is static and the other non-static.

F. Pointer to the object

Pointer to the object will also access data or functions in the classroom using the operator ->, and not use the service period (.) As in the instance which is not a pointer.

This pointer

This pointer is a pointer that is passed secra automatically every time the object was made in memory and will represent the corresponding class name.

G. Objects As Parameters in a Function

In C + +, objects can also serve as a parameter in the definition of a function. This object will be missed by the standard method is by using pass by value (based on value delivered) which aims to access the data (which is public) in a class diman processing functions performed in the outside (not a member function).

H. Returned Value As Object in a Function

In addition to being a parameter, an object can also be used as the value change of a function. In the function will create a temporary object which will then be released immediately after the return value.

12/24/2009

Spam Fighting Tips



Spam is email that is not invited, junk email, in the form of advertising or chain letters. Here, I'll give some tips to fight spam:

1. Delete the email without opening it first
If you do not know his name or topic sender in the email title line, delete the email without reading it. Be sure from time to time you are free from the emails that have been deleted. If not, "trash" you will be quickly filled.

2. Never respond to spam messages
Never respond to spam messages. In his response, it means you have to confirm to spammers that your email address is indeed active.

3. Decide to say no
When you register on the website, for example, read its privacy policy to find out how a web site using your email address, and do not let them use it without seizing you.

4. Ask for help from the IAP (Internet Access Provider)
IAP usually offer free spam filter for you (for example, Earthlink's Spaminator and Hotmail's Brightmail) for avoid spam before it enters your email account.

5. Opponent Only
If you want to fight spammers also disturbances other internet, check abuse.net (www.abuse.net) or Ed Falk's Spam Tracking Page (www.rahul.net / Falk).

Good luck ..

12/23/2009

Executing Shell Script From Java Programming



Hey guys, in this time, i want to share something about Java Programming. Shell script is a script written for the shell, or command line interpreter, of an operating system.
Here is an example to show how to execute the shell scripts from java programs.
If you want to execute the below program set the java path in Unix environment.

export PATH=$PATH:/usr/jdk1.5.0/bin
export CLASSPATH=$CLASSPATH:/usr/jdk1.5.0/bin
create a shell script like shellscript.sh
#!/bin/bash
clear
echo "Good morning, world."

then change the permission for this script.if you execute the shell script you need execute permission.

chmod 777 shellscript.sh
try
./shellscript.sh

From java program

import java.io.IOException;
public class JavaScript {
public static void main(String[] args) {
try {
Runtime.getRuntime().exec("/root/shellscript.sh");
System.out.println("Working Fine");
} catch (IOException e) {
e.printStackTrace();
}
}
}

Happy Trying ..

12/09/2009

Websites for learning Programming...It's Free!



A programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human communication.
Here's the websites for leaning programming



#1 Learn CSS

You can visit :


#2 Learn PHP

You can visit:


#3 Learn HTML

You can visit :


#4 Learn Javascript

You can visit :


#5 Learn ASP

You can visit :


11 Ways to Prevent Computer Viruses

It doesn’t matter if you’ve been on the Internet for five minutes or five years, you’ve probably thought about ways in which you can prevent a computer virus from entering your machine. A virus can compromise your personal information and even destroy your computer completely. Luckily, there are many low cost things you can do to protect yourself and stay one step ahead of the hackers. Here are 11 things you can do to help prevent computer viruses from invading your computer.

1. Install a reliable anti virus program – From the first moment you turn your computer on, you should have a trusted anti virus program by your side. Even if you have a machine that isn’t hooked up to the Internet, a reliable anti virus program is a low cost and common sense addition to any machine. There are even free anti virus programs you can download that work almost as well as industry giants like Norton and McAfee.

2. Install anti-spyware and anti-malware programs – As good as the best anti virus programs are, they sometimes need a little bit of help. Thankfully, many of the top anti-spyware programs are completely free. Spybot Search and Destroy and CCleaner are just two free programs that can help prevent computer viruses from doing any damage on your machine. As helpful as these programs are, however, you must update them and run them on a regular basis for them to do any good.

3. Avoid suspicious websites – A good virus protection program will alert you when you visit a website that attempts to install or run a program on your computer. Many less than reputable adult websites do this, so if you get a warning, don’t go back, you may end up with a bug you can’t get rid of.

4. Never Open Email Attachments Without Scanning Them First – The most common way viruses are spread throughout the Internet is still via email. Some attachments, like pictures, now display in emails and don’t require an attachment to be manually opened, but other documents do. Make sure you use an email client that scans all email attachments before you are allowed to open them. This will help prevent computer viruses from getting a foothold on your machine.

5. Set up Automatic Scans – Many of the top anti virus programs, as well as the best anti-spyware programs, now have settings that will let them automatically run during down times or in the middle of the night. Of course, your computer must be on for this to happen, but having daily scans run when nothing else is going on is a great way to prevent even the latest computer viruses from sticking around too long.

6. Watch Your Downloads – Part of the fun of the Internet is downloading music, movies and other items. However, since these downloads are so massive, it can be easy to sneak a virus along for the ride. Only download these files from trusted sites that you can count on, or, at the very least, scan them before you open them.

7. Updates, Updates, Updates – There is a reason why Windows has a feature called Critical Updates. There is an entire branch of Microsoft dedicated to staying one step ahead of the hackers out there so when they manage to fix a possible security loophole, you need to download the patch right away. Help Microsoft help you prevent computer viruses from causing too much trouble.

8. Know What To Look For – Even if you are just a casual computer user, you should have an idea of how your machine operates, what normal pop up windows look like and what popular viruses are out there, that way, when your computer begins exhibiting tell tale signs, you’ll know. You can help prevent computer viruses by staying updated and educated.

9. Stay Away From Cracked Software – It is so secret that you can download illegal, cracked versions of some programs online. As tempting as it may be, these files are almost always infested with advanced and difficult to detect bugs. Play it safe and get your software from the source.

10. Install a Firewall – A firewall is a program that screens incoming Internet and network traffic. Along with your virus program, it can help prevent unauthorized access to your computer.

11. Be prepared to Lock Down – If you hear of a virus that is spreading like wildfire through the Internet, make an extra effort to be careful. Don’t open any suspicious emails or accept any downloads for a week or two until your virus protection program has been updated and you are, once again, safe.

11/28/2009

Some Hints and Tips on how to avoid virus infections:


Tip 1 : The most common viruses can be disguised as attachments of funny images, greeting cards, or audio and video files and spread by sending them via e-mail messages.

    * Thus, you are advice not to open e-mail attachments unless you know who it’s from and you are expecting it.

Tip 2 : MSN Messenger is getting more and more famous, or even becomes the world’s leading messenger. Unfortunately, many bad people are taking this opportunity to spread computer viruses to the people who are using MSN messenger around the world. This kind of virus is very destructive and they spread from one to another by forcing your messenger to send the virus automatically to your friends by offering some sort of interesting words and notable files such as a message like “is that you on this photo?” with a zipped file which probably be named as “photo0050.jpg” or “photo0050.zip”. These files are definitely viruses.

    * So, you are advice not to receive any suspected files from your friends, even the closest one.
    * You should judge a file by its size with your common sense.
    * You should ask your friend once again to determine whether or not they are really there to send you something, but not the auto-virus.

Tip 3 : Viruses are easily spread by carrying it on a removable medium such as floppy disk, USB drive or CD.

    * Therefore, you should always scan diskettes, CD’s and any other removable media before using them.

Tip 4 : Internet is the main media for virus to spread. Every downloadable file may consists of viruses.

    * You should always scan files downloaded from the Internet before using them.
    * You are advice not to install any unapproved software on your computer.

Tip 5 : The General tip to avoid virus infection.

    * An anti-virus software must be installed in your computer.
    * Ensure that your anti-virus software is up to date.
    * Ensure that your operating system is up to date and patched with the latest security updates. For instance, you should enable Windows Update if you are using Microsoft Windows Operating System.
    * Scan your computer on a regular basis.
    * Install and run a firewall on your computer.

Remember, the more time you spend familiarizing yourself, not just with the anti-virus programs but with your computer, the better you will be, just like everything else, practice makes perfect.
Good Luck guys ^_^!