20.7.13

C++ : Inheritance with BASE & DERIVED Classes

Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time.
The programmer can designate that the new class should inherit the members of an existing class. This existing class is called the base class, and the new class is referred to as the derived class.
The idea of inheritance implements the is a relationship. For example, mammal IS-A animal, dog IS-A mammal hence dog IS-A animal as well and so on.

Base & Derived Classes:

A class can be derived from more than one classes, which means it can inherit data and functions from multiple base classes. To define a derived class, we use a class derivation list to specify the base class(es). A class derivation list names one or more base classes and has the form:
class derived-class: access-specifier base-class
Where access-specifier is one of public, protected, or private, and base-class is the name of a previously defined class. If the access-specifier is not used, then it is private by default.
Consider a base class Shape and its derived class Rectangle as follows:
#include <iostream>
 
using namespace std;

// Base class
class Shape 
{
   public:
      void setWidth(int w)
      {
         width = w;
      }
      void setHeight(int h)
      {
         height = h;
      }
   protected:
      int width;
      int height;
};

// Derived class
class Rectangle: public Shape
{
   public:
      int getArea()
      { 
         return (width * height); 
      }
};

int main(void)
{
   Rectangle Rect;
 
   Rect.setWidth(5);
   Rect.setHeight(7);

   // Print the area of the object.
   cout << "Total area: " << Rect.getArea() << endl;

   return 0;
}
When the above code is compiled and executed, it produces following result:
Total area: 35


Multiple Inheritances:

A C++ class can inherit members from more than one class and here is the extended syntax:
class derived-class: access baseA, access baseB....
Where access is one of public, protected, or private and would be given for every base class and they will be separated by comma as shown above. Let us try the following example:
#include <iostream>
 
using namespace std;

// Base class Shape
class Shape 
{
   public:
      void setWidth(int w)
      {
         width = w;
      }
      void setHeight(int h)
      {
         height = h;
      }
   protected:
      int width;
      int height;
};

// Base class PaintCost
class PaintCost 
{
   public:
      int getCost(int area)
      {
         return area * 70;
      }
};

// Derived class
class Rectangle: public Shape, public PaintCost
{
   public:
      int getArea()
      { 
         return (width * height); 
      }
};

int main(void)
{
   Rectangle Rect;
   int area;
 
   Rect.setWidth(5);
   Rect.setHeight(7);

   area = Rect.getArea();
   
   // Print the area of the object.
   cout << "Total area: " << Rect.getArea() << endl;

   // Print the total cost of painting
   cout << "Total paint cost: $" << Rect.getCost(area) << endl;

   return 0;
}
When the above code is compiled and executed, it produces following result:
Total area: 35
Total paint cost: $2450
When deriving a class from a base class, the base class may be inherited through public, protected orprivate inheritance. The type of inheritance is specified by the access-specifier as explained above.
We hardly use protected or private inheritance but public inheritance is commonly used. While using different type of inheritance, following rules are applied:
  • Public Inheritance: When deriving a class from a public base class, public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class. A base class's private members are never accessible directly from a derived class, but can be accessed through calls to the publicand protected members of the base class.
  • Protected Inheritance: When deriving from a protected base class, public and protectedmembers of the base class become protected members of the derived class.
  • Private Inheritance: When deriving from a private base class, public and protected members of the base class become private members of the derived class.
Exercise-1: Write a c++ program using Inheritance to check whether the given integer number is palindrome or not ?
Exercise-2: Given a range [a,b], you are to  find the summation of all the odd integers in this range. For example,the summation of all the odd integers in the range [3,9] is 3 + 5 + 7 + 9 = 24. View Details:
Exercise-3: Mohammad has recently visited Switzerland. As he loves his friends very much, he decided to buy some chocolate for them, but as this fine chocolate is very ex-pensive (You know Mohammad is a little BIT stingy!), he could only afford buying one chocolate, albeit a very big one (part of it can be seen in  figure  below) for all of them as a souvenir. Now, he wants to give each of his friends exactly one part of this chocolate and as he believes all human beings are equal (!), he wants to split it into equal parts.The chocolate is an M x N rectangle constructed from M x N unit-sized squares. You can assume that Mohammad has also M x N friends waiting to receive their piece of chocolate. To split the chocolate, Mohammad can cut it in vertical or horizontal direction (through the lines that separate the squares). Then, he should do the same with each part separately until he
reaches M x N unit size pieces of chocolate. Unfortunately, because he is a little lazy, he wants to use the minimum number of cuts required to accomplish this task.Your goal is to tell him the minimum number of cuts needed to split all of the chocolate squares apart. View Details:

67 comments:

  1. using C++

    #include
    using namespace std;

    class Pelindrome
    {
    public:
    int userInput(int d);

    protected:
    int data;
    int temp;
    };

    int Pelindrome::userInput(int d)
    {
    data = temp = d;
    }

    class Func: public Pelindrome
    {
    public:
    int mod = 0, check = 0;

    int result(){
    while (temp != 0){
    mod = temp%10;
    check = (check*10 + mod);
    temp = temp/10;

    if (data == check)
    cout << data << " is Pelindrome type number --.\n";
    }

    if (check != data)
    cout << data << " is not Pelindrome type number --.";
    }
    };

    int main()
    {
    int userData;

    cout << "Enter your data that you want to check --:";
    cin >> userData;

    Func obj;
    obj.userInput(userData);
    obj.result();

    return 0;
    }

    ReplyDelete
  2. using c++
    cheek palindrome number
    mamun ur rashid
    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int n)
    {
    num=n;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int a,b=121,c=0;
    int palin()
    {
    b=num;
    while(b!=0)
    {
    a=b%10;
    c=c*10+a;
    b/=10;
    }
    }

    int check()
    {
    if(num==c)
    cout<<"Given number is palindrome number";
    else
    cout<<"Given number is not palindrome number"<<"\n";
    }
    };
    int main()
    {
    number ob;
    int t;
    //cout<<"Enter desire number : ";
    //cin>>t;
    ob.setresult(t);
    ob.palin();
    ob.check();
    }

    ReplyDelete
  3. using c++
    palindrome number
    mamun ur rashid
    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int n)
    {
    num=n;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int a,b=121,c=0;
    int palin()
    {
    b=num;
    while(b!=0)
    {
    a=b%10;
    c=c*10+a;
    b/=10;
    }
    }

    int check()
    {
    if(num==c)
    cout<<"Given number is palindrome number";
    else
    cout<<"Given number is not palindrome number"<<"\n";
    }
    };
    int main()
    {
    number ob;
    int t;
    cout<<"Enter desire number : ";
    cin>>t;
    ob.setresult(t);
    ob.palin();
    ob.check();
    }

    ReplyDelete
  4. #include
    using namespace std;

    class palindrome
    {
    public:
    int num1;
    int func()
    {
    cout<<"Enter your number for check: ";
    cin>>num1;
    num2=num3=num1;
    }
    protected:
    int num2;
    int num3;

    };

    class palin : public palindrome
    {
    public:
    int rony()
    {
    int sum=0, reminder=0;
    while(num2!=0)
    {
    reminder=num2%10;
    sum=(sum*10)+reminder;
    num2=num2/10;
    }
    if (num3==sum)
    cout<<"The palindrome number is: "<<sum;
    else
    cout<<"That is not a palindrome number";

    }

    };

    int main()
    {
    palin obj;
    obj.func();
    obj.rony();
    return 0;

    }

    id: 201510660

    ReplyDelete
  5. #include
    using namespace std;

    class palin
    {
    public:
    int i;
    int methord()
    {
    cout<<"Enter your number for check: ";
    cin>>i;
    j=k=i;
    }
    protected:
    int j;
    int k;

    };

    class child : public palin
    {
    public:
    int setu()
    {
    int x=0, y=0;
    while(j!=0)
    {
    y=j%10;
    x=(x*10)+y;
    j=j/10;
    }
    if (k==x)
    cout<<"The palindrome number is: "<<x;
    else
    cout<<"That is not a palindrome number";

    }

    };

    int main()
    {
    child obj;
    obj.methord();
    obj.setu();
    return 0;

    }

    id :201510992

    ReplyDelete
  6. problem 3
    using c++


    #include
    using namespace std;

    int func(int row, int column)
    {
    int result;
    result = (row-1) + (column-1);
    return result;
    }
    int main()
    {
    int a, b;

    cout << "Enter how many row in your chocolate --: ";
    cin >> a;
    cout << "Enter how many column in your chocolate --: ";
    cin >> b;

    cout << "You need minimum number of cuts is -- " << func(a, b) << "\n";
    return 0;
    }

    ReplyDelete
    Replies
    1. in Question no. 3..shrotly what we should show at least ?..
      is that minimum pice or how many pice need for how many people

      Delete
    2. In Question 3 we need to find out the minimum cuts of, the fact is that we need to keep all the part in square .....

      Delete
  7. problem 2
    using C++

    #include
    using namespace std;

    int func(int firstNumer, int lastNumber)
    {
    int result = 0, i;
    for (i = firstNumer; i <= lastNumber; i++){
    if (i%2 != 0)
    result += i;
    }
    return result;
    }

    int main()
    {
    int a, b;

    cout << "Enter your first number -- : ";
    cin >> a;
    cout << "Enter your last number --: ";
    cin >> b;

    cout << "The summation of all the odd integers in the range --: " << func(a, b);
    return 0;
    }

    ReplyDelete
  8. #include
    using namespace std;

    class checkpalindrome
    {
    public:
    int n;
    int function()
    {
    cout<<"Enter number for check: ";
    cin>>n;
    n2=n3=n;
    }
    protected:
    int n2;
    int n3;

    };

    class sum : public checkpalindrome
    {
    public:
    int name()
    {
    int s=0, r=0;
    while(n2!=0)
    {
    r=n2%10;
    s=(s*10)+r;
    n2=n2/10;
    }
    if (n3==s)
    cout<<"Given number is palindrome number: "<<s;
    else
    cout<<"Given number is not palindrome number";

    }

    };

    int main()
    {
    sum obj;
    obj.function();
    obj.name();
    return 0;

    }

    Maisha Fahmida
    Batch:48th
    ID:201511018

    ReplyDelete
  9. #include
    using namespace std;

    class checkpalindrome
    {
    public:
    int n;
    int function()
    {
    cout<<"Enter number for check: ";
    cin>>n;
    n2=n3=n;
    }
    protected:
    int n2;
    int n3;

    };

    class sum : public checkpalindrome
    {
    public:
    int name()
    {
    int s=0, r=0;
    while(n2!=0)
    {
    r=n2%10;
    s=(s*10)+r;
    n2=n2/10;
    }
    if (n3==s)
    cout<<"Given number is palindrome number: "<<s;
    else
    cout<<"Given number is not palindrome number";

    }

    };

    int main()
    {
    sum obj;
    obj.function();
    obj.name();
    return 0;

    }

    Maisha Fahmida
    Batch:48th
    ID:201511018

    ReplyDelete
  10. #include
    using namespace std;

    class checkpalindrome
    {
    public:
    int n;
    int function()
    {
    cout<<"Enter number for check: ";
    cin>>n;
    n2=n3=n;
    }
    protected:
    int n2;
    int n3;

    };

    class sum : public checkpalindrome
    {
    public:
    int name()
    {
    int s=0, r=0;
    while(n2!=0)
    {
    r=n2%10;
    s=(s*10)+r;
    n2=n2/10;
    }
    if (n3==s)
    cout<<"Given number is palindrome number: "<<s;
    else
    cout<<"Given number is not palindrome number";

    }

    };

    int main()
    {
    sum obj;
    obj.function();
    obj.name();
    return 0;

    }

    Maisha Fahmida
    Batch:48th
    ID:201511018

    ReplyDelete
  11. #include
    using namespace std;

    class palindrome
    {
    public:
    int n;
    int methord()
    {
    cout <<"Enter the number : " << endl;
    cin>>n;
    num=n;
    }
    protected:
    int num;
    };
    class child:public palindrome
    {
    public:
    int palin()
    { int a=num,b=num;
    // cout<<"Num" <<num ;
    int x=0, y=0;
    while(b!=0)
    {
    y=b%10;
    x=(x*10)+y;
    b=b/10;
    }
    if (num==x)
    cout<<"Palindrome number: "<<x;
    else
    cout<<"Not palindrome number";

    }

    };

    int main()
    {
    child obj;
    obj.methord();
    obj.palin();
    return 0;

    }

    ID:201430807

    ReplyDelete
  12. Exercise 01:Palindrome With inheritance.

    #include
    using namespace std;
    class pal
    {
    protected:
    int sum,b,r=0,i;
    public:
    void num(int a)
    {
    sum=a;
    }
    };
    class res: public pal
    {
    public:
    int result()
    {
    int c=sum;
    for(i=sum; sum!=0; i++)
    //while(a!=0)

    {
    b=sum%10;
    sum=sum/10;
    r=r*10+b;
    }
    return r;
    }
    };
    int main()
    {
    int a;
    cout<<"Input number: ";
    cin>>a;
    res appel;
    appel.num(a);

    cout<<endl<<appel.result()<<" ";
    if(a==appel.result())
    cout<<"This is Palindrome Number"<<endl;
    else
    cout<<"Not palindrome Number"<<endl;

    }

    ReplyDelete
  13. using c++
    Mamun ur Rashid
    batch:48th
    problem no:2 by using inheritance

    #include
    using namespace std;
    class summesion
    {
    public:

    int setFirstnum(int a)
    {
    firstnum =a;
    }
    int setLastnum(int b)
    {
    lastnum =b;
    }
    protected:
    int firstnum;
    int lastnum;

    };
    class odd:public summesion
    {
    public:
    int getResult(int first ,int last)
    {
    int result =0,i;
    for(i=first;i<=last;i++){
    if(i%2==0)
    result=result+i;
    }
    return result;
    }
    };
    int main()
    {
    odd sum;
    int c,d;
    cout<<"Enter first number :";
    cin>>c;
    cout<<"Enter last number :";
    cin>>d;
    cout<<"The summesion is :"<<sum.getResult(c,d)<<"\n";

    }

    ReplyDelete
  14. Exercise 02:Range Sum with inheritance...


    #include
    using namespace std;
    class sum
    {
    protected:
    int s,e,sum=0;
    public:
    void get(int a,int b)
    {
    s=a;
    e=b;
    }
    };
    class range:public sum
    {
    public:
    int result()
    {
    cout<>a;
    cout<<"Input Ending Value: ";
    cin>>b;
    range appel;
    appel.get(a,b);
    cout<<endl<<endl<<"Sum of Given Odd Number range: "<<appel.result()<<endl;
    }

    ReplyDelete
  15. Exercise 03: Pice of chocolate with inheritance..


    #include
    using namespace std;
    class chocolate
    {
    public:
    void get(int row,int col)
    {
    r=row;
    c=col;
    }
    protected:
    int r,c,s;

    };
    class res:public chocolate
    {
    public:
    int result()
    {
    s=(r*c)-1;
    return (s);
    }
    };
    int main()
    {
    int a,b;
    cin>>a;
    cin>>b;
    res appel;
    appel.get(a,b);
    cout<<endl<<appel.result()<<endl;
    }

    ReplyDelete
  16. problem 1 using function:

    #include
    using namespace std;

    void check_palindrome(int x)
    {
    int rev=0,remainder;
    int temp=x;

    while(temp!=0)
    {
    remainder=temp%10;
    rev=rev*10+remainder;
    temp/=10;
    }

    if(rev==x)
    cout<>num1;
    cout<<endl;

    check_palindrome(num1);
    }

    ReplyDelete
  17. problem 1 using constructor:

    #include
    using namespace std;

    class palindrome
    {
    public:
    int num1;
    palindrome();
    ~palindrome();
    void show();
    };

    palindrome::palindrome()
    {
    cout<<"Enter a number: ";
    cin>>num1;
    cout<<endl;
    }

    palindrome::~palindrome()
    {
    cout<<"Destructing"<<endl;
    }

    void palindrome::show()
    {
    int rev=0,remainder,temp;
    temp=num1;

    while(temp!=0)
    {
    remainder=temp%10;
    rev=rev*10+remainder;
    temp/=10;
    }

    if(rev==num1)
    cout<<num1<<" is a palindrome."<<endl<<endl;
    else
    cout<<num1<<" isn't a palindrome."<<endl<<endl;
    }

    int main()
    {
    palindrome ob1,ob2;
    ob1.show();
    ob2.show();
    return 0;
    }

    ReplyDelete
  18. proble 1 using INHERITENCE:

    #include
    using namespace std;

    class palindrome
    {
    public:
    void get_num(int n);
    protected:
    int num, temp;
    };

    void palindrome::get_num(int n)
    {
    num=temp=n;
    }

    class result : public palindrome
    {
    public:
    int rev=0,remainder;
    int do_check();
    };
    int result::do_check()
    {
    while(temp!=0)
    {
    remainder=temp%10;
    rev=rev*10+remainder;
    temp/=10;
    }

    if(rev==num)
    cout<>num1;

    result ob1,ob2;

    ob1.get_num(num1);
    ob1.do_check();

    cout<<"Enter another number: ";
    cin>>num2;

    ob2.get_num(num2);
    ob2.do_check();
    }

    ReplyDelete
  19. problem 2 using function:

    #include
    using namespace std;

    int sum=0;

    int sum_of_odd(int x, int y)
    {
    int i;
    for(i=x; i<=y; i++){
    if(i%2!=0)
    sum=sum+i;
    }
    return sum;
    }
    main()
    {
    int period,j,num1,num2;

    cout<<"Number of testcase: ";
    cin>>period;

    for(j=1; j<=period; j++){

    cout<>num1>>num2;

    sum_of_odd(num1,num2);

    cout<<endl<<"Case "<<j<<":"<<" "<<sum;

    sum=0;

    }
    }

    ReplyDelete
  20. #include
    using namespace std;

    class Palindrom
    {
    public:
    int n;
    void get_number()
    {
    cout<<"Enter an integer: ";
    cin>>n;
    number=n;
    }
    protected:
    int number;
    };

    class Check: public Palindrom
    {
    public:
    void check_function()
    {
    int reverse=0, rem,temp;
    temp=n;
    while(temp!=0)
    {
    rem=temp%10;
    reverse=reverse*10+rem;
    temp/=10;
    }
    if(reverse==n)
    cout<<n<<" is a palindrome Number."<<endl;
    else
    cout<<n<<"is not a palindrome number."<<endl;


    }
    };
    int main()
    {

    Check chk;
    chk.get_number();
    chk.check_function();

    return 0;
    }

    ReplyDelete
  21. #include
    using namespace std;

    class OddInteger
    {
    public:
    int L_value,U_value;
    void Get_range()
    {
    cout<<"Enter 2 Integer value for range(Lower and Upper) ";
    cin>>L_value>>U_value;
    Lower=L_value;
    Upper=U_value;
    }
    protected:
    int Lower,Upper;
    };

    class OddIntegerSummation: public OddInteger
    {
    public:
    void Odd_int_sum()
    {
    int L_value=Lower,U_value=Upper,i,sum=0;
    for(i=L_value; i<=U_value; i++)
    {
    if(i%2!=0)
    {
    sum=sum+i;
    }
    }

    cout<<"Summation of Odd integers is: "<<sum;
    }
    };
    int main()
    {
    OddIntegerSummation ois;
    ois.Get_range();
    ois.Odd_int_sum();
    }

    ReplyDelete
  22. #include
    using namespace std;

    int main()
    {
    int a,b,i,sum=0;
    cout<<"Enter the first limit: ";
    cin>>a;
    cout<<"Enter the last limit: ";
    cin>>b;
    for(i=a;i<=b;i++){
    if (i%2!=0)
    sum += i;
    }
    cout<<"The odd number is: "<<sum;
    return 0;

    }

    id:201510660

    ReplyDelete
  23. Example-01


    #include
    using namespace std;
    class pelindrome
    {
    public:
    int getnum1(int n)
    {
    num1=n;
    i=num1;
    }
    protected:
    int num1,i,remain=0, rev=0;
    };
    class process:public pelindrome
    {
    public:
    int cheak()
    {
    while(num1!=0)
    {
    remain=num1%10;
    rev=rev*10+remain;
    num1=num1/10;
    }
    cout<<"Revurse number is: "<>x;
    cout<<endl;
    pro.getnum1(x);
    pro.compare();
    return 0;
    }

    ReplyDelete
  24. Example-02


    #include
    using namespace std;
    class odd
    {
    public:
    int range(int n, int m)
    {
    first=n;
    last=m;
    }
    protected:
    int first,last;
    };
    class process:public odd
    {
    public:
    int sum()
    {
    int result=0;
    for(int i=first; i<=last; i++)
    if(i%2!=0)
    result+=i;
    return (result);
    }
    };
    int main()
    {
    process obj;
    int x,y;
    cout<<"Enter the range: ";
    cin>>x>>y;
    cout<<endl;
    obj.range(x,y);
    cout<<"RESULT: "<<obj.sum()<<endl;
    return 0;
    }

    ReplyDelete
  25. Example-03



    #include
    using namespace std;
    class chocolate
    {
    public:
    int get_row_col(int r, int c)
    {
    row=r;
    col=c;
    }
    protected:
    int row, col;
    };
    class process:public chocolate
    {
    public:
    int div()
    {
    if(row<=300 && row>=1)
    if(col<=300 && col>=1)
    int result=(row*col)-1;
    else{
    cout<<"Wrong input...."<>x>>y;
    cout<<endl;
    obj.get_row_col(x,y);
    cout<<"Result: "<<obj.div()<<endl;
    return 0;
    }

    ReplyDelete
  26. problem 2 using constructor:

    #include
    using namespace std;

    class summation
    {
    public:
    int period;
    summation();
    void show();
    };

    summation::summation()
    {
    cout<<"Number of testcase: ";
    cin>>period;
    }

    void summation::show()
    {
    int j,i,num1,num2, show, sum=0;

    for(j=1; j<=period; j++)
    {
    cout<>num1>>num2;

    for(i=num1; i<=num2; i++)
    {
    if(i%2!=0)
    sum=sum+i;
    }

    cout<<endl<<"Case "<<j<<":"<<" "<<sum<<endl;

    sum=0;
    }

    }
    int main()
    {
    summation ob;
    ob.show();
    return 0;
    }

    ReplyDelete
  27. #include
    using namespace std;

    class palindrome
    {
    public:
    int n;
    int methord()
    {
    cout << "Enter the number : " << endl;
    cin>>n;
    num=n;
    }
    protected:
    int num;
    };
    class child:public palindrome
    {
    public:


    int palin()
    { int a=num,b=num;
    // cout<<"num"<<num;
    int x=0, y=0;
    while(b!=0)
    {
    y=b%10;
    x=(x*10)+y;
    b=b/10;
    }
    if (num==x)
    cout<<"palindrome number: "<<x;
    else
    cout<<"not palindrome number";

    }

    };

    int main()
    {
    child obj;
    obj.methord();
    obj.palin();
    return 0;

    }

    Batch:47th
    ID:201430807

    ReplyDelete
  28. Problem 2
    Using C++

    #include
    using namespace std;
    class summesion
    {
    public:

    int setFirstnum(int a)
    {
    firstnum =a;
    }
    int setLastnum(int b)
    {
    lastnum =b;
    }
    protected:
    int firstnum;
    int lastnum;

    };
    class odd:public summesion
    {
    public:
    int getResult(int first ,int last)
    {
    int result =0,i;
    for(i=first;i<=last;i++){
    if(i%2==0)
    result=result+i;
    }
    return result;
    }
    };
    int main()
    {
    odd sum;
    int c,d;
    cout<<"Enter first number :";
    cin>>c;
    cout<<"Enter last number :";
    cin>>d;
    cout<<"The summesion is :"<<sum.getResult(c,d)<<"\n";

    }

    ReplyDelete
  29. #include
    using namespace std;

    class palin
    {
    public:
    int i;
    int methord()
    {
    cout<<"Enter your number for check: ";
    cin>>i;
    j=k=i;
    }
    protected:
    int j;
    int k;

    };

    class child : public palin
    {
    public:
    int sompa()
    {
    int x=0, y=0;
    while(j!=0)
    {
    y=j%10;
    x=(x*10)+y;
    j=j/10;
    }
    if (k==x)
    cout<<"The palindrome number is: "<<x;
    else
    cout<<"That is not a palindrome number";

    }

    };

    int main()
    {
    child obj;
    obj.methord();
    obj.sompa();
    return 0;

    }

    48TH BATCH
    ID:201510280

    ReplyDelete
  30. #include
    using namespace std;

    int rony(int row, int colum)
    {
    int result;
    result = ((row*colum)-1);
    return result;
    }
    int main()
    {
    int a, b;

    cout << "Enter how many row in your chocolate: ";
    cin >> a;
    cout << "Enter how many column in your chocolate: ";
    cin >> b;

    cout << "You need minimum number of cuts is: " << rony(a, b) << "\n";
    return 0;
    }

    id:201510660

    ReplyDelete
  31. #include
    using namespace std;

    int hamid(int row, int colum)
    {
    int result;
    result = ((row*colum)-1);
    return result;
    }
    int main()
    {
    int w, z;

    cout << "Enter how many row in your chocolate: ";
    cin >> w;
    cout << "Enter how many column in your chocolate: ";
    cin >> z;

    cout << "You need minimum number of cuts is: " << hamid(w, z) << "\n";
    return 0;
    }

    ID:201510511

    ReplyDelete
  32. #include
    using namespace std;

    int main()
    {
    int w,y,i,sum=0;
    cout<<"Enter the first limit: ";
    cin>>w;
    cout<<"Enter the last limit: ";
    cin>>y;
    for(i=w;i<=y;i++){
    if (i%2!=0)
    sum += i;
    }
    cout<<"The odd number is: "<<sum;
    return 0;

    }

    id:201510511

    ReplyDelete
  33. #include
    using namespace std;

    class palindrome
    {
    public:
    int i;
    int fun()
    {
    cout<<"Enter your number for check: ";
    cin>>i;
    j=k=i;
    }
    protected:
    int j;
    int k;

    };

    class son : public palindrome
    {
    public:
    int hamid()
    {
    int x=0, y=0;
    while(j!=0)
    {
    y=j%10;
    x=(x*10)+y;
    j=j/10;
    }
    if (k==x)
    cout<<"The palindrome number is: "<<x;
    else
    cout<<"That is not a palindrome number";

    }

    };

    int main()
    {
    son obj;
    obj.fun();
    obj.hamid();
    return 0;

    }

    id:201510511

    ReplyDelete
  34. #include
    using namespace std;

    int main()
    {
    int m,n,i,sum=0;
    cout<<"Enter the first limit: ";
    cin>>m;
    cout<<"Enter the last limit: ";
    cin>>n;
    for(i=m;i<=n;i++){
    if (i%2!=0)
    sum += i;
    }
    cout<<"The odd number is: "<<sum;
    return 0;

    }

    id:201510992

    ReplyDelete
  35. #include
    using namespace std;

    int setu(int row, int colum)
    {
    int result;
    result = ((row*colum)-1);
    return result;
    }
    int main()
    {
    int x, y;

    cout << "Enter how many row in your chocolate: ";
    cin >> x;
    cout << "Enter how many column in your chocolate: ";
    cin >> y;

    cout << "You need minimum number of cuts is: " << setu(x, y) << "\n";
    return 0;
    }

    id:201510992

    ReplyDelete
  36. TAMANNA RITU
    BATCH:48th
    ID:201510385

    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int r)
    {
    num=r;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int x,y=121,z=0;
    int palin()
    {
    y=num;
    while(y!=0)
    {
    x=y%10;
    z=z*10+x;
    y/=10;
    }
    }

    int check()
    {
    if(num==z)
    cout<<"YOUR NUMBER IS PALINDROME NUMBER. ";
    else
    cout<<"YOUR NUMBER IS NOT PALINDROME NUMBER."<<"\n";
    }
    };
    int main()
    {
    number ar;
    int a;
    cout<<"ENTER THE NUMBER : ";
    cin>>a;
    ar.setresult(a);
    ar.palin();
    ar.check();
    }

    ReplyDelete
  37. #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int r)
    {
    num=r;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int x,y=121,z=0;
    int palin()
    {
    y=num;
    while(y!=0)
    {
    x=y%10;
    z=z*10+x;
    y/=10;
    }
    }

    int check()
    {
    if(num==z)
    cout<<"YOUR NUMBER IS PALINDROME NUMBER. ";
    else
    cout<<"YOUR NUMBER IS NOT PALINDROME NUMBER."<<"\n";
    }
    };
    int main()
    {
    number ar;
    int a;
    cout<<"ENTER THE NUMBER : ";
    cin>>a;
    obj.setresult(a);
    obj.palin();
    obj.check();
    }

    TAMANNA RITU
    ID:201510385
    BATCH:48th


    ReplyDelete
  38. TAMANNA RITU
    BATCH:48th
    ID-201510385


    #include
    using namespace std;
    class oddnumb
    {
    public:
    int fun(int a, int b)
    {
    first=a;
    last=b;
    }
    protected:
    int first,last;
    };
    class process:public oddnumb
    {
    public:
    int sum()
    {
    int result=0;
    for(int i=first; i<=last; ++i)
    if(i%2!=0)
    result+=i;
    return (result);
    }
    };
    int main()
    {
    process obj;
    int a,b;
    cout<<"Enter your first number: ";
    cin>>a;
    cout<<"Enter your last number: ";
    cin>>b;
    cout<<endl;
    obj.fun(a,b);
    cout<<"YOUR RESULT: "<<obj.sum()<<endl;
    return 0;
    }

    ReplyDelete
  39. Problem-1
    Using C++
    Id:201510670

    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int n)
    {
    num=n;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int a,b=121,c=0;
    int palin()
    {
    b=num;
    while(b!=0)
    {
    a=b%10;
    c=c*10+a;
    b/=10;
    }
    }

    int check()
    {
    if(num==c)
    cout<<"Given number is palindrome number";
    else
    cout<<"Given number is not palindrome number"<<"\n";
    }
    };
    int main()
    {
    number ob;
    int t;
    //cout<<"Enter desire number : ";
    //cin>>t;
    ob.setresult(t);
    ob.palin();
    ob.check();
    }

    ReplyDelete
  40. TAMANNA RITU
    BATCH:48th
    ID:201510385


    #include

    using namespace std;

    class chocolate
    {
    public:
    int get(int r,int c)
    {
    a=r;
    b=c;
    }
    protected:
    int a,b,d;

    };
    class res:public chocolate
    {
    public:
    int result()
    {
    d=(a*b)-1;
    return (d);
    }
    };
    int main()
    {
    int n,m;
    cout<<"first valu: ";
    cin>>n;
    cout<<"last value: ";
    cin>>m;
    res obje;
    obje.get(n,m);
    cout<<endl<<obje.result()<<endl;
    }

    ReplyDelete
  41. problem 2 using inheritence:

    #include
    using namespace std;

    class userinput
    {
    public:
    int startrange;
    int endrange;

    userinput();

    };
    userinput::userinput(){
    cout<<"Enter two ranges: ";
    cin>>startrange>>endrange;
    }


    class summation : public userinput
    {
    public:

    int do_sum();
    };



    int summation::do_sum()
    {
    int i,sum=0;
    for(i=startrange; i<=endrange; i++)
    {
    if(i%2!=0)
    sum=sum+i;
    }
    return sum;
    }

    main()
    {
    int testcase,i;
    cout<<"How many testcase: ";
    cin>>testcase;
    for(i=1; i<=testcase; i++)
    {
    summation ob;
    cout<<"Summation "<<i<<" is: "<<ob.do_sum()<<endl;
    }
    }

    ReplyDelete
  42. problem 3 solved by c++

    #include
    using namespace std;
    int main()
    {
    int M,N;
    cout<<"Enter row and column: ";
    while(cin>>M>>N)
    {
    cout<<M*N-1<<endl;
    }
    }

    ReplyDelete
  43. problem 1;
    Id 201510469
    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int n)
    {
    num=n;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int a,b=121,c=0;
    int palin()
    {
    b=num;
    while(b!=0)
    {
    a=b%10;
    c=c*10+a;
    b/=10;
    }
    }

    int check()
    {
    if(num==c)
    cout<<"Given number is palindrome number";
    ecout<<"Given number is not palindrome number"<<"\n";
    }
    };
    int main()
    {
    number ob;
    int t;
    //cout<<"Enter desire number : ";
    //cin>>t;
    ob.setresult(t);
    ob.palin();
    ob.check();
    }

    ReplyDelete
  44. problem 1;
    Id 201510469
    #include
    using namespace std;
    class palindrome
    {
    public:
    void setresult(int n)
    {
    num=n;
    }
    protected:
    int num;
    };
    class number:public palindrome
    {
    public:
    int a,b=121,c=0;
    int palin()
    {
    b=num;
    while(b!=0)
    {
    a=b%10;
    c=c*10+a;
    b/=10;
    }
    }

    int check()
    {
    if(num==c)
    cout<<"Given number is palindrome number";
    ecout<<"Given number is not palindrome number"<<"\n";
    }
    };
    int main()
    {
    number ob;
    int t;
    //cout<<"Enter desire number : ";
    //cin>>t;
    ob.setresult(t);
    ob.palin();
    ob.check();
    }

    ReplyDelete
  45. #include
    using namespace std;

    int rony(int row, int colum)
    {
    int result;
    result = ((row*colum)-1);
    return result;
    }
    int main()
    {
    int a, b;

    cout << "Enter how many row in your chocolate: ";
    cin >> a;
    cout << "Enter how many column in your chocolate: ";
    cin >> b;

    cout << "You need minimum number of cuts is: " << rony(a, b) << "\n";
    return 0;
    }

    id:201510505

    ReplyDelete
  46. #include
    using namespace std;

    int rony(int row, int colum)
    {
    int result;
    result = ((row*colum)-1);
    return result;
    }
    int main()
    {
    int a, b;

    cout << "Enter how many row in your chocolate: ";
    cin >> a;
    cout << "Enter how many column in your chocolate: ";
    cin >> b;

    cout << "You need minimum number of cuts is: " << rony(a, b) << "\n";
    return 0;
    }

    id:201510505

    ReplyDelete
  47. febonacci series using inheritence:


    #include
    using namespace std;
    class febonacci
    {
    public:
    void take_value1(int x, int y,int z);
    //void take_value2(int y);
    // void take_value3(int z);
    protected:
    int a,b,n;
    };
    void febonacci::take_value1(int x,int y,int z)
    {
    a=x;
    b=y;
    n=z;
    }
    /*void febonacci::take_value2(int y)
    {
    b=y;
    }
    void febonacci::take_value3(int z)
    {
    n=z;
    }*/
    class main_work:public febonacci
    {
    public:
    int i,sum=0,summ=0;
    void show();
    };
    void main_work::show()
    {
    cout<>a>>b;
    cout<<"Enter a value as term: ";
    cin>>n;
    ob.take_value1(a,b,n);
    //ob.take_value2(b);
    //ob.take_value3(n);
    ob.show();
    }

    ReplyDelete
  48. febonacci series using constructor:

    #include
    using namespace std;

    class febonacci
    {
    public:
    int a,b,n,summ=0;
    febonacci();
    void show();
    void result();
    };
    febonacci::febonacci()
    {
    cout<<"Emter two Number as the first two value of the series: ";
    cin>>a>>b;
    cout<<"Enter a value as term: ";
    cin>>n;
    cout<<"seris: "<<a<<" "<<b;

    }
    void febonacci::show()
    {
    int i,sum=0;
    for(i=1; i<=n; i++)
    {
    sum=a+b;
    summ=summ+sum;
    cout<<" "<<sum;
    a=b;
    b=sum;
    }
    //cout<<endl<<"Summation is: "<<" "<<summ<<endl;
    }
    void febonacci::result()
    {
    cout<<endl<<"Summation is: "<<" "<<summ<<endl;
    }

    main()
    {
    febonacci ob;
    ob.show();
    ob.result();
    }



    ReplyDelete
  49. febonacci series using function:

    #include
    using namespace std;

    void febonacci(int a, int b, int n)
    {
    int i,sum=0,summ=0;;
    cout<<"seris: "<<a<<" "<<b;
    for(i=1; i<=n; i++)
    {
    sum=a+b;
    summ=summ+sum;
    cout<<" "<<sum;
    a=b;
    b=sum;
    }
    cout<<endl<<"Summation is: "<<" "<<summ<<endl;
    }

    main()
    {

    febonacci(1,1,5);
    }

    ReplyDelete
  50. PROBLEM-2

    #include
    using namespace std;

    int main()
    {
    int i;
    int a,b;
    long sum =0;

    cout << "Enter the first range: ";
    cin >> a;

    cout << "Enter the last range: ";
    cin >> b;

    for(i = a;i <= b; i++)
    if(i % 2 !=0)
    sum = sum + i;
    cout << "Sum of odd numbers in given range is: " << sum;
    return 0;

    }

    Maisha Fahmida
    Batch:48th
    ID:201511018

    ReplyDelete
  51. PROBLEM-3

    #include
    using namespace std;

    int Mohammad(int r,int c)
    {
    int result;
    result=((r*c)-1);
    return result;
    }

    int main()
    {
    int m,n;

    cout<<"Enter how many row in chocolate:";
    cin>>m;

    cout<<"Enter how many column in chocolate:";
    cin>>n;

    cout<<"need minimum number of cuts is:"<<Mohammad(m,n)<<"\n";
    return 0;
    }

    Maisha Fahmida
    Batch:48th
    ID:201511018

    ReplyDelete
  52. using C++

    #include
    using namespace std;

    class Parent
    {
    public:
    void meth(int firstNumberA, int secondNumberA, int rangeA);
    protected:
    int firstNumber, secondNumber, range;
    };

    void Parent::meth(int firstNumberA, int secondNumberA, int rangeA)
    {
    firstNumber = firstNumberA;
    secondNumber = secondNumberA;
    range = rangeA;
    }

    class Child: public Parent
    {
    public:
    int method();
    };

    int Child::method()
    {
    int total = 0, result = 0;
    cout << "In your given range the Fibonocci series is --: " ;
    for(int i = 0; i < range; i++){
    result = firstNumber + secondNumber;
    firstNumber = secondNumber;
    secondNumber = result;
    total += result;
    cout << result << "\t";
    }
    return total;
    }

    void func() //using function to call all the member
    {
    int i = 0, j = 0, k = 0, temp = 0;
    Child obj;

    cout << "Enter your first number --: ";
    cin >> i;
    cout << "Enter your second number --: ";
    cin >> j;
    cout << "Enter a range for your Fibonocci series --: ";
    cin >> k;

    obj.meth(i, j, k);
    temp = obj.method();

    cout << "\nThe total of your Fibonocci series --: " << temp;
    }

    int main()
    {
    func();
    return 0;
    }

    ReplyDelete
  53. Sir, I have question!
    Why we can not make a child class of a constructor class?
    If it is possible then how we can inherit a constructor class?

    using C ++

    #include
    using namespace std;

    class constructor
    {
    public:
    int firstNumber, secondNumber, range;
    constructor(int firstNumberA, int secondNumberA, int rangeA);
    ~constructor();

    int temp();

    };
    constructor::constructor(int firstNumberA, int secondNumberA, int rangeA)
    {
    firstNumber = firstNumberA;
    secondNumber = secondNumberA;
    range = rangeA;
    }
    constructor::~constructor()
    {
    cout << "[+]Memory Released[+]";
    }

    int constructor::temp()
    {
    cout << "In your given range the Fibonocci series is --: ";
    int total = 0, result = 0;
    for(int i = 0; i < range; i++){
    result = firstNumber + secondNumber;
    firstNumber = secondNumber;
    secondNumber = result;
    total += result;
    cout << result << "\t";
    }
    return total;
    }

    int func()
    {
    int i = 0, j = 0, k = 0, temp = 0;
    cout << "Enter your first number --: ";
    cin >> i;
    cout << "Enter your second number --: ";
    cin >> j;
    cout << "Enter a range for your Fibonocci series --: ";
    cin >> k;
    constructor obj(i, j, k);
    temp = obj.temp();
    cout << "\nThe total of your Fibonocci series --: " << temp << "\n";
    }

    int main()
    {
    func();
    return 0;
    }


    ReplyDelete
  54. #include
    using namespace std;
    void sum(int a,int b,int term);
    int main()
    {
    int a=0,b=1,term;
    cout<<"Enter the fibonacci number";
    cin>>a>>b;
    cout<<"Enter the term";
    cin>>term;
    sum(a,b,term);
    }
    void sum(int a,int b, int term)
    {
    int sum=0,i,fib=0;
    for(i=1;i<=term;i++)
    {
    fib=a+b;
    a=b;
    b=fib;
    cout<<fib<<" " ;
    sum=sum+fib;
    }
    cout<<"sum= "<<sum;
    }

    48TH BATCH
    ID:201510280

    ReplyDelete
  55. #include
    using namespace std;

    void sum(int x,int y,int term);
    int main()
    {
    int x=0,y=1,term;
    cout<<"Enter fibonacci number";
    cin>>x>>y;
    cout<<"Enter term";
    cin>>term;
    sum(x,y,term);
    }

    void sum(int x,int y,int term)

    {
    int sum=0,i,fibonacci=0;
    for(i=1;i<=term;i++)

    {
    fibonacci=x+y;
    x=y;
    y=fibonacci;
    cout<<fibonacci<<" " ;
    sum=sum+fibonacci;
    }

    cout<<"sum= "<<sum;
    }

    Batch:48th
    ID:201511018

    ReplyDelete
  56. #include
    using namespace std;
    class Pallindrome
    {
    public:
    int n;
    void get_number();
    protected:
    int number;
    };
    class Check: public Pallindrome
    {
    public:
    void check_pal();
    };
    void Pallindrome::get_number()
    {
    cout<<"Enter an integer: "<>n;
    number=n;
    }
    void Check::check_pal()
    {
    int reverse=0, rem,temp;
    temp=n;
    while(temp!=0)
    {
    rem=temp%10;
    reverse=reverse*10+rem;
    temp/=10;
    }
    if(reverse==n)
    cout<<n<<" is a pallindrome Number."<<endl;
    else
    cout<<n<<" is not a pallindrome number."<<endl;
    }
    int main()
    {
    Check obj;
    obj.get_number();
    obj.check_pal();
    return 0;
    }

    ReplyDelete
  57. ex 2


    #include
    using namespace std;
    class odd
    {
    public:
    int l,u;
    void get_v();
    protected:
    int low,upp;
    };
    class ckodd : public odd
    {
    public:
    int i,sum=0;
    void final_eq();
    };
    void odd::get_v()
    {
    cout<<"Enter lower bound :"<>l;
    cout<<"Enter upper bound :"<>u;
    low=l;
    upp=u;
    }
    void ckodd::final_eq()
    {
    for(i=l;i<=u;i++)
    {
    if(i%2!=0)
    sum+=i;
    }
    cout<<"Summation of all odd numbers between" <<" "<< l<<" "<< "to" <<" "<< u<<" "<< "is :" <<sum<<endl;
    }
    int main()
    {
    ckodd obj;
    obj.get_v();
    obj.final_eq();
    return 0;
    }

    ReplyDelete
  58. ex 3


    #include
    using namespace std;
    class jubbu
    {
    public:
    int m,n;
    void get_mn();
    protected:
    int M,N;
    };
    class choc : public jubbu
    {
    public:
    void final_eq();
    };
    void jubbu::get_mn()
    {
    cin>>m>>n;
    M=m;
    N=n;
    }
    void choc::final_eq()
    {
    int result;
    result=(m*n)-1;
    cout<<result<<endl;
    }
    int main()
    {
    choc obj;
    obj.get_mn();
    obj.final_eq();
    return 0;
    }

    ReplyDelete
  59. #include
    using namespace std;
    int main()
    {
    int num,r,sum=0,temp;
    cout<<"Enter a number:"<>num;
    temp=num;
    while(num)
    {
    r=num%10;
    num=num/10;
    sum=sum*10+r;
    }
    if(temp==sum)
    cout<<"The numner is a palindrom";
    else
    cout<<"The number is not a palindrom";
    }

    ReplyDelete
  60. #include
    using namespace std;
    class palindrome
    {
    public:
    int n;
    void get_number();
    protected:
    int number;
    };
    class check:public palindrome
    {
    public:
    void check_pal();
    };
    void palindrome::get_number()
    {
    cout<<"enter an integer"<>n;
    number=n;
    }
    void check::check_pal()
    {
    int revers=0,rem,temp;
    temp=n;
    while(temp!=0)
    {
    rem=temp%10;
    revers=revers*10+rem;
    temp/=10;
    }
    if(revers==n)
    cout<<n<<"is a palindrome number"<<endl;
    else
    cout<<n<<"is not a palindrome number"<<endl;
    }
    int main()
    {
    check obj;
    obj.get_number();
    obj.check_pal();
    return 0;
    }

    ReplyDelete
  61. #include
    using namespace std;
    class palindrome
    {
    public:
    int n;
    void get_number();
    protected:
    int number;
    };
    class check:public palindrome
    {
    public:
    void check_pal();
    };
    void palindrome::get_number()
    {
    cout<<"enter an integer"<>n;
    number=n;
    }
    void check::check_pal()
    {
    int revers=0,rem,temp;
    temp=n;
    while(temp!=0)
    {
    rem=temp%10;
    revers=revers*10+rem;
    temp/=10;
    }
    if(revers==n)
    cout<<n<<"is a palindrome number"<<endl;
    else
    cout<<n<<"is not a palindrome number"<<endl;
    }
    int main()
    {
    check obj;
    obj.get_number();
    obj.check_pal();
    return 0;
    }

    ReplyDelete
  62. //Ex-1:Palindrom(using Inheritance)
    #include
    using namespace std;
    class palindrom
    {
    public:
    void get_number();
    protected:
    int number;
    };
    class Check:public palindrom
    {
    public:
    void check_pal();
    };
    void palindrom::get_number()
    {

    cout<<"Enter your number:";
    cin>>number;
    }
    void Check::check_pal()
    {
    int rem,sum=0,temp;
    temp=number;
    while(number!=0)
    {
    rem=number%10;
    number/=10;
    sum=sum*10+rem;
    }
    if(temp==sum)
    cout<<"The number is a palindrom"<<endl;
    else
    cout<<"The number is not a palindrom"<<endl;
    }
    int main()
    {
    Check c;
    c.get_number();
    c.check_pal();
    }













































































































































    ReplyDelete
  63. //Ex-2
    #include
    using namespace std;
    class odd
    {
    public:
    int lower,upper;
    void put_range();
    protected:
    int l,u;
    };
    class Check:public odd
    {
    public:
    void get_result();
    };
    void odd::put_range()
    {
    cout<<"Enter your lower range:"<>lower;
    cout<<"Enter your upper range:"<>upper;
    l=lower;
    u=upper;

    }
    void Check::get_result()
    {
    int i,sum=0;
    cout<<"Summation of odd numbers is:"<<endl;
    for(i=lower;i<=upper;i++)
    {
    if(i%2!=0)
    sum+=i;

    }
    cout<<sum;
    }
    int main()
    {
    Check c;
    c.put_range();
    c.get_result();
    }

    ReplyDelete
  64. //Ex-3:
    #include
    using namespace std;
    class Mohammad
    {
    public:
    int m,n;
    void put_a();
    protected:
    int M,N;
    };
    void Mohammad::put_a()
    {
    cout<<"Your solution is:"<>m>>n;
    M=m;
    N=n;
    }
    class Chocolate:public Mohammad
    {
    public:
    void get_solution();
    };
    void Chocolate::get_solution()
    {
    int result;
    result=((m*n)-1);
    cout<<result<<endl;
    }
    int main()
    {
    Chocolate c;
    c.put_a();
    c.get_solution();
    }

    ReplyDelete

Comment Here