GATE 2014 Answer Key by Made Easy Delhi


Civil Engineering Answer Key 2014


ECE Answer Key 2014


Mechanical Answer key 2014

Posted by Unknown On 03:37 No comments READ FULL POST
Polymorphism is one of the crucial features of OOP. It simply means ‘one name, multiple forms’. We have already seen how the concept of polymorphism is implemented using the overloaded functions and operators.
            Mainly they are two types of polymorphism.


Types of Polymorphism in C++:
Compile time polymorphism:
         
          The overloaded member functions are ‘selected’ for invoking by matching arguments, both type and number. This information if known to the compiler at the compile time and, therefore, compiler is able to select the appropriate function for a particular call at the compile time itself. This is called early binding or static binding. Also known as compile time polymorphism, early binding means that an object is bound to its function call at compile time.

Run time polymorphism:

Binding in C++:
           class Base                                                  //base
               {
int b;
public:
void display( )                //base member function
{
}
     };
class  Derived: public Base                      //derived
{
int d;
   public:
void display( )                 //derived member function
{
}
};
           
  How do we use the member function display( ) to display the values of objects of both the classes Base and Derived?. Since the prototype of display( ) is the same in both the places, the function is not overloaded and therefore static binding does not apply. We have seen earlier that, in such situations, we may use the class resolution operator to specify the class while invoking the functions with the derived class objects.

            It would be nice if the appropriate member function could be selected while the program is running. This is known as run time polymorphism. How could it happen?
           C++ supports a mechanism known as virtual function to achieve run time polymorphism.
At run time, when it is known what class objects are under consideration, the appropriate version of the function is invoked. Since the function is invoked with a particular class much later after the compilation, this process is termed as late binding. It is also known as dunamic binding because the selection of the appropriate function is done dynamically at run time.
Dynamic Binding is one of the powerful features of C++. This requires the use of pointers to objects. We shall discuss in detail how the object pointers and virtual functions are used to implement dynamic binding.
Posted by Unknown On 20:36 No comments READ FULL POST
11. Write a program to calculate gross and net pay of employee from basic salary. Create employee class which consists of employee name, emp_id, and basic salary as its data members. Use parameterized constructor in the derived class to initialize data members of the base class and calculate gross and net pay of the employee in the derived class.

#include<iostream.h>
#include<string.h>
class employee
{
    protected:
                int id,basic;                    
                char name[20];
    public:
                employee(int i,char *s,int b)
                    {
                        id=i;    
                        strcpy(name,s);         
                        basic=b;
                    }
                void show()
                    {
                        cout<<"\nEmp. Id: "<<id<<"\n";
                        cout<<"Emp. Name: "<<name<<"\n";
                        cout<<"Basic Salary: "<<basic<<"\n";
                    }
};
class grossnet: public employee
{
            float deduct,gross,net;
            public:
                        grossnet(int i,char *s, int b,int d,float g,float n): employee(i,s,b)
                        {
                                    deduct=d;      gross=g;         net=n;
                        }
                        void calculate();
};
void grossnet::calculate()
{
    float da,hra;
    da=0.4*basic;
    hra=0.2*basic;
    gross=basic+da+hra;
    net=gross-deduct;
    cout<<"Gross Pay: "<<gross<<"\n";
    cout<<"Net Pay: "<<net<<"\n";
}
 
void main()
{
    int eid,ebasic;
    float ededuct;
    char ename[20];
    cout<<"Enter:\n";
    cout<<"Employee Id: ";                  
    cin>>eid;
    cout<<"Employee Name: ";           
    cin>>ename;
    cout<<"Basic Salary: ";    
    cin>>ebasic;
    cout<<"Deductions: ";      
    cin>>ededuct;
    grossnet gn(eid,ename,ebasic,ededuct,0,0);
    gn.show();
    gn.calculate();
}

OUTPUT:

Enter:
Employee Id: 123
Employee Name: Lahari
Basic Salary: 10000
Deductions: 1450.0

Emp. Id: 123
Emp. Name: Lahari
Basic Salary: 10000
Gross Pay: 16000

Net Pay: 14550
Posted by Unknown On 03:33 3 comments READ FULL POST
10. Write a program which prompts the user to enter a string and returns the length of the longest sequence of identical consecutive characters within the string using pointers to data members and member function. For example, in the string "aaaAAAAAjjB", the longest sequence of identical consecutive characters is "AAAAA".

// Length of the Longest Sequence of Identical Consecutive Characters
// Input a String in which one letter has highest continuous frequency

#include<iostream>
#include<string>
using namespace std;
class sequence
{
            char s[20];                                  
  public:
            void getdata();
            void find(sequence);
};
void sequence::getdata()
{
            cout<<"Enter a String: ";
            cin>>s;
}
void sequence::find(sequence ob)
{
            int len,max,i,j,k=0,count=1,pos;
            char ch[20];                
            int fr[20];
            sequence *pm=&ob;  // pm is the pointer to object
            len=strlen(pm->s); // pointer to object -> pointer to member
            for(i=0; i<len; i++)
            {
                        j=i+1;
                        if(s[i]==s[j]) count++;
                        else
                        {
                                    ch[k]=s[i];    // put character in array 'ch'
                                    fr[k]=count;    // put count in array 'fr'
                                    k++;     count=1;
                        }
            }
            for(i=0; i<k; i++)
                        cout<<ch[i]<<fr[i]<<" ";
            cout<<"\n";
            max=0;
            for(i=0; i<k; i++)  // finds maximum continuous frequency
                        if(fr[i]>max)
                        {
                                    max=fr[i];       pos=i;
                        }
            cout<<"Letter "<<ch[pos]<<" has the Longest Sequence: "<<max<<"\n";
}
int main()
{
            sequence seq;
 
            void (sequence::*pg)()=&sequence::getdata;
            (seq.*pg)();
            void (sequence::*pf)(sequence)=&sequence::find;
            sequence *op=&seq;
            (op->*pf)(seq);
}

OUTPUT:

Enter a String: aaaAAAAAjjB
a3 A5 j2 B1
Letter A has the Longest Sequence: 5

Enter a String: jjjK
j3 K1
Letter j has the Longest Sequence: 3

Enter a String: ssjjkkMMM
s2 j2 k2 M3


Letter M has the Longest Sequence: 3
Posted by Unknown On 03:29 No comments READ FULL POST
  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Blog Archive

Contact Us


Name

E-mail *

Message *