Chapter 2 Solve E.Balaguruswamy C++

OOP Chapter 2 Solve
Programming Exercise 2.1 :
#include <iostream>

using namespace std;

int main()
{
    cout << "Maths = 90\nPhysics = 77\nChemistry = 69\n";
    return 0;
}

Programming Exercise 2.2 :
#include <iostream>

using namespace std;

int main()
{
    int a,b;

    cout << "Enter the first number: ";
    cin >> a;
    cout << "Enter the second number: ";
    cin >> b;

    if(a>b)
    {
        cout << "A is the largest value.";
    }
    else
    {
        cout << "B is the largest value.";
    }
    return 0;
}

Programming Exercise 2.3 :
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    char c;

    cout << "Type any character: ";
    cin >> c;

    printf("Corresponding ANCII value is : %d",c);

    return 0;
}

Programming Exercise 2.4 :
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,x;

    cout << "Enter value for A, B, C :\n";
    cin >> a >> b >> c;

    x = (a/b)-c;

    cout << "Value of X = " << x;

    return 0;
}

Programming Exercise 2.5 :
#include <iostream>

using namespace std;

int main()
{
    float farn,cels;

    cout << "Enter temperature in Fahrenheit: ";
    cin >> farn;

    cels = (farn-32)/1.8;

    cout << endl << "Celsius value = " << cels << endl ;

    return 0;
}

Programming Exercise 2.6 :
#include <iostream>

using namespace std;

class temp
{
    float farn,cels;
public:
    void set(void)
    {
        cout << "Enter temperature in Fahrenheit: ";
        cin >> farn;
        cels = (farn-32)/1.8;
        cout << endl << "Celsius value = " << cels << endl ;
    }
};

int main()
{
    temp obj;

    obj.set();

    return 0;
}


No comments:

Post a Comment