Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Monthly Archive May 28, 2013

Difference between a Virtual class and an Abstract class in C++

May 28, 2013 Comments Off on Difference between a Virtual class and an Abstract class in C++ By admin

Difference between a Virtual class and an Abstract class in C++

Virtual Class: A virtual class is one that has been qualified as virtual in the inheritance definition.  When a derived class inherits from more than one base class, then it can inherits the members of a base class from multiple inheritance paths. If the base class is defined as virtual, only one copy of the members of the base class is inherited by the derived class irrespective of the fact that it can be inherited from a number of inheritance paths.

Abstract Class: An abstract class is one, which is never instantiated.  The objects of an abstract base class are never created.  A base class that contains pure virtual functions is an abstract base class.  A pure virtual function is a virtual function that has no implementation in its class.  Thus an abstract class provides a base upon which to build other classes.  It is designed only to act as a base class for other classes and it is not used to create objects.  Thus an abstract base class provides some transit to the derived classes and is never initiated.

Class Inheritance in C++

May 27, 2013 Comments Off on Class Inheritance in C++ By admin

Class Inheritance in C++

Class Inheritance which is a property of OOPs allows a new class to take up the behaviour as well as structure of existing classes, without having to re-design and re-implement this behaviour and structure for the new class.  Hence, the most important advantage of inheritance is code reusability.  A class that has been defined and tested may be used many times, which is extensibility feature supported by inheritance.  Thus the software developed can be reused and can be easily extended.  Every class inherits all the features of the super class.  Only additional features need to be defined, which specify and extend the class further.  The class from which the properties are inherited is referred to as the base class, whereas that class receiving inherited properties is termed as derived class.

Inheritance is achieved by deriving new classes from the existing ones and thus forming a hierarchy of classes.  The following are some of the advantages of inheritance:

a) Reusability:  Inheritance supports the concept of reusability. i.e. reusing existing codes without rewriting the entire code again.  We can derive new classes out of existing ones, without actually modifying it.

b)  Extensibility:  Extensibility of existing codes is the other advantage of using inheritance.  The derived class inherits some or all the properties of the base class and adds some extra features of its own.  This phenomenon of deriving a new class out of existing one i.e. derivation or inheritance helps in extending existing classes by adding new features to them.

c)  Transitive nature:  Inheritance is transitive in nature.  By transitive nature of inheritance we mean that if a child class inherited from a parent class is inherited further then all the sub-child of child class will in turn receive the properties of the parent class too.  For example: If a class named ‘child’ is inherited from another class named ‘father’, then all the sub-classes of ‘child’ will automatically inherit the properties of ‘father’.

d)  We can easily express inheritance relationship through inheritance diagram which is another advantage of inheritance.

All these features make inheritance an important phenomenon / property of OOPs.

Example: Create a class “Employee” of an organization with members Employee-no, Name, Designation, Basic pay.  Define a derived class Executive whose basic_pay is more than Rs. 10,000.

#include <iostream.h>
#include <conio.h>

#define MAX 5

class employee
{
int employee_no;
char name[25];
char desig[25];
float basic_pay;
public:
employee();
void getdata();
float check_sal();
void putdata();
};

employee :: employee()
{
employee_no=0;
basic_pay=0;
}

void employee :: getdata()
{
cout<<“\nEnter Employee Code>”;
cin>>employee_no;
cout<<“\nEmployee Name>”;
cin>>name;
cout<<“\nDesignation>”;
cin>>desig;
cout<<“\nBasic Salary>”;
cin>>basic_pay;
}

void employee :: putdata()
{
cout<<“\n\n\nEmployee Code:”<<employee_no;
cout<<“\nEmployee Name>”<<name;
cout<<“\nDesignation>”<<desig;
cout<<“\nBasic Salary>”<<basic_pay;
}

float employee :: check_sal()
{return(basic_pay);
}

class executive : public employee
{
int empno;
float comm;
public:
void getinfo(int i)
{empno=i;cout<<“\nCommission = “;
cin>>comm;
}
void putinfo()
{cout<<“\nFor employee no “<<empno;
cout<<“, commission = “<<comm;
}
};

void main()
{
int i,k=0,n=0;
employee emp[MAX];
executive exec[MAX];
clrscr();
cout<<“\nInput Employee Information:”;
for(i=0;i<MAX;i++)
{emp[i].getdata();
if(emp[i].check_sal()>10000)
{
cout<<“\nEnter Executive Information:”;
exec[k].getinfo(i+1);
k++;
}
}
cout<<“\nDisplaying Employee Information:”;
for(i=0,k=0;i<MAX;i++)
{
emp[i].putdata();
if(emp[i].check_sal()>10000)
{exec[k++].putinfo();
}
}
getch();
}

,

I can’t find make or gmake, and my life depends on it

May 27, 2013 Comments Off on I can’t find make or gmake, and my life depends on it By MANOJ AGARWAL

I can’t find make or gmake, and my life depends on it

When I tried to install perl-5.18.0 in CentOS 6.4, I got the following error: ‘I can’t find make or gmake, and my life depends on it.  Go find a public domain implementation or fix your PATH setting!’  The error message is shown in Figure-1.

                                                          [Figure-1]

I then did a group install of “Development Tools’ using yum command, as shown in Figure-2.

                                                          [Figure-2]

After installing Development Tools in CentOS 6.4, the error went away and I could install perl-5.18.0.

,

Install perl 5.18.0 in Centos 6.4

May 27, 2013 Comments Off on Install perl 5.18.0 in Centos 6.4 By MANOJ AGARWAL

Install perl 5.18.0 in Centos 6.4

To install Perl in CentOS 6.4, we need to take the following steps:

Step 1: Change directory to /usr/local/src, as shown in Figure-1.

                                                            [Figure-1]

Step 2: Download Perl from CPAN, using ‘wget’ command as shown in Figure-2.  If wget command doesn’t work, then we need to install wget using yum, ‘yum install wget’.

                                                            [Figure-2]

Step 3: Extract the files from tar of perl-18.0.tar.gz using tar command as shown in Figure-3.

                                                            [Figure-3]

 Step 4: Change directory to perl-5.18.0 using cd command as shown in Figure-4.

                                                            [Figure-4]

Step 5: To install perl-5.18.0, run configure command as shown in Figure-5.  Optionally we can also define a PATH towards its installation.

                                                            [Figure-5]

Step 6: After the command ‘./Configure  -des’ is executed successfully, we get the following screen, that shows the message – ‘Now you must run ‘make”.

                                                            [Figure-6]

 Step 7: Run the command ‘make’ as shown in Figure-7.

                                                            [Figure-7]

Step 8: Run the command ‘make test’ as shown in Figure-8.

                                                            [Figure-8]

Step 9: If all tests are done successfully, we get a confirmation that ‘All tests successful’, as shown in Figure-9.

                                                            [Figure-9]

 Step 10: Run ‘make install’ command as shown in Figure-10.

                                                            [Figure-10]

 Step 11: After running ‘make install’, perl-5.18.0 is installed successfully.  To confirm, check the version of installed perl using ‘perl -v’ command as shown in Figure-11.

                                                            [Figure-11]

Install apache 2.2.15 in CentOS 6.4

May 24, 2013 Comments Off on Install apache 2.2.15 in CentOS 6.4 By MANOJ AGARWAL

Install apache 2.2.15 in CentOS 6.4

Apache HTTP server is an open source and most popular web server for Linux distributions as well as for Windows. The website is: http://httpd.apache.org/

CentOS 6.4 comes with Apache version 2.2.15-28.  To install Apache 2.2.15 in CentOS 6.4, we need to do the following:

If yum repository is configured correctly in CentOS, we can use yum command to install httpd, as shown in Figure-1

                                                          [Figure-1]

yum lists all dependencies required to install httpd and lists them as shown in Figure-2.  Press ‘y’ to confirm installing ‘httpd’, along with all its required dependecies.

                                                         [Figure-2]

Once httpd is installed, we get the message that httpd installation along with all of its dependencies is complete as shown in Figure-3.

                                                         [Figure-3]

Restart httpd service using the command, ‘service httpd restart’.  If httpd is started successfully, we see [ OK ] message as shown in Figure-4.

                                                        [Figure-4]

To configure apache settings, we need to make changes in apache configuration file, that is located in ‘/etc/httpd/conf’ directory by the name ‘httpd.conf’ as shown in Figure-5.

                                                        [Figure-5]

Logs from apache are stored in the location ‘/var/log/httpd’.  Two basic log files are frequently used to analyze the activity of Web-server, these are ‘access_log’ and ‘error_log’.  To view these files, use vi editor/tail command/cat command etc. as shown in Figure-6 and 7.


                                                       [Figure-6]

                                                       [Figure-7]

To start apache server at start-up, use the following command:
chkconfig httpd on

To test if apache is running and configured correctly, type this url: ‘http://localhost’ in the browser, and see that apache test page is displayed.

 

,

Install Postgresql 9.2.4 in CentOS 6.4

May 23, 2013 Comments Off on Install Postgresql 9.2.4 in CentOS 6.4 By MANOJ AGARWAL

How to install Postgresql 9.2.4 in CentOS 6.4

PostgreSQL is an open source object relational database system.  It comes pre-bundled with CentOS 6.4, the version of Postgres that is bundled with CentOS 6.4 is 8.4.13.  The latest version of Postgres available as on today is 9.2.4.  If we wish to install this latest version in CentOS 6.4, we have to follow the following steps:

Step 1: Download PostgreSQL v9.2.4 from postgres website by clicking on Download button, given below:

DOWNLOAD PostgreSQl – v9.2.4
[postgresql-9.2.4.tar.gz]
 

Step 2: Copy this file in /usr/local/src

Step 3: Change directory to /usr/local/src, as shown in Figure-1.

                                                          [Figure-1]

Step 4: Unzip the contents of tar using ‘tar -xvzf postgresql-9.2.4.tar.gz’ command as shown in Figure-2.

                                                          [Figure-2]

Step 5: Change directory to postgresql-9.2.4, as shown in Figure-3.

                                                          [Figure-3]

Step 6: Start the installation of Postgres by typing the command: ‘./configure –without-readline –without-zlib’, as shown in Figure-4. 

                                                          [Figure-4]

Step 7: Run command ‘gmake’ as shown in Figure-5.

                                                          [Figure-5]

 Step 8: Run command ‘gmake install’ as shown in Figure-6.

                                                          [Figure-6]

Step 9: Add user ‘postgres’ in CentOS using adduser command and set a password for this user using ‘passwd postgres’ command as shown in Figure-7.

                                                          [Figure-7]

Step 10: Make a new directory for PGDATA, as ‘/var/ lib/pgsql/data’ as shown in Figure-8.

                                                          [Figure-8]

Step 11: Change ownership of this newly created directory ‘/var/lib/pgsql/data’ as postgres.postgres.

                                                          [Figure-9]

Step 12: Switch to non-root user ‘postgres’ using ‘su’ command.  Once logged in as ‘postgres’, run the following command to initialize the database:

/usr/local/pgsql/bin/initdb -D /var/lib/pgsql/data

                                                          [Figure-10]

Step 13: Once database is initialized, we can run the postgres server using the following command:
/usr/local/pgsql/bin/postgres -D /var/lib/pgsql/data > pg_log 2>&1 &

                                                          [Figure-11]

Step 14: Create a database named ‘tests’ and use this database using the following commands as shown in Figure-12.

                                                          [Figure-12]

Step 15: Exit from psql prompt using ‘\q’, exit from ‘postgres’ user shell and open ‘pg_hba.conf’ file inside ‘/var/lib/pgsql/data’ as shown in Figure-13.

                                                          [Figure-13]

 Step 16: Now we need to set up start script for starting PostgreSQL like other services in CentOS.  There is a default start-script named ‘linux’ in this location:
‘/usr/local/src/postgresql-9.2.4/contrib/start-scripts/’

                                                          [Figure-14]

Step 17: Copy this start-script for PostgreSQL in ‘/etc/init.d/’ directory by the name ‘postgresql’ as shown in Figure-15.

                                                          [Figure-15]

Step 18: We can change configuration settings in this start-up script.  To change the settings, open ‘/etc/init.d/postgresql’ in ‘vi’ editor.

                                                          [Figure-16]

Step 19: One thing we need to change in postgresql start-up script is PGDATA location to ‘/var/lib/pgsql/data’ as shown in Figure-17.

                                                          [Figure-17]

Step 20: Grant execute permission to this start-up script using ‘chmod’ as shown in Figure-18.

                                                          [Figure-18]

Step 21: Now we can start, stop, restart or see status of postgresql service using following commands:

# service postgresql start
# service postgresql restart
# service postgresql status
# service postgresql stop

Use ‘chkconfig’ command to start PostgreSQL service at startup of CentOS as shown in Figure-19

                                                          [Figure-19]

Reboot CentOS and see using ‘service postgresql status’ command, if this service starts automatically at startup.

So, we have installed PostgreSQL 9.2.4 in CentOS 6.4.

,

CPAN error please check the validity of the index file

May 23, 2013 Comments Off on CPAN error please check the validity of the index file By MANOJ AGARWAL

CPAN error please check the validity of the index file

To install a module from CPAN in CentOS, we need to install perl-CPAN module.  After it is installed, we may use interactive shell by using the command: “perl -MCPAN -e shell”, or we can also use ‘CPAN’ command to install a cpan module.  When I tried to install a CPAN module, I got an error: ‘Please check the validity of the index file by comparing it to more than one CPAN mirror’, as shown in Figure-1.

                                                            [Figure-1]

It looks as if the something got corrupted in cpan installation, I tried to remove the ‘.cpan’ directory from inside root, as shown in Figure-2.

                                                            [Figure-2]

After deleting ~/.cpan directory, I uninstalled perl-CPAN module from CentOS, using the command: ‘yum remove perl-CPAN’, as shown in Figure-3.

                                                            [Figure-3]

After uninstalling perl-CPAN module, I did a re-install of this module using yum, as shown in Figure-4.

                                                            [Figure-4]

Yum searched for its dependencies that are not installed and listed it as shown in Figure-5.  In this case, only the package needs to be installed as all dependencies are already installed.  Press ‘y’ to continue installing all packages.

                                                            [Figure-5]

It installs the perl-CPAN module along with all of its dependencies as shown in Figure-6.

                                                             [Figure-6]

Now, if I try to install CPAN modules with ‘cpan’ command or try an interactive shell using ‘perl -MCPAN -e shell’, it all worked fine and the problem ‘Please check the validity of the index file by comparing it to more than one CPAN mirror’, got FIXED.

 

,

Can’t locate CPAN.pm – Fixed

May 23, 2013 Comments Off on Can’t locate CPAN.pm – Fixed By MANOJ AGARWAL

Can’t locate CPAN.pm – Fixed

To install Perl modules from CPAN using an interactive shell, we use the command:
perl -MCPAN -e shell

If we type this command in CentOS 6.4, we get an error as shown in Figure-1

                                                            [Figure-1]

If we get an error “Can’t locate CPAN.pm”, it means that the module ‘perl-CPAN’ is not installed in CentOS.  This package comes pre-bundled with CentOS and we have yum configured correctly in CentOS, we can install this module as shown in Figure-2.

                                                             [Figure-2]

When we use yum to install perl-CPAN module, it looks for its dependencies and lists them as shown in Figure-3.

                                                                 [Figure-3]

Once we press ‘y’ to continue installing the package along with its dependecies, the package is installed in CentOS.  After installing the package, when we issue the command again: perl -MCPAN -e shell, we get an interactive shell prompt, as shown in Figure-4 and the problem “Can’t locate CPAN.pm’ is SOLVED.

                                                                 [Figure-4]

Installing perl-CPAN modules solves the issue ‘Can’t locate CPAN.pm in @INC’.

,

Installation of CentOS 6.4 in VMWare Workstation 9.0.2

May 16, 2013 Comments Off on Installation of CentOS 6.4 in VMWare Workstation 9.0.2 By MANOJ AGARWAL


Installation of CentOS 6.4 in VMWare Workstation 9.0.2

We have seen in our previous post how to Create a CentOS 6.4 Virtual machine in VMWare Workstation 9.0.2. Now we will look into the installation steps of CentOS 6.4 operating system inside VMWare Workstation.

In Virtual machine ‘Edit settings’ option, chose CD/DVD option to select the installation Disk/ISO images from CentOS.  Remember to check the option ‘Connect at power on’, so that the CD/DVD/ISO is connected to the machine when we boot it.  When we start the Virtual machine, we get the Figure-1 as shown below.  Select ‘Install or upgrade an existing system’ to do a fresh installation of Centos 6.4.

                                                                   [Figure-1]

In the next step, it asks to do a media test before beginning the installation.  We may chose to go for a media test to verify the installation Disk/ISO image, or we may skip this test.  Select ‘Skip’ as shown in figure-2.

                                                                   [Figure-2]

In the next figurre, it displays the logo of CentOS 6, as shown in figure-3.

                                                                   [Figure-3]

In the next step, we need to chose the language that we would like to use during the installation process.  The default selection is Engish (English).  If we need to select any different language, we may do the selection from the given list, else we may leave the default language and clieck Next as shown in figure-4.

                                                                   [Figure-4]

We have to now select the appropriate keyboard based on regional settings.  The keyboard, by default, is shown as U.S. English.  If we prefer ‘United Kingdom’, we may chose that or any other option from the given list, based on our keyboard.  We may leave the default selection as ‘U.S. English’ for now and click ‘Next’ as shown in figure-5.

                                                                   [Figure-5]

In the next step, we need to specify the storage device for this installation.  We may chose ‘Basic Storage Device’, that is by default, or we may chose ‘Specialized Storage Devices’ for SAN storage or other such specialized storage.  Chose the default option and click on ‘Next’ as shown in figure-6.

                                                                   [Figure-6]

Next, we get a warning for Storage Device, that it may contain data, we may chose to ‘Discard any data’ that is  in it, or we may chose to keep the data, if we think, the virtual disk contains some data.  In this case, it is a new virtual disk, so we may chose ‘Yes, discard any data’, also we need to check the option ‘Apply my choice to all devices with undetected partitions or filesystems’ to make it applicable as shown in figure-7.

                                                                   [Figure-7]

Specify the hostname for this machine.  We may chose any hostname, for this installation, we may use ‘centos64’ as the hostname as shown in figure-8.  We may also use a fully qualified domain name as hostname.  We may Configure network at this stage or leave it for now, as we can do it later once installation is done.  Click on ‘Next’ to continue.

                                                                   [Figure-8]

Next, we need to select the timezone, we may chose the appropriate timezone, in this case, ‘Asis/Kolkata’ as shown in figure-9 and click on ‘Next’ to continue.

                                                                   [Figure-9]

We need to give a password for ‘root’ account.  ‘root’ account is the administrator account in CentOS.  Try to give a strong password and click on ‘Next’ to continue as shown in figure-10.

                                                                   [Figure-10]

The next screen provides the options to use disk space.  We may chose to ‘Use all space’, which means that all partitions will be removed and the complete disk will be available for use.  We may also chose to replace only the linux system, and leave other partitions such as VFAT or FAT32 as such.  We may chose to ‘Shrink current system’ to make room for new installation.  We may chose not to touch the existing partitioning layout and use only the free space for new installation.  We may also chose to create a custom layout as per our requirement.  As it is a new virtual disk, click on ‘Use all space’ as shown in figure-11 and click ‘Next’ to continue.

                                                                   [Figure-11]

Next step is to create a partitioning layout for this new installation.  We may chose to create a Volume Group and Logical Volumes inside this Volume Group.  We have taken a virtual disk size of 100GB, so we can allocate this size among various Physical partitions, Volume Groups and Logical Volumes.  The next screen ‘Please select a Device’ as shown in figure-12 is used for this.

                                                                   [Figure-12]

To take an example, we may define the following partitioning layout:

Filesystem Mounted on Size
 /dev/sda1 /boot 500mb
 vg_centos64 100000mb
   lv_var /var  20000mb
   lv_htdocs /htdocs  35000mb
   lv_root /  10000mb
   lv_home /home  3000mb
   lv_tmp /tmp  3000mb
   lv_mondo /mondo  10000mb

                                                                  [Table-1]

After creating the structure as per Table-1, we get the figure-13 as shown below:

                                                                   [Figure-13]

Clicking on Next button shows the figure-14, that gives Format warnings that /dev/sda will be formatted and all data inside it will be destroyed.  Click on Format to continue.

                                                                   [Figure-14]

The next screen Figure-15 shows the warning about Writing storage configuration to disk. It displays a message that the partitioning options will be written to disk and data on it will be lost.  Click on ‘Write changes to disk’ button.

                                                                   [Figure-15]

The  next figure-16 shows that the formatting is being done on the disk.

                                                                   [Figure-16]

The next figure-17 shows the options to set Boot loader operating system, It will be installed on /dev/sda and on vg_centos64-lv_root.  We also get an option to define a boot loader password, if required.  Click on ‘Next’ to continue.

                                                                   [Figure-17]

On clicking ‘Next’ button, it starts to process the installation and tries to retrieve the installation information for CentOS as shown in figure-18.

                                                                   [Figure-18]

This step is important as we can define in this step what to install.  The default installation is Minimal install.  We may chose other options such as Basic server, Database server, Web server etc. based on our requirement.  Chosing these options decide what packages will be installed and what not.  We can also do a Customized installation, now or later, where we may chose what packages should be installed from the list.  We may chose Minimal install option for our example case and click on ‘Next’ as shown in figure-19.

                                                                   [Figure-19]

When we click on ‘Next’ button, we see the message ‘Installation starting’ and the installation process starts for minimal installation of CentOS as shown in figure-20.

                                                                   [Figure-20]

After the installation is finished, we get the following screen as shown in figure-21, that your CentOS installation is complete.  Click on ‘Reboot’ to restart the virtual machine.

                                                                   [Figure-21]

,

Boot time scan with Avast antivirus 8.0

May 16, 2013 Comments Off on Boot time scan with Avast antivirus 8.0 By MANOJ AGARWAL


Boot time scan with Avast antivirus 8.0

Avast free Anti-virus is used to protect the computers from viruses.  Avast anti-virus 8.0 is a free software that can be downloaded from: http://www.avast.com/en-in/index

We can schedule boot time scan to do a through check of the PC, so that when we restart it, Avast does a boot time scan for viruses.  To schedule a boot time scan, we have to follow the following steps:

  • Open Avast user interface.
  • Click on ‘Security’ tab.
  • Click on Antivirus in the list of tabs on the left side.
  • Click on ‘Scan now’ option inside ‘Antivirus’.
  • On the right side, scroll to bottom, to see ‘Boot-time scan’ option.
  • Click on ‘Schedule now to schedule to run the scan on next system restart as shown in Figure-1.

                                                                                   Figure-1

  • We can set Boot-time parameters as shown in Figure-2, which we get by clicking on ‘Settings’ button.
  • Areas to scan ‘All harddisks’, is default.  Click on ‘Add’ to select specific locations we want to scan.
  • Leave these two options checked, ‘Scan for potentially unwanted programs (PUPs)’ and ‘Unpack archive files’.
  • We need to specify an automatic option, if we need an unattended scan, from the options provided in ‘When a threat is found, apply the following action’, chose ‘Move to chest’ option, other options shown are ‘Repair’, ‘Ask’, ‘Delete’ and ‘No action.

  • Once done with these settings, restart the computer.

 

x Close

Like Us On Facebook

You cannot copy content of this page.