sarehu 84 Posting Whiz in Training

The length of N is 1 + floor(log_2(N)).

sarehu 84 Posting Whiz in Training

And here are some naive answers.

1. Type checking proves properties about the code. The compiler proves your assertion that your function returns an int, or that it returns something whose type depends on the types of the arguments in some way. They can also prove other claims you make about your functions, like whether they throw any exceptions (which Java supports) or what side effects the functions may have (which Haskell supports, albeit without any granularity). Regarding network I/O, searching for things like "monad", "linear types", "uniqueness types", and maybe "session types" might reveal some more information.

2. You can read about lambda calculus on Wikipedia, and I don't know its relationship to formal methods.

sarehu 84 Posting Whiz in Training

MSDN has information on having multiple threads in C#. It's fairly straightforward.

sarehu 84 Posting Whiz in Training

Take undergrad classes in the subjects to figure out what you're interested in.

common programming languages used for each field

It should be easy to pick up whatever programming languages you need when you get to them.

sarehu 84 Posting Whiz in Training

Everybody is behind on technology. Everybody in the world.

Alex Edwards commented: I Agree with this somewhat. Technology is always advancing, and improving systems to keep up with technology is costly. Since there isn't an infinite amount of money to upgrade systems all the time, it stands to reason that everyone is behind! +3
sarehu 84 Posting Whiz in Training

The phrase "if the country is technologically advanced enough to program the script that I am asking for" is completely nonsensical. What are you even talking about.

sarehu 84 Posting Whiz in Training

This question was answered in the IRC channel.

sarehu 84 Posting Whiz in Training

personPtr?

vector<Person*> passengers;  // initializes to an empty vector.
sarehu 84 Posting Whiz in Training

To address your first issue: void pointers. Google it. It's basically a pointer that has no type bound to it. I haven't used them too much but I think they fit your needs.

Dumb dumb dumb dumb dumb dumb dumb dumb what the hell are you talking about.

klactose, the solution is to start with an empty vector and use push_back, which adds a value to the end of the vector (and increases its size() by one).

sarehu 84 Posting Whiz in Training

How large is X? What is the type of your large number? 0.00012354584 is actually quite small :D

sarehu 84 Posting Whiz in Training

This isn't really a C++ question, more of a C++/CLI question, which is a separate language.

But if you looked in the System.String documentation, you'd see the answer: http://msdn.microsoft.com/en-us/library/ezh7k8d5.aspx

Your real problem is that you're using std::string in the first place -- if you're going to be creating a System::String^, create it directly.

sarehu 84 Posting Whiz in Training

Accelerated C++ (by Koenig and Moo) is seconded.

sarehu 84 Posting Whiz in Training

You will not know only three languages. There is no way. You will end up accidentally having to write a few SQL queries, then some build scripts, editor customizations, web server configurations, XML transformations, ...........

And before you know it, you'll have learned too many languages! Time to bang your head against the wall so that you can go back down to three.

sarehu 84 Posting Whiz in Training

That doesn't even make sense. You're talking about a function, not a module, and you're talking about finding a sum when only one argument has been passed.

sarehu 84 Posting Whiz in Training

We don't understand. xxxx is a variable. What does that have to do with modules?

sarehu 84 Posting Whiz in Training

There is no universal definition of 'module'. Ask your professor for details.

sarehu 84 Posting Whiz in Training

No, that just makes things more complicated. If you're never going to use a custom allocator, it doesn't make any sense to do that extra work.

sarehu 84 Posting Whiz in Training

I guess you could write template <class> class Container . For whatever reason, template <typename> typename Container will not work. I guess it's because there's no such thing as a "template <typename> typename", but there is such a thing as a "template <typename> class". template <class> class Container says that Container is a templated class. That Container<T> would be the actual name of a type.

sarehu 84 Posting Whiz in Training

In C99, the latest C standard, that would be legal. (Well, not the "vector.size()", but the runtime initialization of the array size.) You can use

scoped_array<node> nodes_array(new node[vector.size()]);

instead -- if you have the boost libraries installed.

sarehu 84 Posting Whiz in Training

The thing is, I would prefer this design:

template <typename T, template <typename> class Container>
int my_func(std::map<T, Container<T> > arg) {
  typedef std::map<T, Container<T> > Map;
  typedef typename Map::iterator Iter;
  typedef typename Container<T>::iterator CIter;

  int count = 0;
  Iter end = arg.end();
  for (Iter p = arg.begin(); p != end; ++p) {
    std::cout << "Key: " << p->first << "\n";
    CIter value_end = p->second.end();
    for (CIter q = p->second.begin(); q != value_end; ++q) {
      count = count + 1;
      std::cout << "  " << *q << "\n";
    }
  }
  return count;
}

It more clearly describes what you're doing, since you know you're expecting a map<T, container<T> >.

sarehu 84 Posting Whiz in Training

Here's an example that does directly what you want:

template <typename T>
int my_func(T& arg) {
  int count = 0;
  typename T::iterator end = arg.end();
  for (typename T::iterator p = arg.begin(); p != end; ++p) {
    std::cout << "Key: " << p->first << "\n";
    typename T::mapped_type::iterator value_end = p->second.end();
    for (typename T::mapped_type::iterator q = p->second.begin(); q != value_end; ++q) {
      count = count + 1;
      std::cout << "  " << *q << "\n";
    }
  }
  return count;
}


int main() {
  std::map<std::string, std::vector<std::string> > m;
  std::vector<std::string> x, y;
  x.push_back("hello");
  x.push_back("good day");
  x.push_back("hey");
  y.push_back("what");
  y.push_back("okay");

  m.insert(std::pair<std::string, std::vector<std::string> >("x", x));
  m.insert(std::pair<std::string, std::vector<std::string> >("y", y));

  int n = my_func(m);
  std::cout << n << std::endl;
}
sarehu 84 Posting Whiz in Training

1. Assume a growing, subset tree that both Kruskal and MST have in common.
2. Look at the first edge "e" = (x,y) added by Kruskal that does not yield an MST (vertex x is in common subset, vertex y is not).

What do you mean by "the first edge added by Kruskal that does not yield an MST?" Every edge added by Kruskal's algorithm does not yield a minimum spanning tree, _except_ for the last edge added. What do you mean by "first"?

Also, in step one, you refer to a subset tree that both "Kruskal and MST have in common." What does 'Kruskal' mean in this sentence? Kruskal is the name of a person or the name of an algorithm. You're referring to a subset tree that Kruskal's algorithm is in the process of building?

I am being pedantic, but your wording must be precise if you are to convince yourself that you're thinking clearly. And you should always be critical of your wording.

3. The MST must eventually reach y using an edge "f" not in Kruskal (MST + e form a cycle with edge f in MST).
4. Since f came after e, it must be that cost f >= cost e.
5. Since MST + e froms a cycle through y, replace f with e in the MST and you still have an MST
6. Repeat process and eventually the MST morphs into Kruskal

You're using the word …

sarehu 84 Posting Whiz in Training

It "works" because the pointers were the same, because the compiler decided that it didn't need two immutable arrays that had the same contents.

sarehu 84 Posting Whiz in Training

Well, it is possible that using == there will get the right answer, maybe, in that particular case, because the constant string literals "hello" and "hello" could evaluate to the same pointer if the compiler is smart enough.

sarehu 84 Posting Whiz in Training

That code is broken: you're iterating off the end of the string.

sarehu 84 Posting Whiz in Training

Simulate your code by hand with an example input and find out. Is test_string.length supposed to be test_string.size() ?

sarehu 84 Posting Whiz in Training

One very convenient way to test this is with a regular expression, ^\d+$ and ^\d+\.\d+$ in this case. However, that would require the installation of a library for that purpose. But if you ever get this problem while using Perl or Ruby, that would be the solution.

In the case of C++, in your situation, you'll have to use a loop to test each element in test_string to see if it's a digit. That's not actually a big deal, is it? You know that x is a digit if '0' <= x && x <= '9' . Have it count the number of times it sees a '.' -- if the number grows past 1, you have an invalid string. If any characters are neither a digit nor '.', you have an invalid string. Otherwise, the result depends on whether you've seen a decimal point or not.

sarehu 84 Posting Whiz in Training

Think about the types of the values you are using. Does strlen(getlast) really make sense? strlen expects a value of type char* , and you're giving it getlast .

sarehu 84 Posting Whiz in Training
void punchmeinthehead()
{
	const int maxin = 16;
	char lastName[maxin] ;
	char firstName[maxin] ; 
	char midName[maxin] ;

The problem here is that these aren't the same arrays that were declared in the main function. Just because they have the same name doesn't mean they will be the same arrays. In fact, they won't be.

The idea being that you don't want to have to keep track of what names have been given for variables in other parts of your program, C code sees the existence of a given variable only with that variable's block. If you write your punchmeinthehead function as the following, you'll get the same exact behavior. (Note that I've only changed the local names around.)

void punchmeinthehead()
{
	const int maxin = 16;
	char lastBlah[maxin] ;
	char firstBlah[maxin] ; 
	char midBlah[maxin] ;
	
	size_t length = strlen(lastBlah) + strlen(firstBlah) + strlen(midBlah) + 1;
	char  *fullName = new char[length];
	strcpy (fullName, lastBlah);
	strcat (fullName, " ");
	strcat (fullName, firstBlah);
	strcat (fullName, " ");
	strcat (fullName, midBlah);
	cout << fullName << endl;
	delete [] fullName;
}

The rule is, for any local variable you declare, if you change its name and all the instances of its name below that declaration in the same block, you won't change the behavior of your code. So hopefully, you can see that local variable declarations don't refer to anything outside the function, and that they define variables that last only during the current instance of the function call, and cease to …

henpecked1 commented: Sarehu was very helpful in explaining my own stupidity without calling me stupid +1
sarehu 84 Posting Whiz in Training

You could write y = x + 48; more readably by writing y = x + '0'; .

sarehu 84 Posting Whiz in Training
void punchmeinthehead()
{
	const int maxin = 16;
	char lastName[maxin] ;
	char firstName[maxin] ; 
	char midName[maxin] ;
	
	size_t length = strlen(lastName) + strlen(firstName) + strlen(midName) + 1;
	char  *fullName = new char[length];
	strcpy (fullName, lastName);
	strcat (fullName, " ");
	strcat (fullName, firstName);
	strcat (fullName, " ");
	strcat (fullName, midName);
	cout << fullName << endl;
	delete [] fullName;
}

There are so many problems with this function. I don't know where to begin. Instead of answering your question, I would like to ask what you think the contents of lastName will be, and how you expect strlen(lastName) to behave.

sarehu 84 Posting Whiz in Training

Your problem is that you're wring your program in a way such that you are not able to restrict your thought to a few things at a time. You need to organize your program, and accordingly, your thoughts, so that you can manage the complexity of the component that you are working with. Then you can test each component separately and experimentally figure out what are the sources of your problems.

sarehu 84 Posting Whiz in Training

Search on Google for it, and make sure you get the right version. The regular MySQL package doesn't include header files.

Or wait, Red Hat Enterprise 5 includes yum, doesn't it? Try yum install mysql-devel (the package name here is a guess) as a superuser. Or use pirut. I think they're installed, but I'm relying on Wikipedia.

sarehu 84 Posting Whiz in Training

You probably need to install the MySQL-Devel RPM package.

sarehu 84 Posting Whiz in Training

What does

the id in itemsList will be repeat for each different item

mean?

Is that your whole design?

sarehu 84 Posting Whiz in Training

> I think you misunderstood the other poster.
> I don't think that word means what you think it means.
I amaze at the arrogance and rudeness some people possess.

I don't understand why you would be touched off by straightforward responses. Also, haven't you ever seen The Princess Bride?

Do you really believe yourself superior to AD's intellect, and mine?

Relative to AD's, I don't know.

sarehu 84 Posting Whiz in Training

He didn't misunderstand.

I don't think that word means what you think it means.

There are two ways to look at "inline":

The OP was using the way AD wasn't.

sarehu 84 Posting Whiz in Training

Question's still open for anyone who might know an inline solution.

There is x ? 1 + static_cast<int>(floor(log10(static_cast<double>(x)))) : 1; , but that solution is dumb (and doesn't consider negative numbers). I say it's dumb because casting to double means you have to deal with precision issues, and because it is tedious to convince yourself that your code is correct for all possible inputs. There is no practical benefit to writing a solution inline, and it's actually a detriment when you'll have to write it multiple times.

Also, you want to set the width to the width of the maximum number you'll have to print in each column. Setting it to the width of i or square is probably not what you want, because the widths of your columns will change for different values.

Inline solution below

I think you misunderstood the other poster.

sarehu 84 Posting Whiz in Training

It's defined in <unistd.h> when _GNU_SOURCE is defined in the preprocessor.

The solution is to prototype it near the top of the program, somewhere above main().

This is not the solution.

sarehu 84 Posting Whiz in Training

You need to put #define _GNU_SOURCE before the #include <unistd.h> line, so that the preprocessor has the definition while processing unistd.h.

n.aggel commented: thank you! +2