Self-made functions: Opinion

This is a discussion on Self-made functions: Opinion within the C++ Programming forums, part of the General Programming Boards category; Ok, today we learned something new in CS2 (BOUT TIME), she refered to them as self-made functions, seems like a ...

  1. #1
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Self-made functions: Opinion

    Ok, today we learned something new in CS2 (BOUT TIME), she refered to them as self-made functions, seems like a correct term. I am going to type in the program we made, i just want opinions as to what could/should have been done different, if anything. Its a really basic example but we know how she tends to give bad learnings so... Thanks.

    Code:
    #include <iostream.h>
    
    int get_data();
    
    int main()
    {
      int value;
    
      value = get_data();
    
      cout<<value<<endl;
    
      return 0;
    }
    
    int get_data()
    {
      int data;
    
      cout<<"Enter a number: ";
    
      cin>>data;
    
      return data;
    }

  2. #2
    ...
    ... is offline
    Registered User
    Join Date
    Feb 2002
    Posts
    465
    *shakes head in confusion*

    it doesnt look any different than a normal function to me. what is it doing different?
    I came up with a cool phrase to put down here, but i forgot it...

  3. #3
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    I assume by "self made" this means you made it instead of including it from a library such as C runtime. it's not such an important term.

    I guess you're going through the really-basic-stuff-for-non-programmers now.
    "You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter

  4. #4
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    its really lame, were just adding another block and calling it in : /

    This is why i just clicked "buy" on amazon for 926 pages of "C how to program 2nd edition" by whats his faces

  5. #5
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146

    Smile I love self-made functions.

    I absolutely love self-made functions. I think they are very useful. I especially like throwing a bunch of them into a library and just calling that whenever I need them. I have "myinput.h" which has the following functions: GetInt, GetDouble, GetChar, GetApstring. I use that library all the time. I've also written libraries for english and metric conversions and the area and volume of several shapes. Using functions in my own libraries saves me a lot of time. It's also a good way to encapsulate data. Self-made functions are just good all around.

  6. #6
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Well, other than the use of .h header being depracated, its looks alright. You don't have any error handling to guard cin against going into a fail state (see what happens if you type "seven" in when it asks for a number) but thats kind of advanced if you are just getting to writing functions.

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I really had higher expectations when I opened this thread.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    See here: http://www.parashift.com/c++-faq-lit....html#faq-15.2 It's very easy to guard against invalid input.

  9. #9
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331

    Re: I love self-made functions.

    Originally posted by joshdick
    I absolutely love self-made functions. I think they are very useful. I especially like throwing a bunch of them into a library and just calling that whenever I need them. I have "myinput.h" which has the following functions: GetInt, GetDouble, GetChar, GetApstring. I use that library all the time. I've also written libraries for english and metric conversions and the area and volume of several shapes. Using functions in my own libraries saves me a lot of time. It's also a good way to encapsulate data. Self-made functions are just good all around.
    Thats what i want to do, but need to learn about making header files, because i don't know that yet.

    As far as error protecting, in my personal applications i would have a protection, but for in-class apps i don't becuz she tends to complain if i add my own things *shrug*.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is it legal to have functions within functions?
    By Programmer_P in forum C++ Programming
    Replies: 13
    Last Post: 05-26-2009, 12:21 AM
  2. GUI Design Question (Seeking an opinion)
    By Exile in forum C++ Programming
    Replies: 9
    Last Post: 02-10-2005, 07:47 AM
  3. Expression Manipulator v0.2 (bug fixes, functions)
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-26-2003, 05:52 PM
  4. trouble defining member functions
    By dP munky in forum C++ Programming
    Replies: 7
    Last Post: 04-13-2003, 09:52 PM
  5. Statements and Functions
    By GeekFreak in forum C++ Programming
    Replies: 5
    Last Post: 08-15-2002, 01:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21