Monday 21 January 2013

OOP344 week 2 Exercises

1. Sum of two numbers by command line


#include<iostream>
#include<stdlib.h>

using namespace std;

int main(int argc, char* argv[])
{

        int sum;

        if(argc == 3)
        {
                cout << "Sum of the number is: "<< atoi(argv[1]) + atoi(argv[2]) << endl;
        }
        else
        {
                cout << "Please enter thr correct input" << endl;
        }
        return 0;
}

2. Subtraction of two numbers by command line

#include<iostream>
#include<stdlib.h>

using namespace std;

int main(int argc, char* argv[])
{

        int sum;

        if(argc == 3)
        {
                cout << "Sum of the number is: "<< atoi(argv[1]) - atoi(argv[2]) << endl;
        }
        else
        {
                cout << "Please enter thr correct input" << endl;
        }
        return 0;
}


3. Multipication of two numbers by command line

#include<iostream>
#include<stdlib.h>

using namespace std;

int main(int argc, char* argv[])
{

        int sum;

        if(argc == 3)
        {
                cout << "Sum of the number is: "<< atoi(argv[1]) * atoi(argv[2]) << endl;
        }
        else
        {
                cout << "Please enter thr correct input" << endl;
        }
        return 0;
}


4. Division of two numbers by command line

#include<iostream>
#include<stdlib.h>

using namespace std;

int main(int argc, char* argv[])
{

        int sum;

        if(argc == 3)
        {
                cout << "Sum of the number is: "<< atoi(argv[1]) / atoi(argv[2]) << endl;
        }
        else
        {
                cout << "Please enter thr correct input" << endl;
        }
        return 0;
}

No comments:

Post a Comment