1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Class function C++

Discussion in 'C++' started by fmmctg01, May 14, 2011.

Thread Status:
Not open for further replies.
  1. fmmctg01

    fmmctg01 New Member

    How can i random add number using class function in C++ program?
  2. Alvasin

    Alvasin New Member

    A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions.

    An object is an instantiation of a class. In terms of variables, a class would be the type, and an object would be the variable.

    Classes are generally declared using the keyword class, with the following format:

    class class_name {
    } object_names;

    Where class_name is a valid identifier for the class, object_names is an optional list of names for objects of this class. The body of the declaration can contain members, that can be either data or function declarations, and optionally access specifiers.
    fmmctg01 likes this.
  3. Avenger625

    Avenger625 New Member

    I did not quite get your question!!!
    Please elaborate on exactly what you want.....
  4. fmmctg01

    fmmctg01 New Member

    1. Save classFraction in a file called classFraction.cpp.
    2. Write the main function in a file called fractionExercises.cpp. You access class
    Fraction through the statement: #include “classFraction.cpp”. The main function consists
    of a do while loop that displays the following menu:
    What type of exercise would you like to see?
    +, -, * , or /
    The user enters their choice (+, -, * , or /) into a variable named choice. If choice is
    ‘*’, then a function called multFraction() is called. This function is not part of class
    Fraction. It is found in the same file as the main function.
    Function multFraction() generates a random multiplication exercise. Use: srand(time(0)),
    and rand()%15+1, to generate random integers between 1 and 15. Functions srand and
    rand are found in stdlib.
  5. Avenger625

    Avenger625 New Member

    Okay! And after that what do u want to do?????

    And, just a personal question....if u dont mind me asking your nationality...i mean where do u live?
  6. xpi0t0s

    xpi0t0s Mentor

  7. shabbir

    shabbir Administrator Staff Member

Thread Status:
Not open for further replies.

Share This Page