Monday, January 10, 2022

exercise cpp

 #include <iostream>

#include <math.h>
using namespace std;
class SimpleCalculator
{
protected:
    float num1, num2;

public:
    float sum, subtraction, division, multiplication;
    void setdata(float number1, float number2)
    {
        num1 = number1;
        num2 = number2;
    }
    void calculation()
    {

        sum = num1 + num2;
        subtraction = num1 - num2;
        division = num1 / num2;
        multiplication = num1 * num2;
    }
    void display()
    {
        cout << "the sum of " << num1 << " and " << num2 << " is " << sum << endl;
        cout << "the subtraction of " << num1 << " and " << num2 << " is " << subtraction << endl;
        cout << "the division of " << num1 << " and " << num2 << " is " << division << endl;
        cout << "the multiplication of " << num1 << " and " << num2 << " is " << multiplication << endl;
    }
};
class ScientificCalculator
{
protected:
    float newnum1, newnum2;

public:
    float cube1, cube2, logrithm1, logrithm2, exponential1, exponential2, squareroot1, squareroot2;
    void newsetdata(float newnumber1, float newnumber2)
    {
        newnum1 = newnumber1;
        newnum2 = newnumber2;
    }
    void newcalculation()
    {

        cube1 = pow(newnum1,3);
        cube2 = pow(newnum2,3);
        logrithm1 = log10(newnum1);
        logrithm2 = log10(newnum2);
        squareroot1 = sqrt(newnum1) ;
         squareroot2 = sqrt(newnum2) ;
         exponential1 = exp(newnum1);
        exponential2 = exp(newnum2);
    }
    void newdisplay()
    {
        cout << "the cube of " << newnum1 << " and " << newnum2 << " is " << cube1 << " and " << cube2 << " respectively" << endl;
        cout << "the logrithm of " << newnum1 << " and " << newnum2 << " is " << logrithm1 << " and " << logrithm2 << " respectively" << endl;
        cout << "the squareroot of " << newnum1 << " and " << newnum2 << " is " << squareroot1 << " and " << squareroot2 << " respectively" << endl;
        cout << "the exponential of " << newnum1 << " and " << newnum2 << " is " << exponential1 << " and " << exponential2 << " respectively" << endl;
    }
};

class HybridCalculator:public SimpleCalculator , public ScientificCalculator{
float val1,val2;

public:
 void showdata(){
     
    cout<<"Enter the two numbers"<<endl;
    cin>>val1>>val2;

setdata(val1,val2);
calculation();
display();
newsetdata(val1,val2);
newcalculation();
newdisplay();
 }
};


int main()
{

    HybridCalculator obj1;
    obj1.showdata();
    return 0;
}

No comments:

Software scope

 In software engineering, the software scope refers to the boundaries and limitations of a software project. It defines what the software wi...

Popular Posts