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;
}
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. :)
Re: I love self-made functions.
Quote:
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*.