MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Friday, September 27, 2013

dinamic initialization of constructor

#include <iostream>

using namespace std;
class student
{
    private:
    int year;
    int amount;
    float total;
    public:
    student(int a,int y,float r=.12);
    student(int a,int y,int d);
    void display();
};
 student::student(int a,int y,float r)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+total*r;
    }
}
 student::student(int a,int y,int d)
{
    amount=a;
    year=y;
    total=a;
    for(int i=1;i<=year;i++)
    {
        total=total+amount*((float)(d)/100);
        amount=total;
    }
}
void student::display()
{
    cout<<"The resultant value is "<<total<<endl;
}
int main()
{
    int a,b,c;
    float f;
    while(cin>>a>>b>>c)
    {
        student ob(a,b,c);
        ob.display();
        cin>>a>>b>>f;
        student ob1(a,b,f);
        ob1.display();
        cin>>a>>b;
        student ob2(a,b);
        ob2.display();
    }
    return 0;
}

using multple constructor of c++ program

#include <iostream>
using namespace std;
class student
{
    private:
    float a;
    float b;
    public:
    student()
    {

    }
    student(float x,float y)
    {
        a=x;
        b=y;
    }
    friend student sum(student,student);
    void display(student);
};
student sum(student c1,student c2)
{
    student c3;
    c3.a=c1.a+c2.a;
    c3.b=c1.b+c2.b;
    return (c3);
}
void student::display(student k)
{
    cout<<"The resultant is="<<k.a<<" + j"<<k.b<<endl;
}
int main()
{
    student ob2[1000],t;
    float x,y,d,z;
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
        cin>>x>>y;
        student ob(x,y);
        cin>>d>>z;
        student ob1(d,z);
        ob2[i]=sum(ob,ob1);
        }
        for(int i=0;i<n;i++)
        {
          t=ob2[i];
          ob2[i].display(t);
        }
    }
    return 0;
}

#include <iostream>
using namespace std;
class student
{
    private:
    float a;
    float b;
    public:
    student()
    {

    }
    student(float x,float y)
    {
        a=x;
        b=y;
    }
    friend student sum(student,student);
    void display(student);
};
student sum(student c1,student c2)
{
    student c3;
    c3.a=c1.a+c2.a;
    c3.b=c1.b+c2.b;
    return (c3);
}
void student::display(student k)
{
    cout<<"The resultant is="<<k.a<<" + j"<<k.b<<endl;
}
int main()
{
    student ob2[1000],t;
    float x,y,d,z;
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
        cin>>x>>y;
        student ob(x,y);
        cin>>d>>z;
        student ob1(d,z);
        ob2[i]=sum(ob,ob1);
        }
        for(int i=0;i<n;i++)
        {
          t=ob2[i];
          ob2[i].display(t);
        }
    }
    return 0;
}

Sunday, May 12, 2013

codeforces contest program

#include <iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<queue>
using namespace std;
class name
{
    int p;
    int q,m;
    int r,c;
    public:
    void member(int n);
};
void name::member(int n)
{
    c=0;
    for(int i=1;i<n;i++)
    {
        for(int j=i;j<n;j++)
        {
            r=i*i+j*j;
            p=int(sqrt(i*i+j*j));
            q=p*p;
            if(r>n*n)
            break;
            if(r==q)
            {
            c=c+1;
            }
        }
    }
    cout<<c<<endl;
}
int main()
{
    int a;
    name ob;
    while(cin>>a)
    {
        ob.member(a);
    }
    return 0;
}

Thursday, May 2, 2013

sort using class of c++ program

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class node
{
    public:
    string name;
    int age;
    int roll;
    float marks;
};
bool com(const node as,const node k)
{
    if(as.name<k.name)
    return true;
    if((as.name<k.name)||(as.age<k.age))
    return true;
    if(as.marks>k.marks)
    return true;
}
int main()
{
    int n;
    string s;
    int a;
    int r;
    double m;
    node g;
    while(cin>>n)
    {
        vector<node>v;
        for(int i=0;i<n;i++)
        {
        cin>>s;
        cin>>a;
        cin>>r;
        cin>>m;
        g={s,a,r,m};
        v.push_back(g);
        }
    sort(v.begin(),v.end(),com);
    for(int i=0;i<v.size();i++)
    cout<<v[i].name<<" "<<v[i].age<<" "<<v[i].roll<<" "<<v[i].marks<<endl;
    }
    return 0;
}

Thursday, April 25, 2013

c++program using vector

#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
class name
{
 public:
 char a;
 int b;
};
bool com(const name g,const name t)
{
    if(g.a==t.a)
    if(g.b<t.b)
    return 1;
    else
    return 1;
}
int main()
{
    int n;
    char a;
    int b;
    name ob;
    while(cin>>n)
    {
        vector<name>v;
        for(int i=0;i<n;i++)
        {
            cin>>a>>b;
            ob={a,b};
            v.push_back(ob);
        }
        vector<name>s(v);
        sort(s.begin(),s.end(),com);
        for(int i=0;i<s.size();i++)
        cout<<s[i].a<<" "<<s[i].b<<endl;
    }
    return 0;
}

Tuesday, April 16, 2013

using stack of c/c++ program

#include <iostream>
#include<stack>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    int a;
    int k;
    while(cin>>n)
    {
        stack<int>st;
        for(int i=0;i<n;i++)
        {
            cin>>a;
            st.push(a);
        }
        stack<int>::size_type t;
        t=st.size();
        for(int i=0;i<t;i++)
        {
            k=st.top();
            cout<<k<<" ";
            st.pop();
        }
        cout<<endl;
    }
    cout << "Hello world!" << endl;
    return 0;
}

Saturday, April 6, 2013

preorder tree coding of c program

#include<stdio.h>
#define max 10000
long a[max],n,i,j,large,l,r;
void swap(long j,long large)
{

    int p;
    p=a[j];
    a[j]=a[large];
    a[large]=p;
}
void show(long n)
{
for(i=1;i<=n;i++)
scanf("%ld",&a[i]);
for(j=n/2;j>=1;j--)
{
 function(j);
}
for(j=1;j<=n;j++)
printf("%ld ",a[j]);
printf("\n");
}
void function(long j)
{
    l=2*j;
    r=l+1;
    if(l<=n&&a[j]<a[l])
    large=l;
    else
    large=j;
    if(r<=n&&a[j]<a[r])
    large=r;
    swap(j,large);
    if(j!=large)
    {
    function(large);
    }

}
int main()
{
    while(scanf("%ld",&n)!=EOF)
    {
        show(n);
    }
    return 0;
}

Friday, April 5, 2013

maximum value of given a seires

#include<stdio.h>
#define min -1000000
#define maxi 1000
int a[maxi],ms;
void maximum(int p,int r)
{
 int i,s,max;
 int left,right,t,c;
 int sum=0;
 int k;
 max=min;
 for(i=r;i>=p;i--)
 {
     sum=sum+a[i];
     if(sum>max)
     {
     max=sum;
     left=r-i;
     right=i;
     }
 }
 s=r-p;
 if(s==1)
 {
     left=p;
     right=r;
 }
 else
 {
 right=left+1;
 left=i+1;
 }
 k=max;
 if(k>ms)
 {
   ms=k;
   t=left;
   c=right;
   left=t;
   right=c;
 }
}
int function(int p,int r)
{
    int q;
    q=(p+r)/2;
    maximum(p,q);
    maximum(q+1,r);
    maximum(p,r);
   printf("The maximum value is %d\nThe lower boundery is %d \nThe upper boundery is %d\n",ms,p,r);
}
int main()
{
 int n;
 int i;
 while(scanf("%d",&n)!=EOF)
 {
     for(i=1;i<=n;i++)
     scanf("%d",&a[i]);
     ms=0;
     function(1,n);
 }
 return 0;
}

Wednesday, April 3, 2013

uva solve problem 11858

#include<stdio.h>
#define max 10000000000
long s,L[1000002],R[1000002],a[1000002];

void merge(long p,long q,long r)
{
    long n1,n2;
    long i,j,k;
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=max;
    R[n2+1]=max;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];
            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1-i+1;
            j++;
        }
    }

}

void ms(long p,long  r)
{
    long  q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(p,q);
        ms(q+1,r);
        merge(p,q,r);
    }
}
int main()
{
long n;
long i;
while(scanf("%d",&n)!=EOF)
{
    for(i=1;i<=n;i++)
    scanf("%ld",&a[i]);
    i=1;
    s=0;
    ms(i,n);
    printf("%ld\n",s);

}
return 0;
}

uva solve problem 10810

#include<stdio.h>
#define max 10000000000
long s,L[500002],R[500002],a[500002];

void merge(long p,long q,long r)
{
    long n1,n2;
    long i,j,k;
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=max;
    R[n2+1]=max;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];
            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1-i+1;
            j++;
        }
    }

}

void ms(long p,long  r)
{
    long  q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(p,q);
        ms(q+1,r);
        merge(p,q,r);
    }
}
int main()
{
long n;
long i;
while(scanf("%d",&n)!=EOF)
{
    if(n==0)
    break;
    for(i=1;i<=n;i++)
    scanf("%ld",&a[i]);
    i=1;
    s=0;
    ms(i,n);
    printf("%ld\n",s);

}
return 0;
}

Tuesday, April 2, 2013

merge sort of c program

#include<stdio.h>
long long int s;
void ms(int a[],int p,int r)
{
    int q;
    if(p<r)
    {
        q=(p+r)/2;
        ms(a,p,q);
        ms(a,q+1,r);
        merge(a,p,q,r);
    }
}
void merge(int a[],int p,int q,int r)
{
    int n1,n2;
    int i,j,k;
    int L[1000],R[1000];
    n1=q-p+1;
    n2=r-q;
    for(i=1;i<=n1;i++)
    L[i]=a[p+i-1];
    for(j=1;j<=n2;j++)
    R[j]=a[q+j];
    i=1;
    j=1;
    L[n1+1]=12542568;
    R[n2+1]=3655423654;
    for(k=p;k<=r;k++)
    {
        if(L[i]<=R[j])
        {
            a[k]=L[i];

            i++;
        }
        else
        {
            a[k]=R[j];
            s+=n1+1-i;
            j++;
        }
    }
}
int main()
{
int n;
int i,a[100];
while(scanf("%d",&n)!=EOF)
{
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    i=1;
    s=0;
    ms(a,i,n);
    printf("%d\n",s);
}
return 0;
}

merge sort of c++

#include <iostream>
#define max 1000
using namespace std;
class name
{
 private:
 int q;
 public:
void merge(int b[],int p,int r);
};
void name::merge(int b[],int p,int r)
{
    if(p<r)
    {
    q=(p+r)/2;
    merge(b,p,q);
    merge(b,q+1,r);
    msort(b,p,q,r);
    }
}

}
void msort(int b[],int p,int q,int r)
{
    int n1,n2,s,v,j;
    int L[max];
    int R[max];
    n1=p-q+1;
    n2=r-q;
    for(int i=1;i<=n1;i++)
    L[i]=b[i+p-1];
    for(int j=1;j<=n2;j++)
    R[j]=b[q+j];
    s=1;
    v=1;
    for(int k=p;k<=r;k++)
    {
        if(L[s]<=R[v])
        {
         b[k]=L[s];
         s=s+1;
        }
        else
        {
            b[k]=R[v];
            v=v+1;
        }

    }
}
int main()
{
    name ob;
    int n,t,i;
    int b[max];
    t=1;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
        cin>>b[i];
        }
        ob.merge(b,t,n);
        for(i=1;i<=n;i++)
        cout<<b[i];


    }
    return 0;
}

merge sort of c++

#include <iostream>
#define max 1000
using namespace std;
class name
{
 private:
 int q;
 public:
void merge(int b[],int p,int r);
};
void name::merge(int b[],int p,int r)
{
    if(p<r)
    {
    q=(p+r)/2;
    merge(b,p,q);
    merge(b,q+1,r);
    msort(b,p,q,r);
    }
}

}
void msort(int b[],int p,int q,int r)
{
    int n1,n2,s,v,j;
    int L[max];
    int R[max];
    n1=p-q+1;
    n2=r-q;
    for(int i=1;i<=n1;i++)
    L[i]=b[i+p-1];
    for(int j=1;j<=n2;j++)
    R[j]=b[q+j];
    s=1;
    v=1;
    for(int k=p;k<=r;k++)
    {
        if(L[s]<=R[v])
        {
         b[k]=L[s];
         s=s+1;
        }
        else
        {
            b[k]=R[v];
            v=v+1;
        }

    }
}
int main()
{
    name ob;
    int n,t,i;
    int b[max];
    t=1;
    while(cin>>n)
    {
        for(i=1;i<=n;i++)
        {
        cin>>b[i];
        }
        ob.merge(b,t,n);
        for(i=1;i<=n;i++)
        cout<<b[i];


    }
    return 0;
}

Saturday, March 30, 2013

recersive function

#include <iostream>
using namespace std;
class name
{
  private:
  int p;
  public:
  int sum(int n);
};
int name::sum(int n)
{
    if(n==0)
    return 0;
    else
    return (sum(n-1)+n);
}
int main()
{
    name ob;
    int a;
    while(cin>>a)
    {
    cout<<ob.sum(a)<<endl;
    }
    return 0;
}

Friday, March 29, 2013

code jamer contest problem

#include<iostream>
#include<cstring>
#define max 1000
using namespace std;
int main()
{
    char a[max],b[max];
    int c,la,n,t;
        cin.get(a,max);
        la=strlen(a);
        c=0;
        t=0;
        for(int j=la-1;j>=0;j--)
        {
            if(a[j]==' ')
            {
                for(int k=j+1;k<la-t;k++)
                b[c++]=a[k];
                b[c++]=' ';
                t=c;
            }

        }
        for(int s=0;s<la;s++)
            {
                if(a[s]==' ')
                break;
                else
                b[c++]=a[s];
            }
        cout<<"Case #"<<": "<<b<<endl;
    return 0;
}

new item of c++ code

#include <iostream>
using namespace std;
class name
{
    private:
    char a[100];
    public:
    void member(char b[])
    {
    cout<<b;
    }
};
int main()
{
    name ob;
    char a[100]="computerscience&engineering";
    ob.member(&a[8]);
    return 0;
}

Thursday, March 28, 2013

www.use of friend class

#include <iostream>
#include<cstring>
#define max 1000
using namespace std;
class name1
{
    private:
    char a[max];
    char b[max];
    int la,lc;
    public:
    void member()
    {
        cin.get(a,max);
        la=strlen(a);
        lc=la;
        for(int i=0;i<la;i++)
        b[i]=a[i];
    }
    friend class name2;
};
class name2
{
    private:
    char c[max];
    int lb;
    public:
    void member1(name1&la)
    {
        lb=la.lc;
        for(int j=0;j<lb;j++)
        {
        c[j]=la.b[j];
        cout<<c[j];
        }
        cout<<"\n";
    }
    friend class name3;

};
class name3
{
    private:
    char string[max];
    int ld;
    public:
    void member2(name2&lk)
    {
    ld=lk.lb;
    for(int k=ld-1;k>=0;k--)
    {
    string[k]=lk.c[k];
    cout<<string[k];
    }
    cout<<endl;
    }
};

int main()
{
    name1 ob;
    name2 ot;
    name3 om;
    ob.member();
    ot.member1(ob);
    om.member2(ot);
    return 0;
}

Wednesday, March 27, 2013

discribtion of friend class

#include <iostream>
#include<cstring>
#define max 1000
using namespace std;
class name1
{
    private:
    char a[max],c[max];
    int la,d;
    public:
    void member()
    {
        cin.get(a,max);
        la=strlen(a);
        d=la;
        for(int j=0;j<d;j++)
        c[j]=a[j];
    }
 friend class name2;
};
class name2
{
    private:
    char b[max];
    int c;
    public:
    void member1(name1&la)
    {
    c=la.d;
    for(int i=0;i<c;i++)
    {
    b[i]=la.c[i];
    cout<<b[i];
    }
    }
};
int main()
{
    name1 ob;
    name2 ot;
    ob.member();
    ot.member1(ob);
    return 0;
}

useing friend class

#include <iostream>
using namespace std;
class name1
{
    private:
    int a;
    public:
    void function()
    {
        a=0;
    }
    void get(int x)
    {
    a=x;
    }
    void output()
    {
    cout<<a<<endl;
    }
    friend class name2;

};
class name2
{
    private:
    int b;
    public:
    void function1()
    {
    b=0;
    }
    void get1(name1&x)
    {
    b=x.a+25;
    }
    void output1()
    {
    cout<<b<<endl;
    }
};
int main()
{
    int c;
    name1 ob;
    name2 ot;
    while(cin>>c)
    {
        ob.get(c);
        ot.get1(ob);
        ob.output();
        ot.output1();
    }
    return 0;
}

Saturday, March 23, 2013

using char of insertion short

#include <iostream>
#define max 1000
using namespace std;
class name
{
    private:
    int n,tm,p;
    char a[max];
    char b[max];
    public:
    void member(int k);
    void output();
};
void name::member(int k)
{
        n=k;
        for(int i=0;i<n;i++)
        cin>>a[i];
        b[0]=a[0];
        for(int j=1;j<n;j++)
        {
          tm=a[j]-48;
           p=j-1;
          while((tm<(b[p]-48))&&(p>=0))
          {
            b[p+1]=b[p];
            p=p-1;
           }
           b[p+1]=tm+48;
        }

}
void name::output()
{
    for(int i=0;i<n;i++)
    cout<<b[i]<<" ";
    cout<<endl;
}
int main()
{
    int m;
    name ob;
    while(cin>>m)
    {
    ob.member(m);
    ob.output();
    }
    return 0;
}