Method (computer Science) - Example

Example

The following Java code defines a method "rectangle" in the class "main" that can find area of a rectangle.

public class Main { int rectangle(int h, int w) { return h*w; } }

The following C++ code defines methods "Input" and "Display".

#include #include #include struct goods { std::string name; float price; static int percent; void input { std::cout << "Good's name: "; std::cin >> name; std::cout << "Price: "; std::cin >> price; } void display { std::cout << "\n" << name; std::cout << ", Final price with tax: "; std::cout << static_cast(price * (1.0 + goods::percent * 0.01)); std::cout << "\n"; } }; int goods::percent = 20; int main { std::array a; for (auto&& i : a) { i.input; } for (auto&& i : a) { i.display; } }

Read more about this topic:  Method (computer Science)

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)