Duoas 1,025 Postaholic Featured Poster

Your procedure should be named something like FormShow.

Then, either in the IDE using the Object Inspector (or whatever M$ calls it) or in the FormCreate function set the OnShow property to the FormShow procedure.

Duoas 1,025 Postaholic Featured Poster

Typically, your window isn't actually destroyed, it is only hidden. Hence, when you ask to show it again nothing has changed. You will need to add an OnShow event handler to reload your combobox whenever the form is displayed.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

A begin is implied in the body of a lambda.

The problem is that you have to be extra careful to keep data and code separate in scheme. You are mixing the two.

For example, the following is not a valid program: (1 2 3 4) but it is valid data: '(1 2 3 4) Essentially, your update function body at some point evaluates to ('() '()) ...which is not a valid program.

Again, I have yet to re-install PLT so I can't be sure (it has been a few years since I've used scheme much), but you might fix it by simply changing your letrecs to use the following if inside: (if (not (null? lst)) That way, the result is nothing, rather than an empty list.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The same problem?

I see nothing wrong with your code... (I can't test it myself ATM, as I'm just recovering from a system wipe and have yet to reinstall scheme.)

Do you think it might be barfing because upgraph evaluates to '() ?

Duoas 1,025 Postaholic Featured Poster

That shouldn't work at all. Both upgraph and downgraph are defined to take a single argument, but you are passing multiple...

That could be the problem. Make sure also that you aren't calling bitset with '().

Sorry I can't be of more help.

Duoas 1,025 Postaholic Featured Poster

Alas, I've never played with MFC.

I wonder if you wanted a vector of System::String? std::vector<[B]S[/B]tring> Value(10); (Case matters.)

Duoas 1,025 Postaholic Featured Poster

It isn't complaining about the std::vector class, but the string class, which doesn't exist.

Make sure you say: std::vector<std::string> Value(10); Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The problem is essentially this:

vector<term>::iterator p5Current = result.poly.begin();
result.poly.erase( p5Current );
p5Current++;  // <-- this throws an error

Once you erase an element, you cannot operate on it. Since *p5Current no longer exists, it makes no sense to increment to the next one...

You'll have to think a little bit about how to solve this. (If you feel comfortable with the <algorithm> template functions, you might want to take a look at remove_if. However, you can easily do it without using the algorithms remove_if() template function...)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

That's a nice catch. (I thought I tested for that...)

I fixed it by using a temporary. I replaced the line

if (stream.peek() != 'x') stream >> t.co;

with

if (stream.peek() != 'x')
{
	int sign = t.co; // save the current sign (1 or -1)
	stream >> t.co;  // get the coefficent absolute value
	t.co *= sign;    // restore the sign
}

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Post your operator>> code, and which line is giving you trouble.

Duoas 1,025 Postaholic Featured Poster

Look, I'm sorry I didn't go back and re-read your posts before preaching to the choir. All you have to say is "I understand ^ and ** and polys."

What you are failing to grasp is sprawled all over pages 1 through 4 of this thread. It is fine if you want to jump in late but if you are then told "you've missed something" then you have probably missed something.

The purpose of using a programming language is to deal with abstractions. There is nothing magical about it. The last three or four posts OP and I made dealt explicitly with the "special function" of turning adjacent like terms into a single term, for every term in the list. Notation has absolutely no effect on the operation.

I can just give the OP code. But I won't. I want him to write it himself. (He can do it just fine and he'll be happier with the result.) What he is struggling with is how to arrange his data to do the reduction. This requires abstract thought over what is happening to the terms of the polynomial.

What you are struggling with is already a solved point. (Check out the operator>> and the Polynomial class's data structure.)

Sorry if I upset you.

Duoas 1,025 Postaholic Featured Poster

You can't use the ++ operator like that.

You can, however, use it like this:

...iterator i1, i2;

  for (i1 = result.poly.begin(); i1 != result.poly.end(); i1++)
  {
    i2 = i1 +1;  // the next term, if any

    if (i2 == result.poly.end()) break;  // if there isn't any next term, you are done anyway...

    if (i1->expo == i2->expo)
    {
      i1->co += i2->co;  // add the terms
      result.poly.erase( i2 ); // erase the next term
    }
  }

I think that should work.
You could also just use integer indices, as in result.poly[i].expo and the like.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, you are confused because you are mixing C++ and the OP's syntax for a polynomial. They are distinct things.

In textual representations, both x^y and x**y are common to mean "raise x to the power of y". This has absolutely nothing to do with C++.

A term is a multiplicative value. Hence, 4x is "4 times whatever 'x' is". You can add like terms (that is, terms with the same power of x) easily: 4x + 2x = 6x But unlike powers cannot be added: x**2 + x = ??? Three oranges and two oranges are five oranges, but three oranges and two apples are still three oranges and two apples no matter how you look at it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

JRM, please take the time to read the whole thread before jumping to conclusions. His polynomial is expressed as a vector of terms. Each term is composed of a coefficient and an exponent.

orangejuice2005
Why don't you use your sort() method? p3.sort(); Then, all the terms with the same exponent will be adjacent. For example, 4x^2 -3x -6 +9x^3 -2x^2 +7 becomes 9x^3 +4x^2 -2x^2 -3x -6 +7 Terms with like exponents: 9x^3 + (4x^2 -2x^2) -3x +(-6 +7) Combining them is just addition and subtraction of the coefficients: 9x^3 +2x^2 -3x +1 1. After the sorting, just loop through the terms.
2. Inside that loop, check to see if the next term (if any) has the same exponent. If so,
combine (add) the terms. Loop until the next term has a different exponent or you reach the end.
3. Continue with the outer loop until all done.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Coding is the process whereby you take a complicated task and break it down into simpler tasks. If you can't make it so simple you feel a two-year-old could have written it, then you are thinking too hard.

Personally, I would have my operator+ just concatenate the addend to the augend, then use the sort() method to arrange things in order and then join like powers...

Duoas 1,025 Postaholic Featured Poster

That's because you didn't replace lines 17..18 with lines 20..25, as I indicated.

That should fix it. As a note, however, separating line 38 from 34 introduces the possibility to read incorrect input. Here's my take:

istream& operator>> (istream& stream, Polynomial& pnomial)
{
	term t;
	pnomial.poly.clear();
	while (stream)
	{
		stream >> ws;

		if (stream.peek() == ';')
		{
			stream.get();
			break;
		}

		t.co = 1;
		if (stream.peek() == '+') stream.get();
		else if (stream.peek() == '-') {
			t.co = -1;
			stream.get();
		}
		stream >> ws;

		if (stream.peek() != 'x') stream >> t.co;

		if (stream.peek() == 'x')
		{
			stream >> t.var;
			stream >> ws;

			if (stream.peek() == '^')
			{
				stream.get();
				stream >> t.expo;
			}
			else t.expo = 1;
		}
		else t.expo = 0;

		pnomial.poly.push_back( t );
	}
}

Notice how I get to line 30 only if there is an 'x' read. (That way, you can't have "12^3" as a term.)

Keep in mind that neither of our codes are perfect (and could use some significant work) but they do the job on correct input. Which is probably good enough for your professor.

Don't just copy my code into your project. Make sure you know what you are doing (I think you do have a pretty good idea, though).

The next trick is to fix your output to display a polynomial correctly. Just as you did with the input (which I feel justified having helped you so much, since input is tricky) you should start by making an output …

Duoas 1,025 Postaholic Featured Poster

That's because commands in the cwd are not in the PATH by default on Linux/Unix.

Type ./a.out Enjoy!

Duoas 1,025 Postaholic Featured Poster

Actually, your program has a few I/O errors that I'm sorry to say I didn't catch earlier. I'll list them all here for you though.

Polymain.cpp: line 15
Just as a personal stylistic preference, I'd add a single space after the prompt, as: cout<<"Enter selection> "; This isn't a bug, though. Just style. :)

1. Polymain.cpp: lines 44, 47
User input should generally be done on a line-by-line basis (that is, input an entire line as a string, then parse the string) but C++ lends itself to professors having you learn UI with the >> and << operators of the cin and cout streams. These operators do what they are supposed to do, but a one-sided education in their use produces some very bad and buggy I/O programs.

On the line indicated, you have the user input an integer. That's fine (unless the user inputs, say 'a'). I'll defer lecturing to the optional part at the end of my post and just fix egregious errors here.

After inputting the integer there remains a newline sitting in the input stream. The user had to press ENTER to send the number to the program, so we really do need to remove the newline before continuing. (That way the newline doesn't contaminate more input --which it does in your program, btw.) Best to avoid the possibility of error either way. Change line 44 to read:

cin>>choice;
	  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

The same problem occurs on what …

John A commented: Good work. I'm too lazy to do that much correction. :) +13
Duoas 1,025 Postaholic Featured Poster

The only GUI toolkit built-in to Python is Tk. (And Tcl/Tk most definitely does work on the iPod!)

I know next to nothing about the iPod. Is it an embedded OS?

In any case, it is certainly possible to make a single program that does python/tk, but you will likely have to hack python yourself to do it. Since you've got both libraries, I'm not sure what the problem is. Distribution, maybe?

(Oh, yeah, I'd say go with Tcl, but I don't think the footprint would be prohibitive to go with Python. But then again, I know next to nothing about the iPod...)

Duoas 1,025 Postaholic Featured Poster

You've got a name collision with the preprocessor.

At the top, you said #define poly Then below you say: vector<term> poly; which becomes: vector<term> ; Hence the grief.

In general, make sure that you guard your include files by using the same name as the file, but in all caps: #ifndef POLY_H #define POLY_H ...


You've got a lot of other errors in there too... Take them one at a time and try to see where you've made an error. You'll get through it.

The very first error, though, I'll help you with. Poly.cpp, line 10: you are trying to do something you can't: while (stream>> != ';') This is invalid syntax.

I'll show you the right way.

  1. You aren't testing if you are at EOF.
  2. You should peek for ';', because if it isn't you don't want to have actually read the character...
  3. Once you find ';', you'll want to read it.

So, something like the following might help:

while (stream)  // (while not EOF)
  {
    if (stream.peek() == ';')  // are we at the end of the poly?
      { // yes
        stream.get();  // read the ';'
        break;  // end the loop
      }
      ...  // normal stuff follows
  }

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, cin.get() just reads one character, and throws it away (well, returns it, but you didn't save the return value).

Your input function looks much better.

As to the error: I don't know. I don't have your most recent code so I can't investigate on my own. But I think that the problem is a variation on the last problem...

Duoas 1,025 Postaholic Featured Poster

First, this belongs in the C++ forum.

I'm not getting unresolved external symbol errors, but they might be mistaken for some mismatched templated function arguments ("no matching function for call to xxx").

Password.cpp: Lines 55, 68, 91
The fstream.open() function takes a (const char *), not a (std::string). Fix it thus: in.open(FileName[B].c_str()[/B]); Password.cpp: Line 90
Watch the character case of your identifiers. if ([B]adminPW[/B] == Decrypt(EncryptedPass, EncryptionKey)) Password.cpp: Line 99
Again, you've supplied arguments that don't match the function. getline() takes a character for a delimiter, not a string. Alas. getline(in, NameCheck, [B]' '[/B]); This compiles and runs for me. I can't test further because I don't have your test input file, and my brain is too tired right now to read through your code to figure out what it should look like.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

I think what you are looking for is the overrideredirect flag. This tells the wm to buzz-off.

It is generally used for pop-up windows (like balloon pop-ups, menus, etc.).
It is generally a Bad Idea for use with your main application window.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

A good place to start actually is to force the input to take a certain form.

For example, you could say that input must be of the form: [B]-[/B][I]42[/I] [B]x ^[/B][B]-[/B][I]3[/I] where the '-' signs are optional (of course).

You could then just read assuming information is present:

istream& operator>> (istream& stream, Polynomial& poly)
{
    term t;  // You must declare a variable here...

    if (stream.peek() == '+') stream.get();  // skip any '+'s

    stream >> t.co;    // read the coefficient
    stream.get();      // read the 'x'
    stream.get();      // read the '^'
    stream >> t.expo;  // read the exponent

    poly.poly.push_back( t );

    return stream;
}

Now you can go back and add in stuff to check whether or not something is present.
For example, you can modify it to check to see if an exponent is there before trying to read one.
You can check to see whether an 'x' is there before trying to read it.

Then you can type terms of the form 3x instead of 3x^1 and -7 instead of -7x^0 .

Oh yeah, don't forget that in C++ you don't need to say struct term t; you can just say term t; but you must always name a variable. "term" is a type. "t" is a variable. Don't mix them.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The Bloodshed Dev C++ is an IDE. It uses MinGW (GCC).

I personally like the GCC.
Stroustrup likes the Microsoft C++.
Borland C++ is good too (but not always the best at standards-compliance).

Enjoy.

Duoas 1,025 Postaholic Featured Poster

Getting input is probably going to be the toughest part of the assignment. For each term, you have to read something that looks like this (where green is optional) [B]-[/B] [I]12[/I] [B]x[/B] [B]^[/B][I]-2[/I] So, you might want to peek to see if there is a '-' or '+' sign, and make note of it. If there is, read it.

Then try to read a number.

Then the x.

Then check to see if there is a '^'. If so, read it and another number.

Now you have your two numbers. Adjust the first based on whether or not there was a '-' sign in front of it.

Stick your two numbers into a term struct, and push_back() the struct on your poly vector.

For trying to read those numbers, you may want to check out the fail() and clear() members of the input stream.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

> sorry, i didnt read it properley

I do that all the time... :$

Duoas 1,025 Postaholic Featured Poster

iamthwee, you've missed the point.

The OP's Polynomial class is based on a vector of term structs. (He made this change in his second post.) Each term in a polynomial (which he represents with the struct term) has exactly one coefficient and one exponent.

I am full aware that there are many ways to solve this problem. The problem with the link you provided is two-fold:

  1. it doesn't match the structure the OP uses; the link uses a fixed array of terms, the OP does not.
  2. it gives away an answer for free; if the OP were to use it he would learn nothing (and as a professor I would fail him for cheating)

I wasn't criticizing you. I would rather help the OP figure out his problem in his own way rather than re-design his code for him. That's all.

Duoas 1,025 Postaholic Featured Poster

Exactly.

You should actually call finish() no matter what. But it only needs to do something if count is 1 or 2.

Duoas 1,025 Postaholic Featured Poster

Please pay attention.

I said that your professor should have given you an array of three unsigned chars: unsigned char c[ 3 ]; What he actually gave you was three distinct chars: char c1, c2, c3; In both cases, you have three chars that you need to fill before you can use E(k). Everytime the user uses output(plaintext[current_index]); then the output() method should place x's value into one of c1, c2, or c3. Which one it is depends on count.

Think about it:

c[0]   c[1]   c[2]
c1     c2     c3       <-- one of these gets the value in [B]x[/B]

If count is zero, then c1 gets the value.
If count is one, then c2 gets the value.
Et cetera.

So, what do you do when all the c's have values (that is, what do you do when count becomes three)?

Duoas 1,025 Postaholic Featured Poster

Yes, it is the same. And (at least by what I see now) his code does start with randomize.

In computers, there is no such thing as a truly random number. Delphi's random number generator is notoriously wimpy.

You'll have to google "delphi random number generator" or something similar for a better answer.

Good luck.

Duoas 1,025 Postaholic Featured Poster

c[] is an array.
x is not.

Duoas 1,025 Postaholic Featured Poster

iamthwee, how do you get more than one coefficient per term? His struct is fine as is.

Also, the sort() method is not redundant. I called it "normalize", but the thing it does is about the same. By having a routine that normalizes/sorts the polynomial, other activities become a lot easier.

orangejuice2005, you'll have to give me a day to look over your latest. My brain needs sleep now...

Duoas 1,025 Postaholic Featured Poster

Uh, no. The char x is just a char, not an array of char.

Duoas 1,025 Postaholic Featured Poster

The loop belongs in main(), and each time through the loop you need to call output() once.

In the output() method there should not be any loops. I think the assignment would have been more clear had your professor named c1, c2, and c3 as unsigned char c[ 3 ]; So inside output() you can set c[ count ] = x; and count++; Then, if count > 2 you need to encrypt the c[0], c[1], and c[2] (or, as your professor has named them, c1, c2, and c3, and reset count to 0.

Hope this helps.

kylcrow commented: Extremely patient and helpful. Thanks again. +1
Duoas 1,025 Postaholic Featured Poster

How many bits fit in a byte? How many bits to you need for a block to encrypt?

[ p1 ][ p2 ][ p3 ]

Each 'slot' or 'bin' or 'byte' holds a character of the plaintext.

For example:

Imagination is more important than knowledge... --Albert Einstein
123123123123...

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Consider how a block cipher works. In this case, you need three inputs to apply the encryption.

I presume (and hope) that your professor has covered a block cipher in class. As you haven't described the cipher here, I'll just pretend that you know how to use it.

So, you have three slots that need to be filled before the encryption can be done. Your professor has named them c1, c2, and c3. Your professor has also provided you with a way to keep count of how many slots are filled.

The plaintext is output one character at a time. Every output() should fill the next slot. Once the slots are filled, encrypt them, output the result, and clear the slots for use again.

The finish() should take care of the case that there are only one or two slots filled when you run out of plaintext to output(). Therefore, finish() should supply the appropriate values for the unfilled slots and encrypt and output as usual. What should finish() do if there are zero slots filled when it is called? Think about it.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Start small and work your way up. For example, you could start with just creating and displaying a polynomial. Then you could add a method to read a polynomial. Then add polynomials. Etc. Each step of the way test it out in main(). Once you are done, you can move the stuff into separate .h and .cpp files.

The introduction of a term class was brilliant! Good job!

I removed the initialize() method (it won't work and you don't need it).
The sort() method is not a constructor.
I've also renamed get_term() to number_of_terms(), as a more descriptive name.
Don't forget to end a struct or class type with a semicolon.

Also, indentation and formatting will help considerably when you read your code. For example:
[code=C++]

//------------------------------------------------
// The stuff that follows would go in your Poly.h
// file when you are done testing it

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

struct term
{
	int co;
	int expo;
};

class Polynomial
{
	friend istream& operator>> (istream& stream, Polynomial& poly);
	friend ostream& operator<< (ostream& stream, Polynomial& poly);

	public:

		// The list of terms in the polynomial
		// (not necessarily ordered)
		vector<term> poly;

		// default constructor
		Polynomial();
		
		// empties the polynomial of all terms
		void reset();

		// sort the terms from the highest to lowest exponent
		void sort();

		// add two polynomials
		Polynomial operator+( const Polynomial& p );

		// returns the number of terms in the polynomial
		int number_of_terms();
};

//------------------------------------------------
// The …
Dukane commented: excellent response +2
orangejuice2005 commented: Thnx for the continued support and patience! +1
Duoas 1,025 Postaholic Featured Poster

On lines 7 and 9 you forgot to say [b]p1.[/b]coef.begin() , etc.

Line 17 should have a == , not a = .

Your iterators have terrible names. Try
iter --> icoef1
iter2 --> iexpo1
iter3 --> icoef2
iter4 --> iexpo2
This will help.

Now, just remember, every time you increment an iterator to p1 you have to increment both.

if (I want to see the next term in p1) {
  icoef1++;
  iexpo1++;
  }

Likewise for p2's iterators.

Now you'll have to think about how to loop through the polynomials. Remember, you can only sum terms that have the same exponent. Are your polynomials stored in canonical form? (Meaning, that exponents start high and get smaller left to right, as: 4x^4 + 2x^2 - 7x ? How you find matching terms will be easier if it is.)

You will have to find matching exponents and add the coefficients, then push_back() the resulting coef/expo values in p3.

Hope this helps.

(Personally, I would forget the hard stuff and just make a routine that normalizes a polynomial. For example, given 4x^2 +3 and 2x^4 +2x^2 -7 , you could just concatenate the two into one: 4x^2 +3 +2x^4 +2x^2 -7 then normalize it into: 2x^4 +6x^2 -4 )

Duoas 1,025 Postaholic Featured Poster

You need to watch your brace style. (The while end-brace should be at the same indent as the while keyword, based on your other braced blocks.)

The loop never ends because you forgot to cin >> x; at the end of your loop also.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

The line cube[5]; is just a number. However, since the array has only five elements and you are trying to access the sixth, you'll get a bounds error (or worse).

Use a for loop to set each element of the array to zero.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Well, no one else is responding so here's my take. Mind you, I've never tried to do this so I can't claim I know everything there is to know about it.

Windows is pretty particular about not permitting the exe file to be modified while the program is running. So, there are three options I can see (the first two are common, and I don't know if the last would really work or not [for those same technical restrictions]).

  1. Download the updates, then use the run-once registry key (to effect the actual update and launch the new application when Windows is restarted), and tell the user he must restart Windows for the update to take effect.
  2. Keep all the code that can be updated in DLLs that the application uses explicitly (with the LoadLibrary() API function). To update, download the replacements, use FreeLibrary(), replace the DLLs, and use LoadLibrary() again on the new DLLs. This method isn't quite as flexible as the first, obviously, but would suffice for a large number of tasks.
  3. Launch a script or another application that knows how to update. Terminate yourself. The launched app makes the required changes, then starts the new version of the program and terminates itself, leaving the new program running happily.

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes, don't feel bad. This trips up a lot of people.

The << and >> are always for doing text output. If you know any C they are comparable to the printf() and scanf() functions. In other words, they always convert numbers to/from their string representations.

So, like vijayan121 said, you'll have to go to a raw output function: f_DataFile.write( reinterpret_cast<const char *>( &i_verts ), sizeof( i_verts ) ); Good luck.

Duoas 1,025 Postaholic Featured Poster

I think that you need to increase your stack size.

You can do it from the Options -> Compiler -> Memory Sizes menu or use the $M directive at the top of your code.

{$M 32768, 655360}  { Twice the default stack size, default heap size }
program fooey;
begin
  writeln( 'Hello world!' )
end.

Let me know if this helps.

Duoas 1,025 Postaholic Featured Poster

Sorry again... :$

Nice catch on the type of input.

Duoas 1,025 Postaholic Featured Poster

Vegaseat, you really ought to try to give people an idea instead of just writing code for them. People learn better when they can solve the problem themselves. A little direction --a nudge this way or that-- is all that is needed. (It is more satisfying both to the OP and to you who helped.)

Line 10: Never, ever, use input to get user input. That is just plain dangerous. It should read: celsius_list.append([B]raw_input[/B](prompt)) Hope this helps.

[EDIT] Just noticed (again) that you're a mod. I'm probably preaching to the choir. Sorry.

Duoas 1,025 Postaholic Featured Poster

Hmm, as I re-read your code your "generic function" seems to me to be very un-generic --at least in the C++ sense of the word. Hence my suggestion for functors.

If you really want to use function pointers directly you will have to figure some other way to fix it. Otherwise you will need to implement it in terms of C++ generics. Here's an example:

#include <iostream>
using namespace std;

//----------------------------------------
// This is our functor class.
//----------------------------------------
// Currently it is rather simplistic as the point of a functor is
// to hold state, and this class is stateless (it has no member
// variables). In essence, it is just a callable object.
//
class ftor {
  public:
    int operator () ( int augend, int addend ) {
      return augend + addend;
      }
  };

//----------------------------------------
// Here is a normal, everyday function.
//----------------------------------------
int func( int augend, int addend ) {
  return augend + addend;
  }

//----------------------------------------
// Here is a generic function.
//----------------------------------------
// That's "generic" in the C++ sense of the word.
// The function is used below with two different
// types of arguments, so the compiler actually
// creates two functions.
//
template <typename predicate>
void do_something( predicate f, std::string info ) {
  cout << "10 + 5 = "
       << f( 10, 5 )
       << " (" << info << ')'
       << endl;
  }

//----------------------------------------
// Examples of using the generic function
//----------------------------------------
int main() {
  do_something( func,   "using a regular function" …
Duoas 1,025 Postaholic Featured Poster

No, you can't, because member functions take an extra, hidden, argument this.

You might want to check out functors, which would solve your problem! (While you are at it, the entire Function Pointer Tutorials site is worth a good perusal.)

Hope this helps.

Duoas 1,025 Postaholic Featured Poster

Yes. The easiest way would be to use reference parameters.

void Movie::getstuff( std::string &name, int &hours, int &minutes ) {
  name    = getTitle();
  hours   = getLength() /60;
  minutes = getLength() %60;
  }

Then you would call it like

std::string title;
int hour, min;
a.getstuff( title, hour, min );
std::cout << '"' << title << "\" has a runtime of "
  << hour << ':' << min << std::endl;

That said, the better way is to keep it separate like you have it.

std::cout << '"' << a.getTitle() << "\" has a runtime of "
  << a.showtime() << ':' << a.showtimem() << std::endl;

Good luck.

Duoas 1,025 Postaholic Featured Poster

An identifier and a string are different because a string is surrounded by double-quotes.

Movie a(
  "Scorcese",
  "the Departed",
  "Drama",
  151,
  "Leonardo diCaprio",
  "5 Stars",
  "2006"
  );

Formatted for readability...

Have fun!