HOME

Sunday, November 29, 2015

PROGRAM FOR PUT AND GET FUNCTION IN FILE HANDLING

#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main()
{
    char str[50];
    cout<<"Enter the string"<<endl;
    cin>>str;
    fstream obj;
    obj.open("abc.txt",ios::in|ios::out);
    int length;
    length=strlen(str);
    for(int i=0;i<length;i++)
    {
        obj.put(str[i]);
    }
    obj.seekg(0,ios::beg);
    cout<<"READING FROM FILE"<<endl;
    char ch;
    while(obj)
    {
        obj.get(ch);
        cout<<ch;
    }
    obj.close();
    return 0;
}

WRITING AND READING FROM FILE USING CONSTRUCTOR FUNCTION

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
    char name[20];
    int age;
    cout<<"ENTER NAME AND AGE"<<endl;
    cin>>name>>age;
    ofstream obj("1.txt");
    obj<<name<<"\n";
    obj<<age<<"\n";
    obj.close();
    ifstream obj1("1.txt");
    char str[20];
    int x;
    obj1>>str;
    obj1>>x;
    obj1.close();
    cout<<"NAME= "<<str<<endl;
    cout<<"AGE= "<<x<<endl;
    return 0;
}

MULTIPLE INHERITANCE

#include<iostream>
using namespace std;
class employee
{
protected:
    char name[20];
    int id;
public:
    void getdata()
    {
        cout<<"ENTER NAME AND ID"<<endl;
        cin>>name>>id;
    }
};
class salary
{
protected:
    float salaryy;
public:
    void getdata()
    {
        cout<<"ENTER SALARY"<<endl;
        cin>>salaryy;
    }
};
class bonus
{
protected:
    float bonuss;
public:
    void getdata()
{
    cout<<"ENTER BONUS AMOUNT"<<endl;
    cin>>bonuss;
}
};
class total: public employee, public salary, public bonus
{
    protected:
    int totall;
public:
    void getdata()
{
    totall=salaryy+bonuss;
        cout<<"NAME= "<<name<<endl;
    cout<<"ID = "<<id<<endl;
    cout<<"SALARY = "<<salaryy<<endl;
    cout<<"BONUS= "<<bonuss<<endl;
    cout<<"TOTAL SALARY= "<<totall<<endl;
}
};
int main()
{
    total s1;
    s1.employee::getdata();
    s1.salary::getdata();
    s1.bonus::getdata();
    s1.total::getdata();
    return 0;
}

BASIC TO CLASS TYPE

#include<iostream>
using namespace std;
class sample
{
    int hr,mn;
public:
    sample()
    {

    }
    sample(int x)
    {
       hr=x/60;
       mn=x%60;
    }
    void display()
    {
cout<<"hour= "<<hr<<endl;
cout<<"minute= "<<mn<<endl;
    }
};
int main()
{
    int x;
    cout<<"Enter duration"<<endl;
    cin>>x;
    sample s1;
    s1=x;
    s1.display();
return 0;
}

BINARY == OVERLOADING USING FRIEND FUNCTION

#include<iostream>
using namespace std;
class sample
{
    int a;
public:
    void getdata()
    {
        cout<<"ENTER VALUE"<<endl;
        cin>>a;
    }
    void display()
    {
        cout<<"VALUE = "<<a<<endl;
    }
    friend int operator==(sample &obj1, sample &obj2);
};
int operator==(sample &obj1,sample &obj2)
{
    if(obj1.a==obj2.a)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int main()
{
    sample s1,s2;
    s1.getdata();
    s2.getdata();
    if(s1==s2)
    {
        cout<<"BOTH VALUE IS EQUAL"<<endl;
    }
    else
    {
        cout<<"VALUE ARE NOT EQUAL"<<endl;
    }
    return 0;
}

BINARY * OVERLOADING USING MEMBER FUNCTION

#include<iostream>
using namespace std;
class sample
{
    int a;
public:
    void getdata()
    {
        cout<<"ENTER NUMBER"<<endl;
        cin>>a;
    }
    void display()
    {
        cout<<"VALUE = "<<a<<endl;
    }
    sample operator *(sample &obj)
    {
       sample temp;
       temp.a=a*obj.a;
       return temp;
    }
};
int main()
{
sample s1,s2,s3;
s1.getdata();
s2.getdata();
s1.display();
s2.display();
s3=s1*s2;
s3.display();
return 0;
}

DECREMENT OPERATOR OVERLOADING

#include<iostream>
using namespace std;
class decrement
{
    int a,b;
public:
    void getdata(int x, int y)
    {
    a=x;
    b=y;
    }
    void display()
{
    cout<<"DECREMENT VALUE OF A = "<<a<<endl;
    cout<<"DECREMENT VALUE OF B = "<<b<<endl;
}
    friend void operator--(decrement &obj);
};
void operator--(decrement &obj)
{
    --obj.a;
    --obj.b;
}

int main()
{
    decrement s;
    s.getdata(6,7);
    --s;
    s.display();
}

DYNAMIC INITILIZATION OF OBJECT INCLUDING CONSTRUCTOR

#include<iostream>
using namespace std;
class simple
{
    int p,t,r;
public:
    simple(int x, int y, int z)
    {
        p=x;
        t=y;
        r=z;
    }
    void display()
    {
        int result=(p*t*r)/100;
        cout<<"SIMPLE INTEREST IS "<<result<<endl;
    }
};
int main()
{
    int x,y,z;
    cout<<"ENTER PRINCIPLE, TIME AND RATE "<<endl;
    cin>>x>>y>>z;
    simple s1(x,y,z);
    s1.display();
    return 0;

}

FRIEND FUCNTION TO FIND GREATER NUMBER

#include<iostream>
using namespace std;
class XYZ;
class ABC
{
    int x;
public:
    void getx()
    {
        cout<<"ENTER VALUE OF X"<<endl;
        cin>>x;
    }
    friend void greaterr(ABC,XYZ);
};
class XYZ
{
    int y;
public:
    void gety()
    {
        cout<<"ENTER VALUE OF Y "<<endl;
        cin>>y;
    }
    friend void greaterr(ABC,XYZ);
};
void greaterr(ABC obj1, XYZ obj2)
{
    if(obj1.x>obj2.y)
    {
        cout<<"X is greater"<<endl;
    }
    else
    {
        cout<<"Y is greater"<<endl;
    }
}
int main()
{
    ABC obj1;
    XYZ obj2;
    obj1.getx();
    obj2.gety();
    greaterr(obj1,obj2);
    return 0;
}

OBJECT AS FUNCTION ARGUMENT

#include<iostream>
using namespace std;
class sample
{
    int minute,hour, second;
public:
    void getdata()
    {
        cout<<"ENTER TIME IN MINUTE"<<endl;
        cin>>minute;
    }
    void display(sample s1, sample s2)
    {
        minute=s1.minute+s2.minute;
        hour=minute/60;
        minute=minute%60;
        cout<<"total duration is "<<hour<<" hour "<<minute<<" minute. "<<endl;
    }
};
int main()
{
    sample s1,s2,s3;
    s1.getdata();
    s2.getdata();
    s3.display(s1,s2);
return 0;
}

STATIC DATA MEMBER AND STATIC MEMBER FUNCTION

#include<iostream>
using namespace std;
class sample
{
    char name[20];
    int age;
    static int section;
public:
    void getdata()
    {
        cout<<"ENTER NAME AND AGE"<<endl;
        cin>>name>>age;
    }
    static void getdata1()
    {
        cout<<"Enter section"<<endl;
        cin>>section;
    }
    void display()
    {
        cout<<"name= "<<name<<endl;
        cout<<"age= "<<age<<endl;
    }
    static void display1()
    {
    cout<<"section= "<<section<<endl;
    }

};
int sample :: section;
int main()
{
    sample s1,s2;
    s1.getdata();
    s2.getdata();
    sample :: getdata1();
s1.display();
sample :: display1();
s2.display();
sample :: display1();
    return 0;
}

TOWER OF HANOI USING RECURSION

#include<iostream>
using namespace std;
int tower(int, char,char , char);
int main()
{
    int num;
cout<<"ENTER NO OF DISK"<<endl;
cin>>num;
tower(num,'A','B','c');
}
int tower(int num, char beg, char aux, char End)
{
    if(num>0)
    {
        tower(num-1,beg,End,aux);
        cout<<beg<<" -> "<<End<<endl;
        tower(num-1,aux,beg,End);
    }
    return 0;
}

FACTORIAL USING RECURSION

#include<iostream>
using namespace std;
int fact(int);
int main()
{
    int num;
    cout<<"ENTER NUMBER"<<endl;
    cin>>num;
    cout<<"Factorial is "<<fact(num)<<endl;
    return 0;
}
int fact(int num)
{
    if(num==1 || num==0)
    {
        return 1;
    }
    else
    {
        return num*fact(num-1);
    }
}

FUNCTION OVERLOADING

#include<iostream>
using namespace std;
int volume(int);
int volume(int, int , int);
int volume(int, int);
int main()
{
    int s,l,b,h1,h2,r;
    cout<<"Enter side of cube"<<endl;
    cin>>s;
    volume(s);
    cout<<"Enter radius and height of cylinder"<<endl;
    cin>>r>>h1;
    volume(r,h1);
    cout<<"enter length, breadth and height of cuboid"<<endl;
    cin>>l>>b>>h2;
    volume(l,b,h2);
    return 0;
}
int volume(int s)
{
int result1=s*s*s;
cout<<"volume of cube is "<<result1<<endl;
return 0;
}
int volume(int r,int h1)
{
    int result2=3.14*r*r*h1;
    cout<<"Volume of cylinder is "<<result2<<endl;
    return 0;
}
int volume(int l, int b, int h2)
{
    int result3=l*b*h2;
    cout<<"volume of cuboid is "<<result3<<endl;
    return 0;
}

DEFAULT ARGUMENT

#include<iostream>
using namespace std;
int interest(int , int,int r=5);
int main()
{
    int p,t;
    cout<<"Enter principle and time "<<endl;
    cin>>p>>t;
    interest(p,t);
    return 0;
}
int interest(int p, int t, int r)
{
    int si=(p*t*r)/100;
    cout<<"Simple Interest is "<<si<<endl;
return 0;
}

INLINE FUNCTION

#include<iostream>
using namespace std;
inline int Square(int l)
{
    int s=l*l;
    return s;
}
inline int Cube(int l)
{
    int s1=l*l*l;
    return s1;
}
int main()
{
    int l;
    cout<<"Enter side"<<endl;
    cin>>l;
    cout<<"Square is "<<Square(l)<<endl;
    cout<<"Cube is "<<Cube(l)<<endl;
    return 0;
}

Wednesday, November 25, 2015

JQUERY PROGRAM TO CHANGE COLOR OF TEXT WHEN USER CLICK ON BUTTON

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("#id1").click(function()
{
$(".cl1").css("color","blue");
});
$("#id2").click(function()
{
$(".cl1").css("color","green");
});
$("#id3").click(function()
{
$(".cl1").css("color","red");
});
});
</script>
<body><p class="cl1">
<span style="border: 5px groove cyan"> Click on button to change my color</span>
</p><br>
<br>
<button id="id1">Blue</button>
<button id="id2">Green</button>
<button id="id3">Red</button>
</body>
</html>

Monday, November 23, 2015

JQUERY TO HIDE TEXT WHEN CLICK ON BUTTON AND TO SHOW WHEN DOUBLE CLICK ON BUTTON

<html>
<head>
<script src="jquery-2.1.4.min.js"></script>
<script>
$(document).ready(function()
{
$("#id1").click(function()
{
$(".class1").hide();
});
$("#id2").click(function()
{
$(".class2").hide();
});
$("#id3").click(function()
{
$(".class3").hide();
});
$("#id3").dblclick(function()
{
$(".class3").show();
});
$("#id2").dblclick(function()
{
$(".class2").show();
});
$("#id1").dblclick(function()
{
$(".class1").show();
});
});
</script>
</head>
<body>
<h1 class="class1">Click frist button to hide me</h1><br>
<h2 class="class2">click second button to hide me</h2><br>
<h3 class="class3">click third button to hide me</h3><br>
<button id="id1">First</button>
<button id="id2">Second</button>
<button id="id3">Third</button>
</body>
</html>

Sunday, November 22, 2015

MULTIPLE INHERITANCE

#include<iostream>
using namespace std;
class sample
{
    protected: int x;
    public: void getx()
    {
        cout<<"Enter value of x"<<endl;
        cin>>x;
    }
};
class sample1
{
protected:
    int y;
public:
    void gety()
    {
        cout<<"Enter value of y"<<endl;
        cin>>y;
    }
};
class sample2: public sample, public sample1
{
    int result;
public:
    void multiply()
    {
        result=x*y;
        cout<<"Result is: "<<result<<endl;
    }
};
int main()
{
    sample2 s;
    s.getx();
    s.gety();
    s.multiply();
    return 0;
}

Thursday, November 12, 2015

GREATEST AND SMALLEST ELEMENT IN 2D ARRAY

<html>
<head><title> Greatest and Smallest in 2d array</title>
</head>
<body>
<script language="javascript">
var i,j,greatest,smallest;
var num= new Array(2);
for(i=0;i<2;i++)
{
num[i]=new Array(3);
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
num[i][j]=parseInt(prompt("Enter the element",0));
}
}
greatest=num[0][0];
smallest=num[0][0];
document.write("Number you have entered are:<br>");
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
document.write(num[i][j]+"<br>")
if(greatest<num[i][j])
{
greatest=num[i][j];
}
if(smallest>num[i][j])
{
smallest=num[i][j];
}
}
}
document.write("Greatest element is "+greatest);
document.write("<br>Smallest element is "+smallest);
</script>
</body>
</html>

Wednesday, November 4, 2015

JAVASCRIPT==COMPARE TWO NUMBER USING DIALOG BOX AND RETURN STATEMENT

<html>
<head>
<script language="javascript">
function compare(a,b)
{
if(a>b)
{
return a;
}
else
{
return b;
}
}
</script>
</head>
<body>
<script language="javascript">
var x=parseInt(prompt("Enter first value",0));
var y=parseInt(prompt("Enter second value",0));
alert("Greater is "+compare(x,y));
</script>
</body>
</html>

CALCULATE EXPONENT OF GIVEN NUMBER BY USING TEXT BOX

<html>
<head>
<script    language="javascript">
function calculate(a,b)
{
var i,c=1;
for(i=0;i<b;i++)
{
c*=a;
}
f1.t3.value=c;
}
</script>
<body>
<form name="f1">
<label>number</label><input type="text" name="t1" value="0"><br>
<label>expontional</label><input type="text" name="t2" value="0"><br>
<label>number</label><input type="text" name="t3" value="0"><br>
<input type="button" value="calculate"onclick="calculate(f1.t1.value,f1.t2.value)">
<input type="reset" value="clear">
</form>
</body>
</html>

JAVASCRIPT==SUM OF ELEMENT OF 2D ARRAY

<html>
<body>
<script language="javascript">
var a= new Array(2);
var sum=0;
for(var i=0;i<a.length;i++)
{
a[i] = new Array(3);

}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
a[i][j]=parseInt(prompt("Enter element",0));
}
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
sum+=a[i][j]
document.write(a[i][j]+"&nbsp;&nbsp;");
}
document.write("<br>");
}
document.write("Total sum of element is "+sum);
</script>
</body>
</html>