Jump to content

Functions and classes explained


_Seb1

3 posts in this topic

Recommended Posts

Posted

So in this information thread I will explain what a Class is and what they are used for. Before I can explain what a Class is I must explain Functions and their usage.

The idea behind Functions that the code should be executed multiple times, so it gets outsorced to a Function. Such Functions can be called randomly in the program and if that happens all the Instructions in the function will be executed. The usage of Functions are not only to prevent code doubles. They can be  appointed very flexibal

- While calling the Function up, your able to send Data into it.

- After the Function has ended you can return Data to its calling place.

as example we will take an easy math function:

f(x) = x²

this function can be called with different Parametres and always computes the square of it. When it gets called up with the parametre 2 it delivers 4 as result.

They are able to work more than a math function though:

- the quantity of the parametres aren‘t limited. You can use many parametres.

- The Datatypes(Int, Float/Double etc other thread) are free choosable so you can use strings or booleans too.

- You can return values to its access point.

How is a Function made?

 

Name

Parametres

Return type

Functionstrunk

Must not be like this, but as C++ is very strict about that, you will need to write all that.

Example for a function:

Return Type Functionname(List_of_Parametres)

{(start of the functionstrunk aka Codeblock)

Instruction1;

Instruction2;

....

}

If a Function should not return Data the special return type void is used.

The list of parametres is a seperated list of Datatype-Name-Pairs.(int alpha, string beta)

The return instrction

The return instruction ends the function and gives the data back to its calling place. example the function f(x) = x²:

int f(int x)

{

  int y;

  y = x * x;

  return y;

}

That above is Pseudocode, you can realize it like that but there are parts missing(like defining x).

It is possible to use more than one return instruction. So as example:

int max(int x, int y)

{

 if (x > y)

    return x;

  return y;

}

It checks if x is bigger than y if thats true it gives back the data to its calling place and ends the function. If it is not true it returns y to the calling place and the function ends here.

Failures in the Function code

int max_failmao(int x, int y)

{

 if (x > y)

  return y;

}

👆wrong because there isnt a return instruction defined for x.

void failures

Void return type: Doesnt return values.

So

void Joka( )

{

 return 5;

}

👆failure

You can still use a return instruction in a void function to end it prematurely.

void WithJoka(int x)

{

if (x > 5)

 return;

}

 

Recursions.

Now because this is not used very often due to its high amount of storage eat, you won‘t face it very often.

int Recursionexample()

{

 return( ) + 1

} 

would always call itself up again and add 1 to its parametres. This endlessrecursion would cause a crash of the program. Recursions are a very elegant way to solve problems but it takes muh storage due to its recalls.

 

Classes

What is a „Class“?

A class is an own datatype you can manage after your favor. In those classes objects(so called instances) are saved. So for the class „Human“ Seb, Tronald Dump etc. can be chosen as instances. Characteristic for classes is that all instances have the same skills(So called attributes: howtall; weight).  Every Instance in a class can perform actions: Like baking a cake(humans).

the skills of each instance can vary(not always the same weight).

You can simulate an own similar world with those classes.

How do you realize it in code?

3 parts:

The name

The skills

The actions

So in C++ a class is made like this:

(easy class)

class ClassnameJokaGay

{

..... Skills and actions .....

}

Actions are realized by functions in this actions are called methods of a class if you made it with functions. In the class you can access the skills(attributes)

Classes always have constructures, those methods are used to make new classinstances. Well now we know how to build a class, but what about a Constructor?

A Constructor is made like a function, having the same name like the class and without giving the return type.

ex.:

class score

{

....

   score( )

   {

     quantitygoalsteam1 = 0;

     quantitygoalsteam2 = 0;

   }

}

So because they are playing and they could shoot some goals we need methods to realize that class.

so ex.:

class score

{

 ....

 void goalsteam1( )

{

 quantitygoalsteam1 = quantitygoalsteam1 + 1;

}

Adds a goal to the team

void goalsteam2( )

 {

  quantityofgoalsteam2 =     quantityofgoalsteam2 + 1;

 }

}

So this was now long enough. If I have time I will create one about how to create instances and use them.

 

 

 

Archived

This topic is now archived and is closed to further replies.

  • Our picks

    • World War Heroes — WW2 PvP FPS +3 Mods [ Unlimited Ammo ]
      Mod APK Game Name: World War Heroes — WW2 PvP FPS By Azur Interactive Games Limited
      Rooted Device: Not Required.
      Google Play Store Link: https://play.google.com/store/apps/details?id=com.gamedevltd.wwh

       

      🤩 Hack Features

      - Freeze Ammo
      - No Recoil
      -- No Ads
      • 0 replies
    • Rise & Loot: Idle Hero RPG v1.1.2 [ +15 Cheats ] Currency Max
      Modded/Hacked App: Rise & Loot: Idle Hero RPG By Ngoc Minh Le
      Bundle ID: com.riseloop.idlerpg
      App Store Link: https://apps.apple.com/us/app/rise-loot-idle-hero-rpg/id6821365929?uo=4

      🤩 Hack Features

      - Never Die
      - One Hit Kill
      ===== VIP =====
      - Skip Ads
      - Add Currency
      - Max Damage
      - Multi Attack x5
      - Always Exotic Loot
      - Sale Value x1000
      - Money Multiplier
      - Free Shopping / Not IAP
      - Battle Speed x3
      - Unlock All Realms
      - God Roll Gear
      - Best Card Picks
      - Daily Reward Always Ready
      • 0 replies
    • Rise & Loot: Idle Hero RPG v1.1.2 [ +15 Jailed ] Currency Max
      Modded/Hacked App: Rise & Loot: Idle Hero RPG By Ngoc Minh Le
      Bundle ID: com.riseloop.idlerpg
      App Store Link: https://apps.apple.com/us/app/rise-loot-idle-hero-rpg/id6821365929?uo=4

      🤩 Hack Features

      - Never Die
      - One Hit Kill
      ===== VIP =====
      - Skip Ads
      - Add Currency
      - Max Damage
      - Multi Attack x5
      - Always Exotic Loot
      - Sale Value x1000
      - Money Multiplier
      - Free Shopping / Not IAP
      - Battle Speed x3
      - Unlock All Realms
      - God Roll Gear
      - Best Card Picks
      - Daily Reward Always Ready
      • 1 reply
    • Stick Fight: Evolution v1.0.6 [ +22 Cheats ] Currency Max
      Modded/Hacked App: Stick Fight: Evolution By Ngoc Minh Le
      Bundle ID: com.min001.stickman.warrior.evolution.age
      App Store Link: https://apps.apple.com/us/app/stick-fight-evolution/id6747939675?uo=4

      🤩 Hack Features

      - Add Currency
      - Never Die
      - Max Damage
      ===== VIP =====
      - Auto Win
      - Skip Ads
      - Game Speed
      - Unlimited Battle Food
      - Cheat Panel +15
      • 0 replies
    • Stick Fight: Evolution v1.0.6 [ +22 Jailed ] Currency Max
      Modded/Hacked App: Stick Fight: Evolution By Ngoc Minh Le
      Bundle ID: com.min001.stickman.warrior.evolution.age
      App Store Link: https://apps.apple.com/us/app/stick-fight-evolution/id6747939675?uo=4

      🤩 Hack Features

      - Add Currency
      - Never Die
      - Max Damage
      ===== VIP =====
      - Auto Win
      - Skip Ads
      - Game Speed
      - Unlimited Battle Food
      - Cheat Panel +15
      • 0 replies
    • Geometry Cannon : Idle Defense v1.4.4 [ +7 Cheats ] Currency Max
      Modded/Hacked App: Geometry Cannon : Idle Defense By SUPERBOX. Inc
      Bundle ID: com.superbox.ios.idledefense
      App Store Link: https://apps.apple.com/us/app/geometry-cannon-idle-defense/id6742388718?uo=4
       

      🤩 Hack Features

      - Gold Pass
      - Silver Pass
      - Add Currency
      - Never Die
      - Max Damage
      - Kill All Enemies
      - Game Speed
      • 0 replies
    • Geometry Cannon : Idle Defense v1.4.4 [ +7 Jailed ] Currency Max
      Modded/Hacked App: Geometry Cannon : Idle Defense By SUPERBOX. Inc
      Bundle ID: com.superbox.ios.idledefense
      App Store Link: https://apps.apple.com/us/app/geometry-cannon-idle-defense/id6742388718?uo=4

      🤩 Hack Features

      - Gold Pass
      - Silver Pass
      - Add Currency
      - Never Die
      - Max Damage
      - Kill All Enemies
      - Game Speed
      • 0 replies
    • Neon Castle: Idle TD RPG v1.0 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Neon Castle: Idle TD RPG By Mert Can Diker
      Bundle ID: com.medu.neon.castledefense.idlerpg.ios
      App Store Link: https://apps.apple.com/us/app/neon-castle-idle-td-rpg/id6748567934?uo=4

      🤩 Hack Features

      - Add Currency
      - Never Die
      - Max Damage
      - Kill All Enemies
      • 0 replies
    • Neon Castle: Idle TD RPG v1.0 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Neon Castle: Idle TD RPG By Mert Can Diker
      Bundle ID: com.medu.neon.castledefense.idlerpg.ios
      App Store Link: https://apps.apple.com/us/app/neon-castle-idle-td-rpg/id6748567934?uo=4

      🤩 Hack Features

      - Add Currency
      - Never Die
      - Max Damage
      - Kill All Enemies
      • 0 replies
    • Endless Defense: Idle Tower v0.2.13 [ +4 Cheats ] Currency Max
      Modded/Hacked App: Endless Defense: Idle Tower By MAD PIXEL GAMES LTD
      Bundle ID: battle.castle.clash.wave
      App Store Link: https://apps.apple.com/us/app/endless-defense-idle-tower/id6740865987?uo=4

      🤩 Hack Features

      - Ads No
      - Add Currency
      - Never Die
      - Max Damage
      • 0 replies
    • Endless Defense: Idle Tower v0.2.13 [ +4 Jailed ] Currency Max
      Modded/Hacked App: Endless Defense: Idle Tower By MAD PIXEL GAMES LTD
      Bundle ID: battle.castle.clash.wave
      App Store Link: https://apps.apple.com/us/app/endless-defense-idle-tower/id6740865987?uo=4
       

      🤩 Hack Features

      - Ads No
      - Add Currency
      - Never Die
      - Max Damage
      • 0 replies
    • Fishing Inc: Legendary Catch +10 Jailed Cheats [ Unlimited Money ]
      Modded/Hacked App: Fishing Inc: Legendary Catch By Snapbreak Games AB
      Bundle ID: com.snapbreak.fishinginc
      App Store Link: https://apps.apple.com/us/app/fishing-inc-legendary-catch/id6770534658?uo=4

       


      🤩 Hack Features

      - Freeze Gold
      - Unlimited Gold -> Will increase instead of decrease.
      - Freeze Casts
      - One-Click Catch
      - Always Perfect Catch
      - Unlock All Fish
      - Complete All Achievements
      - Trigger Kraken Event
      -- No Ads
      -- Deluxe Bundle Purchased
      • 2 replies
×
  • Create New...

Important Information

We would like to place cookies on your device to help make this website better. The website cannot give you the best user experience without cookies. You can accept or decline our cookies. You may also adjust your cookie settings. Privacy Policy - Guidelines