Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   Technology (https://www.graalians.com/forums/forumdisplay.php?f=54)
-   -   Coding in C++ (https://www.graalians.com/forums/showthread.php?t=26365)

Jatz 11-25-2014 04:00 AM

Quote:

Posted by hosler (Post 519844)
Are you saying the prebuilt python stacks are flawed?

No, i'm taking about rolling your own. It's a lot easier to have python hold your hand.

Fysez 11-25-2014 05:29 AM

Completely forgot about this post.
Anyways, I went ahead and uploaded this to Google drive and downloaded it here so I could post it.

*Note: giving someone full code without first explaining everything is bad practice. So you may want to learn other ways or at least understand everything line by line*
This is in Java
Spoiler
import java.io.*;
import java.util.*;
public class Tester {
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
System.out.print("Enter something like 8 + 33 + 1,345 -137 : ");
String s = kb.nextLine(); //Best to store in a String and then create a new Scanner
//object; otherwise, it can get stuck waiting for input.
Scanner sc = new Scanner(s);
sc.useDelimiter("");
s = "";
while (sc.hasNext()) {
while (sc.hasNext("\\s")) {
sc.skip("\\s*");
}
if (sc.hasNext()) {
s = s+sc.next();
}
}
System.out.println(s);
sc = new Scanner(s);
//Set delimiters to a plus sign surrounded by any amount of white space...or...
// a minus sign surrounded by any amount of white space.
sc.useDelimiter("\\+|\\-");
int sum = 0;
if (s.startsWith("-")) {
sum = sum-sc.nextInt();
} else {
sum = sum+sc.nextInt();
}
while (sc.hasNextInt()) {
String operation = sc.findInLine("\\+|\\-");
if (operation.equals("+")) {
sum = sum+sc.nextInt();
}
if (operation.equals("-")) {
sum = sum-sc.nextInt();
}
}
System.out.println(sum);
}
}

Tricxta 11-25-2014 08:58 AM

Quote:

Posted by Fysez (Post 520116)
Completely forgot about this post.
Anyways, I went ahead and uploaded this to Google drive and downloaded it here so I could post it.

*Note: giving someone full code without first explaining everything is bad practice. So you may want to learn other ways or at least understand everything line by line*
This is in Java
Spoiler
import java.io.*;
import java.util.*;
public class Tester {
public static void main(String args[]) {
Scanner kb = new Scanner(System.in);
System.out.print("Enter something like 8 + 33 + 1,345 -137 : ");
String s = kb.nextLine(); //Best to store in a String and then create a new Scanner
//object; otherwise, it can get stuck waiting for input.
Scanner sc = new Scanner(s);
sc.useDelimiter("");
s = "";
while (sc.hasNext()) {
while (sc.hasNext("\\s")) {
sc.skip("\\s*");
}
if (sc.hasNext()) {
s = s+sc.next();
}
}
System.out.println(s);
sc = new Scanner(s);
//Set delimiters to a plus sign surrounded by any amount of white space...or...
// a minus sign surrounded by any amount of white space.
sc.useDelimiter("\\+|\\-");
int sum = 0;
if (s.startsWith("-")) {
sum = sum-sc.nextInt();
} else {
sum = sum+sc.nextInt();
}
while (sc.hasNextInt()) {
String operation = sc.findInLine("\\+|\\-");
if (operation.equals("+")) {
sum = sum+sc.nextInt();
}
if (operation.equals("-")) {
sum = sum-sc.nextInt();
}
}
System.out.println(sum);
}
}

That code... please don't post such stuff here, go ahead and explain concepts with brief lines of pseudocode but that's it.
You're bound to confuse motorox otherwise and he could do without that. Your code, doesn't promote desirable practices and is best kept clear of this thread.
Make your own thread if you want to show everyone that you can hack and make a mess at that...

hosler 11-25-2014 03:03 PM

Quote:

Posted by Jatz (Post 520079)
No, i'm taking about rolling your own. It's a lot easier to have python hold your hand.

Exactly. No excuse not to use python with all its power.

Fysez 11-25-2014 05:33 PM

Quote:

Posted by Tricxta (Post 520171)
That code... please don't post such stuff here, go ahead and explain concepts with brief lines of pseudocode but that's it.
You're bound to confuse motorox otherwise and he could do without that. Your code, doesn't promote desirable practices and is best kept clear of this thread.
Make your own thread if you want to show everyone that you can hack and make a mess at that...

LOL you truly are stupid.
Not only does that code have NOTHING to do with hacking, your comment is not original. I clearly stated AND put it in a spoiler for the fact that it's, as stated, bad practice.

Maybe rather than taking your grudge out on me for being better than you'll ever be, you can remove your account and swim onto the worthless life ahead of you.

hosler 11-25-2014 06:13 PM

Check your privileges, tricxta

Tricxta 11-25-2014 08:17 PM

This will be my only reply to this matter.

Quote:

Posted by Fysez (Post 520242)
LOL you truly are stupid.
Not only does that code have NOTHING to do with hacking, your comment is not original. I clearly stated AND put it in a spoiler for the fact that it's, as stated, bad practice.

You said "Note: giving someone full code without first explaining everything is bad practice. So you may want to learn other ways or at least understand everything line by line" NOT that your code promotes bad practices and shouldn't be used. In fact, you encouraged him to try understand it..
Your code doesn't teach anyone anything given the layout of your solution. It's not intuitive at all and definitely doesn't promote the OO paradigm like it should. I'm saying all this since C++ is an OO language itself and it's better to have someone write code properly from the start than become exposed and learn from solutions that may suggest otherwise.

Quote:

Posted by Fysez (Post 520242)
Maybe rather than taking your grudge out on me for being better than you'll ever be, you can remove your account and swim onto the worthless life ahead of you.

You have no way of judging yourself against me as a better programmer. Yes, you've coded yourself a 3d graal engine, great job.. It doesn't mean you're automatically above others.
How about instead of posting your code you really prove your knowledge and promote a code design that encompasses desirable attributes, maintainability being a big one... efficiency wouldn't be bad either.
Please, go ahead and read up on this sort of stuff.http://msdn.microsoft.com/en-au/library/ee658094.aspx

If you want to further continue this conversation don't bother replying in this thread, instead take it to facebook or pms. Cheers mang.

Quote:

Posted by hosler (Post 520257)
Check your privileges, tricxta

????

@Motorox and any others who are wondering what I'm on about..
In object oriented languages, responsibility of each object should be specific and clear with each object's functions performing a clearly labelled task and nothing else. In fysez's example, one object's method is responsible for everything. This makes it unclear when debugging as to which component might have stuffed up. And.. what if we wanted to add something new!?
Yes, the scale of the code at the moment makes this scenario not as bad as you might think and this argument seem petty but, as with anything, this can easily grow out of hand.

fp4 11-25-2014 10:27 PM

ruby is fun to script in

Fysez 11-25-2014 11:31 PM

Quote:

Posted by Tricxta (Post 520287)
Spoiler
This will be my only reply to this matter.


You said "Note: giving someone full code without first explaining everything is bad practice. So you may want to learn other ways or at least understand everything line by line" NOT that your code promotes bad practices and shouldn't be used. In fact, you encouraged him to try understand it..
Your code doesn't teach anyone anything given the layout of your solution. It's not intuitive at all and definitely doesn't promote the OO paradigm like it should. I'm saying all this since C++ is an OO language itself and it's better to have someone write code properly from the start than become exposed and learn from solutions that may suggest otherwise.


You have no way of judging yourself against me as a better programmer. Yes, you've coded yourself a 3d graal engine, great job.. It doesn't mean you're automatically above others.
How about instead of posting your code you really prove your knowledge and promote a code design that encompasses desirable attributes, maintainability being a big one... efficiency wouldn't be bad either.
Please, go ahead and read up on this sort of stuff.http://msdn.microsoft.com/en-au/library/ee658094.aspx

If you want to further continue this conversation don't bother replying in this thread, instead take it to facebook or pms. Cheers mang.


????

@Motorox and any others who are wondering what I'm on about..
In object oriented languages, responsibility of each object should be specific and clear with each object's functions performing a clearly labelled task and nothing else. In fysez's example, one object's method is responsible for everything. This makes it unclear when debugging as to which component might have stuffed up. And.. what if we wanted to add something new!?
Yes, the scale of the code at the moment makes this scenario not as bad as you might think and this argument seem petty but, as with anything, this can easily grow out of hand.

I'm not going to read your book of a story. As for the first part, do you really not know what "bad practice" means?
It means you can use it, but you'd probably be cutting yourself shorter than actually learning it yourself.

Also, what? C++ is not OO. You can use completely valid code, whether that be objects, structures, the main function isn't even in an object. JAVA is OO. As a professional programmer in both, Java AND C++, they're nearly identical in logic and all functions from java can be made the exact same to C++.

As someone who learns better reading ACTUAL code rather than "boring stuff here. This part won't help you but we'll include it. More hiring stuff you probably won't understand", I believe others learn better testing examples and runable code rather than pseudo code you'll never learn.

Hell, even my java and C++ books have actual code in them to read.



The only reason in my mind that you dislike, and feel the need to make me "feel threatened" of you is because I used to (yes, used to) hack on Graal.
How about minding your own business and taking that **** talker you call a mouth somewhere else. You're not wanted, nor needed, here and should dilly along to your pathetic life.

Motrox 11-26-2014 03:19 AM

Quote:

Posted by Tricxta (Post 520287)
@Motorox and any others who are wondering what I'm on about..
In object oriented languages, responsibility of each object should be specific and clear with each object's functions performing a clearly labelled task and nothing else. In fysez's example, one object's method is responsible for everything. This makes it unclear when debugging as to which component might have stuffed up. And.. what if we wanted to add something new!?
Yes, the scale of the code at the moment makes this scenario not as bad as you might think and this argument seem petty but, as with anything, this can easily grow out of hand.

Let's not fight guys..

Sorry if I missed some of the comments said up top. Hard to find things in blocks of text.

@Tricxta
I'm having some trouble comprehending so bare with me.
Are you saying to keep written code organized so you can go back and find things to add or fix? Like adding comments and such with //?

Also I went back into the calculator and I wanted to try focus on how functions use parameters.
It keeps printing 1 for the answer for some reason.

PHP Code:

// Additional Practice
#include <iostream>

using namespace std;

int addition (int aint b){
    
int sum b;
    return 
sum;
}


int main() {
 
int a,b;
 
int choice;
 
cout << "Add the first number" << endl;
 
cin >> a;
 
cout << "Add a second number" << endl;
 
cin >> b;
 
cout << "The summation of these two numbers would equal " << addition << endl;
 
 return 
0;



Also could someone explain the difference between endl and \n?
I see them both used for the same purpose I think.
When and why should I use one over the other?

Tricxta 11-26-2014 03:56 AM

Quote:

Posted by Motrox (Post 520379)
Let's not fight guys..

Sorry if I missed some of the comments said up top. Hard to find things in blocks of text.

@Tricxta
I'm having some trouble comprehending so bare with me.
Are you saying to keep written code organized so you can go back and find things to add or fix? Like adding comments and such with //?

Also I went back into the calculator and I wanted to try focus on how functions use parameters.
It keeps printing 1 for the answer for some reason.

PHP Code:

// Additional Practice
#include <iostream>

using namespace std;

int addition (int aint b){
    
int sum b;
    return 
sum;
}


int main() {
 
int a,b;
 
int choice;
 
cout << "Add the first number" << endl;
 
cin >> a;
 
cout << "Add a second number" << endl;
 
cin >> b;
 
cout << "The summation of these two numbers would equal " << addition << endl;
 
 return 
0;



Also could someone explain the difference between endl and \n?
I see them both used for the same purpose I think.
When and why should I use one over the other?

Endl versus \n : http://stackoverflow.com/questions/2...c-stdendl-vs-n
It all depends on the problem as to which you choose. For your application, it's preferable you stick with endl. As a general note, try keep away from inserting random symbols and numbers into your code and instead assign them to a meaningful constant's name that you'd use instead, this will be helpful after reading your code when you forget it.

For most of your programming questions, chances are someone has asked the same thing in the past and stackoverflow is great for that sort of thing :)

As for your code, you're not passing a parameter at all to your addition function. Try out
PHP Code:

additiona


Jatz 11-27-2014 03:30 AM

"using" an entire namespace is horrible practice. It is preferred to use only the members of the namespace you need, such as:

PHP Code:

using std::cout;
using std::endl

As tric said, you need to pass the parameters to your addition function, because a and b were declared in the local scope of the main function.

Also, you don't really need an addition function at all. here's how i'd write it:

PHP Code:

#include <iostream>

int main()
{
    
int xy;

    
std::cout << "Enter your first number\n";
    
std::cin >> x;
    
std::cout << "Enter your second number\n";
    
std::cin >> y;
    
std::cout << "The summation of these numbers is: " << << "\n";

    return 
0;


The trick to writing maintainable code is knowing the exact requirements of what you're trying to make, and not over-complicating your solution.

Writing a function to do basic arithmetic which is supported by the language natively is overkill.

If you need any c++ help at all, feel free to add me on skype: allofthegoodnamesaretaken101

Powder 11-27-2014 02:21 PM

Quote:

Posted by Ghettoicedtea (Post 516467)
Im pretty sure GS2 is based off of java c++ so you might have some help here

Yes, it's based off C++!

Jatz 11-27-2014 02:29 PM

Quote:

Posted by Powder (Post 520746)
Yes, it's based off C++!

No it's not. Please don't say things when you have absolutely no idea what you're talking about. GS2 is nothing like Java or C++. GS2 is most similar to JavaScript, which contrary to what the name suggests, is completely unrelated to Java.

C++ is the lowest level of the the languages (Closest to machine code) because it forces you to manage your own memory. It has the concept of pointers, while Java & Javascript do not, using references instead. C++ is static typed & follows C-Style syntax.

Java is a spiritual successor to C++ in that it follows the object oriented paradigm. It is Static typed & follows C-Style syntax.

JavaScript is the highest level language of the three, as the name suggests it is a scripting language (not a programming language) and is therefore interpreted by another application. (Oftentimes a browser written in c++). Javascript is dynamic typed, and while being based on C-Style syntax, differs slightly in some areas.


GS2 is barely an OOP language, it is more event driven in nature. (for example, the function onCreated() is called every time the script is initialized. GS2 has dynamic types, and a syntax nearly identical to Javascript.

Powder 11-27-2014 02:32 PM

Quote:

Posted by Jatz (Post 520752)
No it's not. Please don't say things when you have absolutely no idea what you're talking about. GS2 is nothing like Java or C++. GS2 is most similar to JavaScript, which contrary to what the name suggests, is completely unrelated to Java.

C++ is the lowest level of the the languages (Closest to machine code) because it forces you to manage your own memory. It has the concept of pointers, while Java & Javascript do not, using references instead. C++ is static typed & follows C-Style syntax.

Java is a spiritual successor to C++ in that it follows the object oriented paradigm. It is Static typed & follows C-Style syntax.

JavaScript is the highest level language of the three, as the name suggests it is a scripting language (not a programming language) and is therefore interpreted by another application. (Oftentimes a browser written in c++). Javascript is dynamic typed, and while being based on C-Style syntax, differs slightly in some areas.


GS2 is barely an OOP language, it is more event driven in nature. (for example, the function onCreated() is called every time the script is initialized. GS2 has dynamic types, and a syntax nearly identical to Javascript.


GraalOnline runs on C++... :blush:


All times are GMT. The time now is 07:56 PM.

Powered by vBulletin/Copyright ©2000 - 2026, vBulletin Solutions Inc.