I’ve found C++ to be thoroughly fun and enjoyable, but it’s too complicated for me. This doesn’t mean I’m giving up, I’m planning on trying Python next, oh gosh, hope it’s easier to grasp!
First off (actually last off, I just realized the number as I was about to post this), this is the 30th informational post (I think unless I forgot to number one)! I was recently scrolling through my posts to see what I lacked and guess what? I forgot to include one of the most fundamental charts/information, the operators and ways of comparing values. Now if that sounds confusing, just remember those signs from Algebra II about inequalities and stuff. That’s thingies I’m talking about (and for some reason my computer recognizes “thingies” as an actual word..?).
So here are the charts followed by their usage (borrowed from “cpusplus.com”):
(Sorry if the pictures are on the small side, I’m not a fanatic for “Paint” or photo-editing in general)
NOTE: Modulo – is the term used to divide a number by another, and collect their remainder ) represented by the percent symbol %. For example:
x=22 % 3;
“X” in this case would be equal to 1 because 22/3 equals 7 remainder 1.
And following our charts are the usages (most are just like how you’d use them on a calculator):
Modulo: x % 2
The equality signs will most commonly used in “if-else” statements so that’s how I’ll show them:
Equal to: if (x==10)
Not Equal to: if (x!=10)
Greater Than: if (x>10)
Less Than: if (x<10)
Greater Than or Equal to: if (x>=10)
Less Than or Equal to: if (x<=10)
And there you have it, the basic operators!
So I’ve finally got some time to get up to date with the blog (personal yay), and so you’ve hopefully tried using functions. What you’ll probably notice is that every time you want to use a function, you have to call on it right? Well what if you can have a function that repeats itself until it stops… like a loop? Well it’s here that “recursivity” comes into play. Now if you type that into any text editor Windows will say it’s not a real word, that’s technically true because it’s total jargon. Back to recursivity, the basic concept is a function calling on itself until a condition is fulfilled, for example “x<9999999″ or something like that. The structure of a recursive-function is exactly like any other functions, except with a little twist… instead of:
type name (parameters)
return ( [anything variable related] )
type name (parameters)
if-else loop with a condition to be fulfilled.
return ( [the function's name and something modifying it] )
So let’s look at an example provided by CPlusPlus.com’s tutorial:
Pretty straight forward right? Each time the loop is called it is repeated and “a” is decreased until the condition is reached… Easy as pie.
Have fun and good luck!
After a workout, you feel tired right? That’s because you pushed your body passed it’s usual limit by dumping for stuff to do it which is why your also hurt the next day. This concept is much like the “overload” concept used in the C++ language. Essentially, overloading is barraging one name/title with a lot of outcomes provided the conditions are met. If you didn’t understand what that means, let me break it down. A function’s title, is not unique to that function only, that title can be used with many other functions so long as the types of its parameters aren’t the same (at least on parameter has to have a different type). If you are unsure as to what a parameter is, please refer back to post #25. So how do we control which function is used when we call upon the title you ask. Well the CPU isn’t a total dumdum, it knows that an “int” function can’t take “float” values, therefore it automatically searches for a function using:
- The title declared
- The type that is specified
Following the basic understanding of the capabilities of overload, let’s look at a basic application:
See how modify is called upon twice but each time a different function is used? That’s overloading in action, it can prove to be very helpful at times when you don’t want anything to go wrong so you include a bajillion functions each with a different type but the same statements. JOY!
Good luck and have fun!