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;
}