Author Topic: i need help for c++  (Read 5337 times)

Offline NiGhT^^StAlKeR

  • Safelist Administator
  • MonsterKill Member
  • *
  • Posts: 4705
  • Country: mon
  • Karma: +266/-247
  • Geh.TT. / Rockasaurus / Nox.Interfector
  • Awards Winner of 1 Photoshop Challenge Contest [COMMON] Warlock Tour Winner [RARE] Rubick Tournament Winner Morphling Tour Winner Award [RARE] Mirana 1v1 Tournament Winner [RARE] Invoker 1v1 Tournament Winner [RARE] Admiral Tournament Winner [RARE] 1v1 Windrunner Tour Winner [RARE] 1v1 Earthshaker Tournament Winner [RARE] LA Ladder #11-25 [EPIC] Shadow Raze Tour Award [RARE] Path of the King Tour 1. Place Award [LEGENDARY] 3v3 SHOM Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] 1v1 AR Tour Winner [RARE] IHRL Member [RARE] IHRL Champion [EPIC] IHRL Legend [LEGENDARY] 5v5 Night Cup Winner [EPIC] Tiny Tournament Winner [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #30 on: March 31, 2015, 23:56 »
Any Reason for using initializer lists in the constructor ?

In this easy class, it is pretty much same as using regular stuff like

kompleks(int a,int b){Re=a; Im=b;};

But in programs where more classes are connected and some are derived from others, it can speed up process a bit, specially if there are many variables in class as far as I know.  I'm not exactly sure why, but compiler probably treats them like some special type of function, not like the regular call etc.

sto ova zadnja kad onesem 3 i 5 kaze 9 i 24 :D treba 9 i 25 ? :D

Neam pojma, bug, worked fine for me
Dota - Pick me 0:51  SF :)
Dota - Symphony of skills 4:23 SF :D
Dota - Light the torch 2:12  SF :D
Dota - Keep ownage 0:25-1:25 Naix :D
WoDotA 8)

Offline NiGhT^^StAlKeR

  • Safelist Administator
  • MonsterKill Member
  • *
  • Posts: 4705
  • Country: mon
  • Karma: +266/-247
  • Geh.TT. / Rockasaurus / Nox.Interfector
  • Awards Winner of 1 Photoshop Challenge Contest [COMMON] Warlock Tour Winner [RARE] Rubick Tournament Winner Morphling Tour Winner Award [RARE] Mirana 1v1 Tournament Winner [RARE] Invoker 1v1 Tournament Winner [RARE] Admiral Tournament Winner [RARE] 1v1 Windrunner Tour Winner [RARE] 1v1 Earthshaker Tournament Winner [RARE] LA Ladder #11-25 [EPIC] Shadow Raze Tour Award [RARE] Path of the King Tour 1. Place Award [LEGENDARY] 3v3 SHOM Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] 1v1 AR Tour Winner [RARE] IHRL Member [RARE] IHRL Champion [EPIC] IHRL Legend [LEGENDARY] 5v5 Night Cup Winner [EPIC] Tiny Tournament Winner [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #31 on: April 01, 2015, 00:06 »
sto ova zadnja kad onesem 3 i 5 kaze 9 i 24 :D treba 9 i 25 ? :D

ah y, cause I made variable a an integer, function pow returns float, so it was 24.999smth = 24 as integer.

Just replace pow(a,2) with a*a
Dota - Pick me 0:51  SF :)
Dota - Symphony of skills 4:23 SF :D
Dota - Light the torch 2:12  SF :D
Dota - Keep ownage 0:25-1:25 Naix :D
WoDotA 8)

Offline castiele

  • Master Jedi
  • Honored member
  • WickedSick Member
  • *
  • Posts: 2260
  • Country: 00
  • Karma: +120/-179
  • Spit on my karma;)
    • View Profile
    • Awards
Re: i need help for c++
« Reply #32 on: April 01, 2015, 23:20 »
you just comlicating your life with c++,use python ofc;)

Offline cacomonster

  • Pro Member
  • *
  • Posts: 477
  • Country: 00
  • Karma: +32/-21
  • Awards Warlock Tour Winner [RARE] Shadow Raze Tour Award [RARE] Pudge Wars Tournament Winner [RARE] Mirana Wars Winner [RARE] 3v3 SHOM Tournament Winner [RARE] Castle Fight Winner [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #33 on: April 01, 2015, 23:38 »
Well .. C++ is the strongest language .. ( just harder to use ) ..

Offline div.ide

  • Honored member
  • WickedSick Member
  • *
  • Posts: 1763
  • Country: pl
  • Karma: +235/-61
  • Awards Winner of 1 Challenge of the Week [COMMON] Forum staff member [RARE] Drummer - Music Quiz #2 [RARE] Trumpeter- Music Quiz #3 [COMMON]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #34 on: April 02, 2015, 00:32 »
Well .. C++ is the strongest language .. ( just harder to use ) ..
To kill a fly, you don't need to use grenade. Besides, just because c++ (or hell, asm for that matter) can run faster, doesn't mean it will in hands of unexperienced dev. Moreover, unlike with python, javascript, php, java, and a bunch of others, you can't really make a webapp with c++ can you? :P (hint - web stuff is trending :P)

you just comlicating your life with c++,use python ofc;)
I don't think it's a matter of choice in this particular case.

sto ova zadnja kad onesem 3 i 5 kaze 9 i 24 :D treba 9 i 25 ? :D

ah y, cause I made variable a an integer, function pow returns float, so it was 24.999smth = 24 as integer.

Just replace pow(a,2) with a*a
You could also be aware about casting float to int, and round that either with round() function  (part of <math.h> library) or effectively do it manually by adding pow(a,2)+0.5 before cast to int (same result... in most cases) :P
Limited float precision can be a bitch.
01010111 01100101 01101100 01101100 00100000 01100100 01101111 01101110 01100101 00101100 00100000 01101110 01100101 01110010 01100100 00101110

Offline jeandarc

  • Administrator
  • HolyShit Member
  • *
  • Posts: 5198
  • Country: jp
  • Karma: +865/-649
  • Server Account: jeandarc
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards Lagabuse Legend Winner of 1 Challenge of the Week [COMMON] Winning 3 seasons of Football Betting [EPIC] GFX Tournament Participant [COMMON] Making 50 bets in Footbal Betting [COMMON] GFX staff member [RARE] Winner of 1 Signature of the Week Contest [COMMON] LA Ladder #11-25 [EPIC] 1v1 Earthshaker Tournament Winner [RARE] 1v1 Queen of Pain Tour Winner [RARE] Winner of 5 ShadowRaze Tours [LEGENDARY] Mirana Wars Winner [RARE] Pudge 1v1 Tournament Winner [RARE] Invoker Wars Tournament [RARE] 1v1 AR Tour Winner [RARE] Pudge Wars Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] Uther Party Tournament Winner [COMMON] MadBalls Tournament Winner [RARE] Junior Tournament Member [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #35 on: April 02, 2015, 11:36 »
Wise words lil divide, too bad your post was too long and i cba to read all of that. I like short and quality posts.

Thank you,
Regards,
Jean, love and peace.

Offline NiGhT^^StAlKeR

  • Safelist Administator
  • MonsterKill Member
  • *
  • Posts: 4705
  • Country: mon
  • Karma: +266/-247
  • Geh.TT. / Rockasaurus / Nox.Interfector
  • Awards Winner of 1 Photoshop Challenge Contest [COMMON] Warlock Tour Winner [RARE] Rubick Tournament Winner Morphling Tour Winner Award [RARE] Mirana 1v1 Tournament Winner [RARE] Invoker 1v1 Tournament Winner [RARE] Admiral Tournament Winner [RARE] 1v1 Windrunner Tour Winner [RARE] 1v1 Earthshaker Tournament Winner [RARE] LA Ladder #11-25 [EPIC] Shadow Raze Tour Award [RARE] Path of the King Tour 1. Place Award [LEGENDARY] 3v3 SHOM Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] 1v1 AR Tour Winner [RARE] IHRL Member [RARE] IHRL Champion [EPIC] IHRL Legend [LEGENDARY] 5v5 Night Cup Winner [EPIC] Tiny Tournament Winner [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #36 on: April 02, 2015, 22:10 »
You could also be aware about casting float to int, and round that either with round() function  (part of <math.h> library) or effectively do it manually by adding pow(a,2)+0.5 before cast to int (same result... in most cases) :P
Limited float precision can be a bitch.

Yea I know div.ide, the casting and adding 0.5 works also, and the round, and many more ways, but imo easiest was just to do as I said, replace it with a*a, so he doesn't need to think about those things so much :D

And about c++, it is usually used for harder stuff, not these easy tasks, but it was his school task so I decided to help, hopefully I managed to do it.

I prefer Matlab for my engineering problems which can be solved easier by using it.
C++ is too deep programming for me and my needs, but I can still do a lot in it, powerful stuff.
« Last Edit: April 02, 2015, 22:13 by NiGhT^^StAlKeR »
Dota - Pick me 0:51  SF :)
Dota - Symphony of skills 4:23 SF :D
Dota - Light the torch 2:12  SF :D
Dota - Keep ownage 0:25-1:25 Naix :D
WoDotA 8)

Offline uCANseeMe

  • Pro Member
  • *
  • Topic Author
  • Posts: 315
  • Karma: +5/-28
    • View Profile
    • Awards
Re: i need help for c++
« Reply #37 on: April 03, 2015, 18:08 »
TY VERY MUCH <3

Offline jeandarc

  • Administrator
  • HolyShit Member
  • *
  • Posts: 5198
  • Country: jp
  • Karma: +865/-649
  • Server Account: jeandarc
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards Lagabuse Legend Winner of 1 Challenge of the Week [COMMON] Winning 3 seasons of Football Betting [EPIC] GFX Tournament Participant [COMMON] Making 50 bets in Footbal Betting [COMMON] GFX staff member [RARE] Winner of 1 Signature of the Week Contest [COMMON] LA Ladder #11-25 [EPIC] 1v1 Earthshaker Tournament Winner [RARE] 1v1 Queen of Pain Tour Winner [RARE] Winner of 5 ShadowRaze Tours [LEGENDARY] Mirana Wars Winner [RARE] Pudge 1v1 Tournament Winner [RARE] Invoker Wars Tournament [RARE] 1v1 AR Tour Winner [RARE] Pudge Wars Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] Uther Party Tournament Winner [COMMON] MadBalls Tournament Winner [RARE] Junior Tournament Member [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #38 on: April 04, 2015, 08:12 »
Np

Offline MyUberNick

  • Founder
  • WickedSick Member
  • *
  • Posts: 1336
  • Country: hr
  • Karma: +277/-83
  • Awards Lagabuse Legend LA High Staff [EPIC] MVP Member [LEGENDARY] LA Ladder #11-25 [EPIC]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #39 on: May 08, 2015, 19:15 »
Any Reason for using initializer lists in the constructor ?

In this easy class, it is pretty much same as using regular stuff like

kompleks(int a,int b){Re=a; Im=b;};

But in programs where more classes are connected and some are derived from others, it can speed up process a bit, specially if there are many variables in class as far as I know.  I'm not exactly sure why, but compiler probably treats them like some special type of function, not like the regular call etc.

sto ova zadnja kad onesem 3 i 5 kaze 9 i 24 :D treba 9 i 25 ? :D

Neam pojma, bug, worked fine for me

Yes in theory constructor initialization lists are faster than assigning a value from the body of the constructor. It's because of how the class members are constructed.

If you don't use initialization list:
- all class members will be initialized with their default constructor
- and then in constructor body you will initialize them again and assign them to members

If you use initialization list:
- all class members will be initialized with their default constructor or whichever else constructor you chose in the initialization list so you are initializing members only once not twice

In practice compiler probably optimizes simple cases as in this thread.



you just comlicating your life with c++,use python ofc;)

+1, life is too short for C++, you need it if you need performance, if not don't complicate your life, learn Java,C#,some web language :).



Well .. C++ is the strongest language .. ( just harder to use ) ..
To kill a fly, you don't need to use grenade. Besides, just because c++ (or hell, asm for that matter) can run faster, doesn't mean it will in hands of unexperienced dev. Moreover, unlike with python, javascript, php, java, and a bunch of others, you can't really make a webapp with c++ can you? :P (hint - web stuff is trending :P)

+1. You can make a webapp, see you in few years :D.

Offline jeandarc

  • Administrator
  • HolyShit Member
  • *
  • Posts: 5198
  • Country: jp
  • Karma: +865/-649
  • Server Account: jeandarc
    PSR: Loading
    Games: Loading
    Wins/Loses: Loading/Loading
    Hero K/D/A: Loading
    Creep K/D/N: Loading
    Show/hide more stats
  • Awards Lagabuse Legend Winner of 1 Challenge of the Week [COMMON] Winning 3 seasons of Football Betting [EPIC] GFX Tournament Participant [COMMON] Making 50 bets in Footbal Betting [COMMON] GFX staff member [RARE] Winner of 1 Signature of the Week Contest [COMMON] LA Ladder #11-25 [EPIC] 1v1 Earthshaker Tournament Winner [RARE] 1v1 Queen of Pain Tour Winner [RARE] Winner of 5 ShadowRaze Tours [LEGENDARY] Mirana Wars Winner [RARE] Pudge 1v1 Tournament Winner [RARE] Invoker Wars Tournament [RARE] 1v1 AR Tour Winner [RARE] Pudge Wars Tournament Winner [RARE] 2v2 SHOM Tournament Winner [RARE] Uther Party Tournament Winner [COMMON] MadBalls Tournament Winner [RARE] Junior Tournament Member [RARE]
    • View Profile
    • Awards
Re: i need help for c++
« Reply #40 on: May 08, 2015, 19:44 »
Ivo stop rrying to be cool, you will never be cool