• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Jokab

Member
Is there any resource that teaches that? And isn't that something that's apart of C# and C++?

Any beginner book on an object-oriented language (Java, C++, C# to name a few) will thoroughly teach you OOP. And yes, C# and C++ are definitely very object-oriented.
 

Onemic

Member
Any beginner book on an object-oriented language (Java, C++, C# to name a few) will thoroughly teach you OOP. And yes, C# and C++ are definitely very object-oriented.

Well I'm currently going through the Javascript course at codeacademy, would that be enough or would it be best to use more resources?
 

squidyj

Member
recursion is kicking my ass

D:

Recursion is a joy!, a joy!

oh Haskell!

But seriously what's troubling you?


pompidu..... It looks like all that happens when you press the search button right now is it grabs whatever is in your text fields into a number of Strings and does nothing with that data.
seems like you want to take that string data, convert it to double or int, use that to build a criteria and use your new criteria to print a selection of houses to. thankfully there's a handy method in the Integer wrapper class and one just as good for doubles.

Integer.parseInt(String s)
Double.parseDouble(String s)

which takes a string and returns its integer value.

I might also add that as per your tester class you don't really need to declare labels for those criteria.

houseList.printHouses(new Criteria (1000, 505000, 100, 5000, 0, 10)); //valid instruction
 
Well I'm currently going through the Javascript course at codeacademy, would that be enough or would it be best to use more resources?

If Edsger Dijkstra were alive today, he might update his quote to say "It is practically impossible to teach good programming to students that have had a prior exposure to BASIC Javascript: as potential programmers they are mentally mutilated beyond hope of regeneration."
 
Anyone in C++ know the variable for the value of Pi (3.14....)? The book doesn't have it and I have to use it to do one of the equations/programs in the book.
 

Slavik81

Member
Anyone in C++ know the variable for the value of Pi (3.14....)? The book doesn't have it and I have to use it to do one of the equations/programs in the book.
There's no official constant for it, but you might find M_PI in math.h

On Windows with Microsoft's headers there's a define you need to enable, too: _USE_MATH_DEFINES
 
You could define a constant with the double PI = 22/7. It's an approximation, but it will work.



Not in standard C++ or C from what I was able to gather.

I think under <math.h> it's listed as M_PI

or use atan(1) * 4 and cache it that way.

There's no official constant for it, but you might find M_PI in math.h

On Windows with Microsoft's headers there's a define you need to enable, too: _USE_MATH_DEFINES

Thanks for the replies, since there's no variable I can draw off from predetermined library I just decided to set it as a constant double at 3.14159, hopefully that works.
 
Noob question incoming:
Do I always have to initialize a new scanner if I want to read a different input from the user or can I use the same one?
Example:
Scanner sc = new Scanner(System.in);
System.out.println("How many items do you want?");
order= sc.nextInt();
System.out.println("would you like express shipping?");
Scanner ans = new Scanner(System.in);
answer=ans.nextLine();
if (answer.equals("yes")){
//rest of code
I had to add the second scanner because it wouldn't let me type something in before in the command prompt.

And the main methods can't access instance variables? Only locals, right? Just want to be sure.
 

Lkr

Member
we're making a cash register program as an assignment. anyway, my problem is that when making a case for store credit, i set tax to 0, price and total are the same value for this. everything is fine. everything is a double stored in the array. when i go to print, it prints out price and tax just fine, but it prints total as say 10.00 and then prints a memory address right next to it. only happens here, if i do a normal item everything is fine. setprecision doesn't help either. i know this is very vague, but i'm pretty upset about this
 

Godslay

Banned
we're making a cash register program as an assignment. anyway, my problem is that when making a case for store credit, i set tax to 0, price and total are the same value for this. everything is fine. everything is a double stored in the array. when i go to print, it prints out price and tax just fine, but it prints total as say 10.00 and then prints a memory address right next to it. only happens here, if i do a normal item everything is fine. setprecision doesn't help either. i know this is very vague, but i'm pretty upset about this

Show us some code. Sounds like you are outputting the address rather than the value at the address.
 

Lkr

Member
Show us some code. Sounds like you are outputting the address rather than the value at the address.

is there a reason it would only happen with the credit option though? its the same exact code for every other type of item, the only difference being that if it is credit that the tax is 0 and the total and price variables have the same value. i'm just printing it through a for loop

Code:
for(int i = 0; i < Size; i++
{
  cout << MyArray.Price() << " " << MyArray.Total();
}

Price and Total are just functions that return the value of a private variable
 
is there a reason it would only happen with the credit option though? its the same exact code for every other type of item, the only difference being that if it is credit that the tax is 0 and the total and price variables have the same value. i'm just printing it through a for loop

Code:
for(int i = 0; i < Size; i++
{
  cout << MyArray.Price() << " " << MyArray.Total();
}

Price and Total are just functions that return the value of a private variable

We need more code than that. What is MyArray storing? Is it an array of objects that you are using to store a transaction?
 
is there a reason it would only happen with the credit option though? its the same exact code for every other type of item, the only difference being that if it is credit that the tax is 0 and the total and price variables have the same value. i'm just printing it through a for loop

Code:
for(int i = 0; i < Size; i++
{
  cout << MyArray.Price() << " " << MyArray.Total();
}

Price and Total are just functions that return the value of a private variable


Is that an actual code snippet? Because you are missing an ending parenthesis in the for loop after i++ and you aren't even using the variable to traverse the array. Don't you need MyArray.Price() and so on...
 

Godslay

Banned
Is that an actual code snippet? Because you are missing an ending parenthesis in the for loop after i++ and you aren't even using the variable to traverse the array. Don't you need MyArray.Price() and so on...


In addition to this, how are you storing the size for the loop? Just to make sure it is looping through all the items.
 

Lkr

Member
Is that an actual code snippet? Because you are missing an ending parenthesis in the for loop after i++ and you aren't even using the variable to traverse the array. Don't you need MyArray.Price() and so on...


no, i just typed an example of my code. i really can't post it because they'll scan for plagarism crap. basically i call everything fine in the program.
there are four types of transactions that can be made. for the other three, everything works fine using the same method. for this fourth one, it just randomly prints a memory address after it prints the correct value. i'll probably have my teacher look at it tomorrow, it is just driving me crazy, sorry
c++, and the CurrentSize stores the size of the array(it is dynamic)
 
Noob question incoming:
Do I always have to initialize a new scanner if I want to read a different input from the user or can I use the same one?
Example:

You can generally use the same one...however nextInt and nextLine do not mix well. Basically nextInt does not consume the whole line (the carriage return at the end).

A good practice is to only use nextLine (and turn it into an int if required), or to have two scanners, one for lines and one for ints. Otherwise it all gets pretty messy .

And the main methods can't access instance variables? Only locals, right? Just want to be sure.

Locals and static variables.
 

Vic

Please help me with my bad english
Finally figured out how to run a basic C++ program on Linux. This is promising!
 

Godslay

Banned
no, i just typed an example of my code. i really can't post it because they'll scan for plagarism crap. basically i call everything fine in the program.
there are four types of transactions that can be made. for the other three, everything works fine using the same method. for this fourth one, it just randomly prints a memory address after it prints the correct value. i'll probably have my teacher look at it tomorrow, it is just driving me crazy, sorry
c++, and the CurrentSize stores the size of the array(it is dynamic)

What is the memory address it is outputting? I wonder if you are going one too far on your array?

For example, this:

Code:
int myArray [3];

	for (int i= 0; i < 3; i++)
	{
		myArray[i] = i;
	}

	for (int i = 0; i < 4; i++)
	{
		cout << " " << myArray[i];
	}

Will output this:

iFTp9639nQoOD.png
 
no, i just typed an example of my code. i really can't post it because they'll scan for plagarism crap. basically i call everything fine in the program.
there are four types of transactions that can be made. for the other three, everything works fine using the same method. for this fourth one, it just randomly prints a memory address after it prints the correct value. i'll probably have my teacher look at it tomorrow, it is just driving me crazy, sorry
c++, and the CurrentSize stores the size of the array(it is dynamic)


Did you overload your transaction class constructor?

Can you post examples of the signatures and what you are passing in when creating a credit transaction?

Edit - try setting tax to 0.0 instead of 0
 

Godslay

Banned
Did you overload your transaction class constructor?

Can you post examples of the signatures and what you are passing in when creating a credit transaction?

Edit - try setting tax to 0.0 instead of 0

I think we lost him! I agree though something is either not getting initialized, or he is going looping beyond the bounds of the array and outputting garbage. At least that would be my guess without being able to see the actual innards.
 
For the first time, I am almost completed with a game in Java (yay), but after this, I really want to learn C.

For some strange reason, Java is easy, Python is easy, and (6502) ASM is easy and fun from my limited time with it, but I am having problems learning C and especially C++. I have no idea what it is that bothers me about those languages...

Did/does anyone else feel that way?
 
For the first time, I am almost completed with a game in Java (yay), but after this, I really want to learn C.

For some strange reason, Java is easy, Python is easy, and (6502) ASM is easy and fun from my limited time with it, but I am having problems learning C and especially C++. I have no idea what it is that bothers me about those languages...

Did/does anyone else feel that way?


Nope, I found both C ad C++ straight forward and simple while programming languages like Java to be bloated.

Although I'm now a Java programmer for a living, still prefer C++.
 
Nope, I found both C ad C++ straight forward and simple while programming languages like Java to be bloated.

Although I'm now a Java programmer for a living, still prefer C++.

Did you start with Java? If you did I think C and C++ are quite difficult to wrap your head around. Pointers especially are a stumbling block for people going back.
 
Did you start with Java? If you did I think C and C++ are quite difficult to wrap your head around. Pointers especially are a stumbling block for people going back.


No, I started with C then moved on to C++

What frustrated me when learning Java are all the hoops you have to jump through to get things accomplished, especially things that are relatively easy to do in C or C++.

Once you understand and get use to how things are done in Java, it's an awesome language.
 
I understand the pointers. I haven't had much hands-on time with C, so I'm no expert, but... I guess there's just something about the language and the way people use it that seems intimidating and complicated.
 
Nope, I found both C ad C++ straight forward and simple while programming languages like Java to be bloated.

Although I'm now a Java programmer for a living, still prefer C++.

Say what you will about Java vs C++, but the latter is definitely an extremely bloated language.

Come to think of it, I believe this is the first time I have ever heard anyone call C++ "straight forward and simple" compared to Java.
 

Slavik81

Member
For the first time, I am almost completed with a game in Java (yay), but after this, I really want to learn C.

For some strange reason, Java is easy, Python is easy, and (6502) ASM is easy and fun from my limited time with it, but I am having problems learning C and especially C++. I have no idea what it is that bothers me about those languages...

Did/does anyone else feel that way?
The things I had trouble with:
- symbol linkage
- implicit type promotions
- special rules for c-style arrays
- poor compiler error messages, especially for templates

Years later I still think a lot of these are the fault of the language and the tools. Clang and C++11 are fixing some things, but a lot of it runs deep into the language.

Still I do like them. I've learned the idiosyncrasies now, so I've paid that cost. I feel like I mostly understand what is happening when I use C++, so I'll likely use it for a long time to come.
 

Anson225

Member
i'm trying to teach myself programming, but i don't have any previous experience. which would be an appropriate language for me to start with and lay a good foundation? thanks
 

Lonely1

Unconfirmed Member
I suddenly found myself giving a class on programing and I fell that my performance is less than satisfactory.

They are third year students on CS, so they are supposed to know their way around programming by know. So, the approach I took was to prepare examples on how to do things that I consider that are relevant in order to understand the language and paradigm (functional). I even code some traps inside my code in order to ask them questions like "Can anyone tell my why doing that is a bad idea? How can we improve it?" Yet, I barely get any feedback. I feel trapped in dull monologue, reading and trying to explaining line of code after line of code, without any hint if my explanation terrible.

Doesn't help that I didn't payed attention to my programing courses when I was a student, since I preferred a hands on approach. You can say I considered the courses I took almost as dull as my own.

Any tips, programming GAF?
 
In C, does anyone know how to make a void type function return a reversed string to main? I just can't get this working properly. And I can't use any string functions.
 
In C, does anyone know how to make a void type function return a reversed string to main? I just can't get this working properly. And I can't use any string functions.

I haven't tested this, but something like this should work.

Code:
void reverse(char* s)
{
	char* p = s;
	int len = 0;
	char c;

	while (*p++)
	    len++;
			
	for (int i = 0, j = len-1; i < j; ++i, --j) {
	    c = s[i];
	    s[i] = s[j];
	    s[j] = c;
	}
}
 

squidyj

Member
I suddenly found myself giving a class on programing and I fell that my performance is less than satisfactory.

They are third year students on CS, so they are supposed to know their way around programming by know. So, the approach I took was to prepare examples on how to do things that I consider that are relevant in order to understand the language and paradigm (functional). I even code some traps inside my code in order to ask them questions like "Can anyone tell my why doing that is a bad idea? How can we improve it?" Yet, I barely get any feedback. I feel trapped in dull on a monologue, reading and trying to explaining line of code after line of code, without any hint if my explanation terrible.

Doesn't help that I didn't payed attention to my programing courses when I was a student, since I preferred a hands on approach. You can say I considered the courses I took almost as dull as my own.

Any tips, programming GAF?

I have seen first hand some attempts to get students involved. It always turned out awkward and embarrassing. Personally I wouldn't mind learning from lectures if it wasn't so goddamn slow, I read a good set of lecture notes in 15 minutes, maybe there's a problem in there I work out and I already know the lecture better than I would have if I had sat in the class and listened to the professor talk for an hour.

I know why I don't want to say shit in class, First of all I don't want to be wrong, second of all I don't want to be that guy with all the answers, third, I'm probably not even paying attention to your lecture and am currently browsing NeoGAF on my laptop, sorry.

-Signed, 3rd Year Comp Sci student currently taking Paradigms.
 
Top Bottom