1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Class function C++

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

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

    fmmctg01 New Member

    Joined:
    Mar 31, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    How can i random add number using class function in C++ program?
     
  2. Alvasin

    Alvasin New Member

    Joined:
    Apr 6, 2011
    Messages:
    8
    Likes Received:
    1
    Trophy Points:
    0
    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 {
    access_specifier_1:
    member1;
    access_specifier_2:
    member2;
    ...
    } 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

    Joined:
    Feb 1, 2011
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    0
    I did not quite get your question!!!
    Please elaborate on exactly what you want.....
     
  4. fmmctg01

    fmmctg01 New Member

    Joined:
    Mar 31, 2011
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Feb 1, 2011
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    0
    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

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
  7. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
Thread Status:
Not open for further replies.

Share This Page