• 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.

C++ Help?

Status
Not open for further replies.

d[-_-]b

Banned
Slavik81 said:
Visual Studio 2008 /w VisualAssistX. I loved Visual Studio for C#, but found it was garbage for C++. However, VisualAssistX fixes it, making it a great tool. Such an amazing plug-in.

On my laptop, I generally just use Notepad++ or gvim with some sort of build system. I haven't settled on one. Any recommendations? My only real experience has been with boost-build Jamfiles, and I hate them with such a passion.
How about VS2010?
Moving on to another topic, any gaf C++ workshops :O? I'd need practice, any ideas what I should do or where I should look?
 

barnone

Member
Can anyone recommend some supplemental c++ tutorials? Videos would be awesome. Taking my second semester of the language (my first foray into programming) and I'd like to read more about abstract data types, dynamic vs status binding, Liskov substitution principle, and other stuff about classes. Lecturer is all over the place, and my textbook is great for what it covers but it doesn't always have the material I am looking for.
 

usea

Member
barnone said:
Can anyone recommend some supplemental c++ tutorials? Videos would be awesome. Taking my second semester of the language (my first foray into programming) and I'd like to read more about abstract data types, dynamic vs status binding, Liskov substitution principle, and other stuff about classes. Lecturer is all over the place, and my textbook is great for what it covers but it doesn't always have the material I am looking for.
Your questions are more easily answered by a google search than I could explain.
- http://en.wikipedia.org/wiki/Liskov_substitution_principle (has nothing to do with c++ specifically)
- dynamic vs static binding is whether something is resolved at compile time or runtime. Google it, there are tons of explanations.
- As for abstract data type, you can read the wikipedia entry I guess. But I think that's just referring to an abstract class. That means that functions are defined, but not implemented. It's similar to the notion of an Interface in other languages.

If you need to learn more about object oriented programming in c++, try here: http://www.cplusplus.com/doc/tutorial/ specifically the Object Oriented Programming section.
 

The Technomancer

card-carrying scientician
I'm so proud GAF, despite the fact that I'm learning C++ from a 1300 page book by myself and I haven't even gotten to things like classes yet, I still managed to write a program that takes user input to form a matrix, and then runs transformations on each row until it reaches row eschalon form.
 

Toby

Member
I figure this is as good a place as any to ask this. I need to make an application that has a gui. Problem is, I have only ever done console applications. I know C++, comfortable with C#, and know very little Java (taking the class now).
I would like the application to run in a browser and be able to run on windows, linux, and mac OS. The obvious choice would be Java, but I have also been looking at developing with silverlight, as it also seems to fulfill my requirements.
So, are there any other options I should look at? Any opinions on the two I am looking at?
 

Haly

One day I realized that sadness is just another word for not enough coffee.
I'm not sure about Java but I know Visual Studio makes it very easy to make a Windows Form, as long as you're not looking to make custom graphical elements like buttons and whatnot.

There's a video tutorial here showing off some of the basic tools: http://www.youtube.com/watch?v=WgKZfIWLleg

As for web integration I have no clue.
 
Toby said:
I figure this is as good a place as any to ask this. I need to make an application that has a gui. Problem is, I have only ever done console applications. I know C++, comfortable with C#, and know very little Java (taking the class now).
I would like the application to run in a browser and be able to run on windows, linux, and mac OS. The obvious choice would be Java, but I have also been looking at developing with silverlight, as it also seems to fulfill my requirements.
So, are there any other options I should look at? Any opinions on the two I am looking at?

Try Flash + Actionscript or Javascript + Canvas.
 

wolfmat

Confirmed Asshole
Toby said:
I figure this is as good a place as any to ask this. I need to make an application that has a gui. Problem is, I have only ever done console applications. I know C++, comfortable with C#, and know very little Java (taking the class now).
I would like the application to run in a browser and be able to run on windows, linux, and mac OS. The obvious choice would be Java, but I have also been looking at developing with silverlight, as it also seems to fulfill my requirements.
So, are there any other options I should look at? Any opinions on the two I am looking at?
Another choice is to pick a browser and use its plugin system, and the associated language.

Not saying you should do that. You should do whatever matches your specific task.

So if you have a frontend-heavy task, for instance, you should pick a framework that makes it particularly effortless to handle that (especially when you're looking at the browser as a platform). If you need some hardcore CPU time with fast results, don't pick an interpreted language, or externalize that aspect to compiled stuff and poll results (for instance, you could use a server-client model and differentiate as said). Et cetera.

Basically, without knowing what exactly it is you want to do, it's hard to tell what's best for you.

JS GUI magic stuff is out there in droves. Usually does the job for prototyping, at the least. But there as well, it depends on what you want to do, as they have strengths and weaknesses.

Picking the right base to go from in terms of library code is something that you should put a lot of energy into. Do research, look at code, read feedback to frameworks, that kind of stuff.
 

hemtae

Member
Code:
void LListJar::remove(const Marble& m)
{
   list<Marble>::iterator i;

   for (i = ll.begin(); i != ll.end(); ++i)
      if (*i == m) {
         ll.erase(i); 
         break;
      }
}

bool LListJar::is_in_jar(const Marble& m) const{
	list<Marble>::iterator iter;

	for(iter = ll.begin(); iter!= ll.end(); ++iter) //error in this line
		if(*iter == m)
			return true;
	return false;
}

the compiler says everything is fine with the remove function while it says error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_List_const_iterator<_Mylist>' (or there is no acceptable conversion) with the equals sign underline for the is_in_jar function

Help?
 

Nerevar

they call me "Man Gravy".
Toby said:
I figure this is as good a place as any to ask this. I need to make an application that has a gui. Problem is, I have only ever done console applications. I know C++, comfortable with C#, and know very little Java (taking the class now).
I would like the application to run in a browser and be able to run on windows, linux, and mac OS. The obvious choice would be Java, but I have also been looking at developing with silverlight, as it also seems to fulfill my requirements.
So, are there any other options I should look at? Any opinions on the two I am looking at?

Wait, what? Generally browser-based precludes platform-centric development, unless you're building an IE6-targetted platform. Java is super easy, but J2EE (aka server-side Java) is kind of obnoxious and filled with annoying gotchas. It's really good to know though, most enterprises are either all-MS or some combination of Oracle / Java / Unix stack. Knowing both .NET and J2EE will really give you a leg up in the skills department.

For what you're looking to do I'd say you're pretty much looking at some kind of Flash or Javascript framework. Depending on what you want to do with your life (enterpise developer? Freelance website builder? Go join a startup?) that should dictate which route you go. Then you'll have to settle on a back-end, which will probably be dictated more by your hosting options than anything else. Google provides free J2EE hosting for low-volume apps on Google App Engine. PHP hosting is pretty ubiquitous and cheap. Good luck finding decent-priced Microsoft server hosting. etc etc. Just get your hands dirty, dont' be afraid to build something you're going to throw away, and have fun. That's really all you can do. I think you need to go in realizing that you will have to completely leave your console-centric / WinForms-centric development comfort zone and really learn a completely different way to build a UI. Web-based development is interesting and challenging, but can be really rewarding when done right.

Edit: rereading this thread makes me glad I don't do C++ development anymore. It reminds me of that essay I read a while ago about how great developers will inevitably spend 90% of their life miserable. Syntatic sugar makes life so much easier.
 

Lathentar

Looking for Pants
hemtae said:
Code:
void LListJar::remove(const Marble& m)
{
   list<Marble>::iterator i;

   for (i = ll.begin(); i != ll.end(); ++i)
      if (*i == m) {
         ll.erase(i); 
         break;
      }
}

bool LListJar::is_in_jar(const Marble& m) const{
	list<Marble>::iterator iter;

	for(iter = ll.begin(); iter!= ll.end(); ++iter) //error in this line
		if(*iter == m)
			return true;
	return false;
}

the compiler says everything is fine with the remove function while it says error C2679: binary '=' : no operator found which takes a right-hand operand of type 'std::_List_const_iterator<_Mylist>' (or there is no acceptable conversion) with the equals sign underline for the is_in_jar function

Help?

is_in_jar is a const function. You should be using a const_iterator! Calling ll.begin will try to return a const_iterator, but you're trying to assign to an iterator. Fail. If you're using a recent compiler just do for( auto iter = ll.cbegin(); ...

Redoing this code!
Code:
void LListJar::remove(const Marble& m)
{
   ll.remove( m );
}

bool LListJar::is_in_jar(const Marble& m) const
{
   return std::find( ll.begin(), ll.end(), m ) != ll.end();
}
 

hemtae

Member
Lathentar said:
is_in_jar is a const function. You should be using a const_iterator! Calling ll.begin will try to return a const_iterator, but you're trying to assign to an iterator. Fail. If you're using a recent compiler just do for( auto iter = ll.cbegin(); ...

Redoing this code!
Code:
void LListJar::remove(const Marble& m)
{
   ll.remove( m );
}

bool LListJar::is_in_jar(const Marble& m) const
{
   return std::find( ll.begin(), ll.end(), m ) != ll.end();
}

Thank you so very much
 
Hey Gaf, I got a bit of coding help. Sadly I've spent years lurking and never posting unless I had something meaningful to say so I cannot put this in its own thread. This is for a class and this teacher actually uses these programs for research purposes if they are good so I am actually trying to make this efficient. So here it goes:


I have to write a program that runs on a Cluster using MPI that will find all of the prime numbers from 1 to N. N's value should be 1million - 10trillion. We are using the prime number sieve algorithm to accomplish this. I don't need help with the coding yet I more need help with the algorithm design on how to make this algorithm work on a cluster. The main reason is I am trying to keep communication over head down. It is 1gigabit symmetrical connection but I think swapping the entire list between max of 16 nodes out and back in then merging them could hurt processing time.

(8nodes for these examples but its variable from 2-16)

So my main issue is sure I could take the first 8 prime numbers I know, and send them to the 8 nodes and have it do the Prime numbers sieve algorithm on it. Then have the entire array of 10 trillion numbers sent back from all 8 nodes to one and merge them then redistribute and do it again.

I would just have to have P^2 primes to accomplish this so it would be (P^2/number of nodes) swaps to do. Does anyone see a more efficient way than sending these lists back and forth since they are so big? Also these nodes are independent so there is not shared memory just MPI.

Maybe I should send like the first 50 uncrossed out integers back from each node and have one node eliminate the primes that do not appear in all the lists then spam out that set of primes for the nodes to do the sieve with again.

If you have a great idea on how to accomplish this i can PM you my IM handle or skype name also if that's easier than typing out a reply. Thanks Gaf

tl;dr
algorithm tweaking for parallel processing
if your good at math or cs please help

edit: nvm I think I figured out an easier way to do this. But if anyone has any awesome suggestions let me know.
 

Linkhero1

Member
I need help with my code. My instructor wants us to create a program that takes what the user types and display it on screen. When the user enters a flag he wants our program to state that a flag has been detected. The user keeps entering whatever they want until the end flag is detected. My problem is that I want to write a bool if else statement but I'm not sure how to do it using getch();

Code:
	cout << "Please enter anything [Type 01111110 to start flag and end flag]: ";
	
	while (count < 2)
	{
		for (i = SIZE-1; i > 0; i--)
			buff[i] = buff[i-1];
	
	putchar((buff[0] = getch()));
 

Chichikov

Member
Linkhero1 said:
I need help with my code. My instructor wants us to create a program that takes what the user types and display it on screen. When the user enters a flag he wants our program to state that a flag has been detected. The user keeps entering whatever they want until the end flag is detected. My problem is that I want to write a bool if else statement but I'm not sure how to do it using getch();

Code:
	cout << "Please enter anything [Type 01111110 to start flag and end flag]: ";
	
	while (count < 2)
	{
		for (i = SIZE-1; i > 0; i--)
			buff[i] = buff[i-1];
	
	putchar((buff[0] = getch()));
I'm not sure I fully understand your question.
What is a flag? just a special character?
Also, what do you mean by 'a bool if else statement'?

But to answer the question I think you may have asked -
getch() just return a number (which in c is how characters are stored), so you can just write -

Code:
if ('a' == getch())
   <do something>
else
   <do something else>

Also, I really don't get your loop, what are you trying to do there?
 

poweld

Member
Linkhero1 said:
I need help with my code. My instructor wants us to create a program that takes what the user types and display it on screen. When the user enters a flag he wants our program to state that a flag has been detected. The user keeps entering whatever they want until the end flag is detected. My problem is that I want to write a bool if else statement but I'm not sure how to do it using getch();

Code:
	cout << "Please enter anything [Type 01111110 to start flag and end flag]: ";
	
	while (count < 2)
	{
		for (i = SIZE-1; i > 0; i--)
			buff[i] = buff[i-1];
	
	putchar((buff[0] = getch()));
Is this a troll? This makes almost no sense. What is the flag? When are you incrementing count? What does count represent?
 

Linkhero1

Member
It's not a troll. I have no reason to troll. I'm just really terrible at programming. I didn't have the problem on me to describe it well enough. Once I get home I'll PM you Chichikov because you seem to get the jest of what I'm asking. I didn't post the full code but I will when I get home. It's in C and I'm attempting to rewrite it in C++. It doesn't use any loops but I want to write it that way.
 

dogmaan

Girl got arse pubes.
I have an exam tomorrow and this was on the practice test, apparently I got the question wrong :lol

Which one of the following statements is correct?

A cache hit is when:

Selected Answer: the desired instruction is found in cache and main memory doesn't need to be
accessed.


Correct Answer: an instruction expected in cache is not found and an error is generated.



I have found quite a few questions like that :\
 

poweld

Member
Linkhero1 said:
It's not a troll. I have no reason to troll. I'm just really terrible at programming. I didn't have the problem on me to describe it well enough. Once I get home I'll PM you Chichikov because you seem to get the jest of what I'm asking. I didn't post the full code but I will when I get home. It's in C and I'm attempting to rewrite it in C++. It doesn't use any loops but I want to write it that way.
In that case, if you're looking to print out individual characters:
Code:
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	char flag = '?';

	cout << "Enter character:";
	char c = getchar();
	while (c != flag) {
		cout << c << endl;
		c = getchar();
	}
	return 0;
}
...or if you want to get linefeed-terminated strings:
Code:
#include <iostream>
using namespace std;

int main(int argc, char** argv) {
	string flag = "???";
	string s;
	
	cout << "Enter word:";
	cin >> s;
	while (s.compare(flag) != 0) {
		cout << s << endl;
		cout << "Enter word:";
		cin >> s;
	}
	return 0;
}
 

TheExodu5

Banned
dogmaan said:
I have an exam tomorrow and this was on the practice test, apparently I got the question wrong :lol





I have found quite a few questions like that :\

Huh? You were right on the money...what gives? Their 'correct' answer would be a cache miss. =\
 
Slavik81 said:
I have an actual VS2008 licence. If I switched to 2010 I'd have to buy a VS2010 professional licence, and they're expensive.
MSDNAA.

Join IEEE like the rest of us cool kids and download to your hearts delight!
 
Okay, so this is a simple problem that I just can't figure out for the life of me atm. I have this program that lets you assign names to up to 5 people. My problem is that the program always skips the first assignment.

#include <iostream>
#include <string>
using namespace std;

string getName()
{
string name;
cout<<"Enter the name of the player : ";
getline(cin,name);
return name;
}
int main()
{
int no_of_players;
cout << "Enter the number of players: ";
cin >> no_of_players;
string players[5];
for (int x=0; x<no_of_players;x++)
players[x]=getName();
return 0;
}

This is what I get.
KY92R.png

What am I overlooking?
 

Slavik81

Member
Dreams-Visions said:
MSDNAA.

Join IEEE like the rest of us cool kids and download to your hearts delight!
I finished my degree in '09, and my IEEE student membership expired January 2010. These days, I'm a 'professional'.

It's kind of too bad that VS2010 dropped the standard edition. The price of entry is a lot higher these days if you want plug-in support... And you're not a student.
 

Lathentar

Looking for Pants
dragonballjoseph said:
Okay, so this is a simple problem that I just can't figure out for the life of me atm. I have this program that lets you assign names to up to 5 people. My problem is that the program always skips the first assignment.



This is what I get.
KY92R.png

What am I overlooking?
You're grabbing the newline character of the "number of players" line. Do a get line after the player enters the number of players.
 

Toby

Member
#include <iostream>
#include <string>
using namespace std;

string getName()
{
string name;
cout<<"Enter the name of the player : ";
getline(cin,name);
return name;
}
int main()
{
int no_of_players;
cout << "Enter the number of players: ";
cin >> no_of_players;
string players[5];
cin.ignore();
for (int x=0; x<no_of_players;x++)
players[x]=getName();
return 0;
}
newline still in input buffer, can add ignore there, fixes problem
 

poweld

Member
dragonballjoseph said:
Okay, thanks. ^_^
You will encounter a stack overflow if >5 players are entered. Instead of a string array (string players[5]), you would be better off using a vector<string> (vector<string> players) and using the push_back member function. vectors will perform dynamic allocation for you so you will avoid such issues.
 

AcciDante

Member
Hey duders. This is my second semester of learning C++, and I like to think I've got a pretty good grasp of the language, so I'd like to try another language out. All I've made so far is console applications in C++, so I'd like to try something graphical. I hear C# is a good one? Any recommendations on languages and books?
 

CrankyJay

Banned
C# is fine. You don't need a book. Just follow tutorials online.

You can write windows apps in C#. Download Visual Studio 2010 Express from Microsoft. It's free.

If you want to get into more highly customizable shit, then you can combine WPF (Windows Presentation Foundation) with C# as the background code, but that would require you to learn XAML (which isn't all that hard in my opinion).
 

AcciDante

Member
CrankyJay said:
C# is fine. You don't need a book. Just follow tutorials online.

You can write windows apps in C#. Download Visual Studio 2010 Express from Microsoft. It's free.

If you want to get into more highly customizable shit, then you can combine WPF (Windows Presentation Foundation) with C# as the background code, but that would require you to learn XAML (which isn't all that hard in my opinion).
Any good tutorial recommendations? I have Visual Studio 2010 Professional thanks to MS's dreamspark program.
 

AcciDante

Member
The assignment I'm doing now has a whole bunch of classes inheriting from a base class, so I don't want to post all that here, but I'm having issues using base class pointers. I have an abstract base class, then two children of that abstract base. I should be able to use a base pointer to hold the children objects, right? I know this isn't very descriptive, but I could use some general tips on using abstract classes.
 

Chichikov

Member
AcciDante said:
The assignment I'm doing now has a whole bunch of classes inheriting from a base class, so I don't want to post all that here, but I'm having issues using base class pointers. I have an abstract base class, then two children of that abstract base. I should be able to use a base pointer to hold the children objects, right? I know this isn't very descriptive, but I could use some general tips on using abstract classes.
Yes you should be able to, that's the very basis of polymorphism.
What issues do you have?

Edit: wikipedia has a nice code sample that might help you.
 
AcciDante said:
That's a good example on that page. I have that kind of set up working, the problem comes from calling a function that would only be in the cat class. Let's say the cat class had a function called purr(). How would you call purr() from the base class pointer?

You don't. You have a design problem if that's the case. The point of passing around a base class is because the things operating on it are GENERIC in the sense that they operate on any kind of thing that might derive from it. Let's say the base class is animal and derived is cat. Then the things you're passing around animal* pointers to should only care about animals. If they're telling something to purr then the design is wrong because not all animals can purr. What would happen if you passed in a dog*?
 

Chichikov

Member
AcciDante said:
That's a good example on that page. I have that kind of set up working, the problem comes from calling a function that would only be in the cat class. Let's say the cat class had a function called purr(). How would you call purr() from the base class pointer?
You can't, that function does not exist in the base class.
Think about it for a second, Animal pointer can be a Dog, what would happen if you try to call Purr on a dog?

You need to cast it to a Cat pointer.

And now would be a good time to familiarize yourself with dynamic_cast (if you haven't done so already).

Though in all honesty, a good real world design should usually avoid relying on casting in C++.
 
Chichikov said:
You can't, that function does not exist in the base class.
Think about it for a second, Animal pointer can be a Dog, what would happen if you try to call Purr on a dog?

You need to cast it to a Cat pointer.

And now would be a good time to familiarize yourself with dynamic_cast (if you haven't done so already).

Please don't suggest this. His design is fucked up, don't teach him how to get around bad designs with dynamic_cast this early on in his programming career.
 

Chichikov

Member
cpp_is_king said:
Please don't suggest this. His design is fucked up, don't teach him how to get around bad designs with dynamic_cast this early on in his programming career.
You're right, I added a line to my post.
It just kinda hard to show the right design when dealing with something as abstract as cats and dogs classes.
 
Chichikov said:
You're right, I added a line to my post.
It just kinda hard to show the right design when dealing with something as abstract as cats and dogs classes.

Yea if he gave more details about why he wanted to call purr() on an animal pointer it might help tell him how to fix it.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Would it work if he had a function in his base class called "makeNoise()" and then implemented that function differently in Class Cat and Class Dog?
 
Status
Not open for further replies.
Top Bottom