Fill largest number to a class - C++ Class

C++ examples for Class:Class Creation

Description

Fill largest number to a class

Demo Code

                         
#include <iostream>
                         /*www . j a  va 2 s. c o m*/
class MyValue {
 private:
    int counter = 0;
    double number = 0;
    double largest = 0;
                         
 public:
    MyValue();
    ~MyValue();
                         
    // SETTERS
    void setLargest(double);
                         
    // GETTERS
    double getLargest();
                         
    void run();
};
MyValue::MyValue() {}
MyValue::~MyValue() {}
                         
// SETTERS
void MyValue::setLargest(double l) { largest = l; }
// GETTERS
double MyValue::getLargest() { return largest; }
                         
void MyValue::run() {
    std::cout << "Program to find the largest of 10 numbers\n" << std::endl;
                         
    while (counter < 10) {
        std::cout << "Enter number: (" << (10 - counter) << " remaining): ";
        std::cin >> number;
                         
        if (number > getLargest()) {
            setLargest(number);
        }
                         
        counter++;
    }
                         
    std::cout << "Largest Number is: " << getLargest() << std::endl;
}
                         
int main(int argc, const char *argv[]) {
    MyValue ftl;
                         
    ftl.run();
    return 0;
}

Result


Related Tutorials