Thursday, August 3, 2017

Product of Two Numbers Using Classes in C++

Here is a simple code that I wrote a long time ago while I am working as a college professor in one of the University in my hometown. I was teaching C++ programming from the basics to advance topics. Below is a code the shows how to use classes to find the product of two number being provided by the user. I am using Dev C++ as my C++ compiler in writing this program and CodeBlocks as my text editor. I hope you will learn something from it. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

Thank you.



Program Listing



#include <iostream>
#include <string>

using namespace std;

class multiply {
    int val1,val2;
    char reply;
    public:
    int get_data();
    void display_result(void);
};


int multiply :: get_data()
{
    while (1) {
    system("cls");
    cout << "enter two number :";
    cin >> val1>> val2;
    cout << "\n\n The Product is " << (val1*val2);
    cout << "\n\n";
    cout << "More Y Or N : ";
    cin >> reply;

    if (tolower(reply) == 'n') {
        cout << "Thanks";
        break;
    }
    }
}

void multiply :: display_result(void)
{
    int val=0;
    val = get_data();
}

main() {
    multiply numbers;

    numbers.display_result();
}



No comments:

Post a Comment