Recursive
2012-06-29 22:34:29
Basically what the title says
2012-06-29 22:34:29
2012-06-29 22:36:57
2012-06-29 23:01:36
From: JoeyGupta
It'll take a long time to explain, everything is different:
The functions, syntax, and what exactly can be done with it.
Edit: I think this could be in a more appropriate section of the forums, Perhaps it should be moved to:
SRL-Forums > Programming > Programming
int TableTopW = 10;
int TableTopH = 10;
int LegLength = 10;
int LegThickness = 5;
int TableTopArea = TableTopWidth * TableTopHeight;
bool RoundTable = false; //Square = True;
bool RoundLegs = true; //Square = False;
void CreateTable(int &TopWidth, int &TopHeight, int &LegLen, int &LegThick, bool &RoundTop, bool &RoundLegs)
{
//Create Some Tables and have our Parameters hold the values for each table made! This can probably be thousands of variables.
}
//The above code provides no encapsulation and can be accessed and changed at any moment in time.
//The above can represent anything.. Any table. We cannot have two tables with the same variables because
//editing one will change the other.. Another thing, Tables variables if allocated on the heap will not delete
//automatically!
class Table
{
private:
int TTW, TTH, LL, LT;
int TTA;
bool RT, RL;
public:
Table(int TopWidth, int TopHeight, int LegLen, int LegThick, bool RoundTop, bool RoundLegs);
~Table();
int GetTopArea();
}
Table::Table(int TopWidth, int TopHeight, int LegLen, int LegThick, bool RoundTop, bool RoundLegs) : TTW(TopWidth), TTH(TopHeight), LL(LegLen), LT(LegThick), RT(RoundTop), RL(RoundLegs){}
Table::GetTopArea(){ return TTW * TTH;}
//Now this provides the user an interface. Every time you want to make a new table, you simple call the constructor like so:
Table FirstTable = Table(10, 10, 10, 5, true, false);
Table SecondTable = Table(50, 50, 25, 15, false, true);
//I've just created two tables without extra variables and stuff.. These tables have properties that can be accessed through the . operator or -> operator depending
//on how it was constructed.
//In Procedural programming, I'd have to make separate variables for EACH table! And Creating a new table will not be so easy!
2012-06-29 23:06:55
2012-06-30 04:33:39
2012-06-30 04:48:16
From: nielsie95
Brandon, you are talking about procedural, not functional programming.
Chig, just consult Wikipedia.
2012-06-30 05:44:00
From: Brandon
Functions are the exact same in Procedural Programming vs. Object Oriented programming in C/C++
…
2012-06-30 11:04:22
From: superuser
For the reference, there is no such language as C/C++. There is C and then there is C++. You don't have objects/classes in C.
2012-06-30 12:53:10
From: Brandon
Why so picky? I've used C/C++ only once in my answer and it simply explains the concept to the OP. That statement is completely untrue and doesn't answer OP's question. This is object oriented programming in C:
http://msdn.microsoft.com/en-us/library/cc815324%28v=office.12%29.aspx
It's done with a C++ concept using vTables and polymorphism. You don't have provided classes in C but it doesn't mean you cannot program objects. There are tons of examples showing OOP programming in C on google and StackOverflow. Not only that, a lot of programmers use C/C++ when referring to thigns that can possibly be done in both or sometimes completely unrelated. The reason is because we all know that C/C++ go almost hand in hand and in this case, I used it "once" and correctly.
2012-07-01 19:17:36
From: Wikipedia
[INDENT]The focus of procedural programming is to break down a programming task into a collection of variables, data structures, and subroutines, whereas in object-oriented programming it is to break down a programming task into objects that expose behavior (methods) and data (members or attributes) using interfaces. The most important distinction is whereas procedural programming uses procedures to operate on data structures, object-oriented programming bundles the two together so an "object", which is an instance of a class, operates on its "own" data structure.
Nomenclature varies between the two, although they have similar semantics.[/INDENT]