jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I've been playing around with it a bit but...
So with the example "SPOON"
U queue: SPOON (the original one, you fill it back up again which gets confusing)
R queue: NOOPS (should be this way but it's not)
so you empty U out and put SPOON back into it again in the process of making R
u.first() vs. r.first() S vs N not the same, toggle your boolean and we say it's not a palindrome

"NOON"
U : NOON
R : NOON
u.first() vs. r.first() N vs. N check
Update U to OON (by your delete step)
Update R to OON
u.first vs r.first O vs. O check
etc.
boolean remains true, so it's a palindrome

But....your reversing technique is taking the front of of one queue and putting it into the back of another, so they're sharing the same order, so you're testing bobr vs. bobr instead of bobr vs. rbob. What we really need to do is get the back element of a queue (which we can), put it into another (which we can) and pop off the back element and get the next to last (which we cannot).

What I think you should do (like I had started to mention before) is split your string, so NOON would become NO and ON. Flip around ON and enqueue it as NO, now you can compare the two. If you have a …

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Something weird is going on with your streams they are getting lumped together if your queue starts out empty

Printing pre-reverse U
From the print step
-------------------------
Printing reversed U (R)
From the print step
-------------------------
Printing pre-reverse U
From the print step
racecar
-------------------------
Printing reversed U (R)
From the print step
-------------------------
Printing pre-reverse U
From the print step
bobr
bobr
racecar
racecar
-------------------------
Printing reversed U (R)
From the print step
racecar
-------------------------

That and I don't think your reversal step is reversing at all.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Surely. A good night's sleep never hurts

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I see I see....sorry, nevermind about the second part... I thought deleteQueue was clearing the whole thing.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What happens when you put in noon?

I've kind of overlooked it until now but shouldn't your queue have a function to advance the queue and get rid of the elements in the front? Seems like you make a fresh queue for each pair of letters or numbers. My feeling is you should split the string in half (tossing out the middle character if there are an odd number), feed them into separate queues (one set flipped around) and then go through the both one by one? (so compare element 1 of queue A and element 1 of queue B, "next()" your queue, compare element 2 of A and 2 of B, etc.)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why do you need a counter? You could make a boolean variable and use that in an if statement instead of your switch.

bool isPalin = true;
while (!s.isEmptyQueue())/*s is not empty*/
{
      s.deleteQueue();
      u.addQueue(word);
  
  if(!(u.front() == r.front()))    /*compares front elements, does something if the two not equal, delete elements*/
      {
      u.deleteQueue();
      r.deleteQueue();

      isPalin = false;
      break;
      }
      
}

if(isPalin)
cout<<"is a palindrome"<<endl;
else
cout<<"is not a palindrome"<<endl;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See if you can put the for loop together to do the solid block, then we can go from there

Please show something towards this end. What part is giving you the most trouble? Start off trying to print 1 line of 5 stars (without using a string), then 3 lines.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
if(!(u.front() == r.front()))    /*compares front elements, does something if the two not equal, delete elements*/
   {
        u.deleteQueue();
        r.deleteQueue();
        break;
   }

Since you don't care as long as the pairs of digits/letters are off by at least one, just break out of the while loop.

Do you see with your other setup that you would never get to case 1?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If counter is one, counter/2 = 0 (since it is an int), so it's giving you a false reading. Maybe you want to break out of the while once you sense any difference or something.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You should probably use srand(time(0)); at the top (http://www.cplusplus.com/reference/clibrary/cstdlib/rand/)and do your subsequent calls to rand() % dimension (not rand %100 as a 3 by 3 is not going to need numbers up to 99). As it is your program is trapped on one value and it keeps looping ad nauseum.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

That's the purpose of the assert, to halt the program if a particular condition is not met. So you're calling your front() or back() methods on what apparently is an empty queue.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're not being a pain at all. However, I will not write the code for you. I would be glad to walk through (most of) it with you. See if you can put the for loop together to do the solid block, then we can go from there (I think that's the least difficult starting point, 2 for loops one inside the other, one to keep track of rows and the other stars). If you're not comfortable posting your code you can leave just a piece of it. I think it may be a good idea for you to make 4 separate programs initially and then cobble it all together with the "menu" at the very end.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you are using a for loop to print your stars, why not have another for loop to print spaces? So run one for loop to loop over the # of lines you need and within that have 2 for loops (stars and spaces). Hand code it to convince yourself (e.g., ok so I'm on on lines 0 and N I need x number of stars, so mix in some if statements). It's really not that long of a program once it comes down to it...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

no, like wingless said a+1-a+3 not equal to a+1-(a+3)
I'm not sure what your assumptions are...

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

* (unary, dereferencing) has higher precedence than addition or subtraction, so it's like (*a)+1-(*a)+3.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I was just playing around with that (well, putting your link.cpp into your link.h to see if it was the compiler being finicky about templates). Anyway glad it worked for ya.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'd change them all to link rather than risking collision with that other header file (which is probably the non-standard STL list header)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Part of it is your header is link.h and you include "list.h" (which even though it's in quotes, it ends up finding some older header called list.h in the search path). There's some stuff with your node class too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Maybe I'm missing something, but do you actually create myIntList (instantiate your List object) before you attempt to use it in main()?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your statements in line 57 doesn't make any sense. The ternary operator for if statements needs 3 things. So delete the :0 there . Unless you have been explicitly taught the way you have it, it makes the code difficult to read. I haven't broken down all of your if statements to see if they make sense in light of your spec but one thing I noticed is you have no condition for the user specifying > 744 minutes, the program just exits silently.

Also, if (pkg == 'A'|| pkg =='B' || pkg =='C') is just hanging off in the air. You need to put in braces if you want to encompass everything underneath it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Post the portion that you are working on or refer us back to the old program as to where you are having problems

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok. Do you understand about pointers? When you are passing in an array it's (to the best of my knowledge) converted to a type * at compile time to be passed into a function. When your array is being passed into your function it is being changed within the function, so that when you pass it into the next call in main() it is something different.

So basically change your cubing function to values[index] = values[index]*values[index]*values[index]; and in main() work off this pseudocode

declare values array;
declare tempvals (same size)
read_numbers (values);
copy values to tempvals
square_array (values);
cube_array (tempvals);

If you're having trouble with arrays there are tons (and tons) of writeups on the web about them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I should say pass it into your modified cube function, one that had values[index] = values[index]*values[index]*values[index]; not as you have it.

(also please use code tags with your code the next time)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Code didn't seem to change too much as it is essentially the same thing. Remember your arrays are being passed as double * so once your functions are returning to main you have changed value arrays. Put some intermediate couts in there to convince yourself. You may have to store the array you get back from read_numbers() into another array and pass that into your cube function.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I see what the OP thought they were doing, they were thinking that after squaring it they were going to multiply in one more of the original arrays to get a cube, but since the square came back by reference it turns out to be to the 4th power. But you are correct that they are identical.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Before the cubing step values[] = original value squared, so saying cubed = values[]*values[] = originalvalue squared * original value squared = original value to the fourth. Also in your parlance, cube_root is the same as cubed which it is not (e.g., cube root of 27 = 3). So, ultimately I think the way you have it laid out is fairly confusing. You could pass in a second result array to each of the functions and leave your original one intact, depending on your specification....

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See http://www.cplusplus.com/reference/iostream/manipulators/setw/
That way the widths of your fields will be constant and you can use your ostream directly without all that mildly stressful string manipulation.

yatman commented: excellent help! +0
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to change all the variables in inputfn to references, otherwise you'll just have whatever garbage is in those locations after they are initialized. EDIT: file IO seems to be ok.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Also see my post in your other thread about the flaw in your multiplication...

Stu, I'm thinking having 2 functions (one operator and one non-operator) might have been part of the assignment.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Awesome. Glad you got it to work!

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Your multiplication and division functions are incorrect. A/B * C/D is simply (A*C) /(B*D) you have some extra factors in there. Your numerator for the division function is actually the correct amount, so just separate that into the numerator and denominator. Scratch some examples out on paper to convince yourself. There may be more that is wrong here but there's two obvious places to start.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Namespaces are important, but for the sake of a school assignment you could probably put using std::cout; and using std::endl; instead. Then you'd have to specify for the std::ofstream , etc. But I do concede to your point Stu and agree that good habits are important at any stage of the game.

StuXYZ commented: good comment on using (well you agreed with me :) +2
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Why are you calling resultsfn with only 5 parameters when it takes 11 in your prototype and definition? It will not assume defaults for those. Often what the compiler says, goes.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Here's a p-code skeleton. If you're still having trouble, figure out what it takes to print just the stars on separate lines with the right count, then figure out how to print out the spaces with one star at the end of each line. Then combine the two.

for loop (stepping through the lines)
{
          if(above the midpoint)
              {number of spaces =
                number of stars =  
                }
           else
               {  number of spaces =
                 number of stars =  
                }
          for loop (using number of spaces)
                  print spaces
          for loop (using number of stars)
                  print stars

         Now print an endl to go to the next line.
}

This is one of those times when putting it out on paper can help too.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You still have the endl (s) in your code. You need to get rid of those otherwise you will be printing out stars and spaces with a carriage return line feed after them. Here's a hint - on the way down you're subtracting one space, once you get to the halfway mark you are adding a space. In other words pop in some if statements. Don't be afraid to try a bunch of different things, you'll learn a lot that way.

In the future, don't just ditch your post for a new one, as adding a reply to it will bump it up on the list anyway.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I'm still not grasping why you need ListNode and Node.... You probably need to make Node a private class of NumberList and using your NumberList constructor to make new nodes, possibly using a method to add new nodes as necessary.
As it is, node doesn't have a constructor to take in both things. Looking back, Node seems to be one of a doubly linked list and ListNode a node in a singly-linked. I think this might be one of those times to take the requirements and take a step back. See what kind of list you need, which elements constructors should do what. It might be bad design but you can start with everything public and introduce your hiding step by step and change the . operators to getters and setters, etc.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

EDIT: missed how it was before. But your Node itself has a default constructor taking no arguments. I think the problem lies in all the private inner class friend layout that you have. I understand that you may have a requirement for data hiding but I can't quite wrap my head around how to code around that.

Also, please kindly use code tags.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Go through your files that I uploaded back and make sure that I didn't make any changes that you didn't make. Otherwise these do compile on my machine, albeit giving a program that outputs "Incorrect installation!"

If you know where you're going, look for the command line tools that are part of Mingw included in your Dev-C++ and try to compile it on the command line (my "g++ .... " from before).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Then it gives you the option to send an error report or dont send. How do I get that to go away?

Write a program that doesn't overstep your name array and crash. Only giving you a hard time...

There isn't a next element to test after "Tim."

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I haven't used it since it's infancy in the 90's (dating myself here,I'm sure it's matured since then), but basically you need to start a console project (screenshot here: http://en.wikiversity.org/wiki/Installing_and_using_Dev-C%2B%2B) and incorporate those headers and cpp files into the project by right clicking the project name.
I'm sure there are plenty of other folks on here who know Dev-C++ like the back of their hand, so post back if you're still having trouble.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to compile them at the same time as they are dependent on one another e.g., g++ -o myprogram ergasia.cpp feature.cpp depending on what compiler you are using. I suppose you could compile them separately to .o files and link them together but doing it in one step is easier.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Seem to be missing semicolons after your class declarations in the headers:

class Feature {
private:
	int Id;
	int Frequency;
	string Description;
public: 
	void setId(int i);
	void setFrequency(int f);
	void setDescription(const string d);
	int getId();
	int getFrequency();
	string getDescription();
	Feature(int i, int f, const string d);
};     <-------------- (and in your other header too)

Oh yeah, and get rid of that declaration of main in the header file. Keep the one in the cpp file.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

cin << info; is incorrect, the >> operator should be used instead. Probably just glazed over it because you had it right the other times.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Don't use the endl as that's moving each * onto it's own line. You have the right idea with 2 for loops. Are you prevented from adding a third to step through each line of the diamond? You might use some if statements, placed strategically to decide which of the top or bottom you are printing and how to change the spacing. The best advice I can give you is try some different things -- you said you're close to printing the top of it, can you print the bottom of it by itself?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Calculating commission at the beginning like that will just calculate it once, and with the wrong amount for the sale.
Firstly, turn the whole thing into a do while loop because you have a while at both ends and that doesn't make sense.
Then make commissionA, commissionB and commissionE variables. commissionA+=(0.10*saleAmount); and saleAmountA+=saleAmount; If it helps you, run through it on paper with the values your variables take on. You're most of the way there, just read up on some stuff.

Also, I think the code snippet heading is used more for folks that have a function they want to add to the library for the site....

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

There are many other things, but you need to have template <class T> before every function definition that uses T (e.g. in array.cpp). Also you pull capacity out of thin air. Make sure your function names are spelled correctly as, within the code you posted you have "Disply" as your function name.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Check out:
http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13

It's touchy about template parameters being defined in separate compilation units. It probably has to do with your DataType parameter being used in a function with your T parameter in main. I did not try your code so I'm not positive.

P.S. What's up with that font? hehe

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This is going to sound bad, but can you use the terms from my code please.....I'm not sure what you mean otherwise....I'm not clear on function(double & value).....how would I code it cor the radius portion?

In this case, since your functions are returning values (radius returns a double and distance returns a double) you can just grab those values into a local variable in main()

e.g.

int main()
{
            your other variables
            double dist, rad;

            further down....
 
            dist = distance(center1,center2, etc);
            rad = radius(center3);
             
}

Now instead of just outputting those to a cout (which was implicitly using the return value anyway) you can do whatever you want with them. e.g., double halfdist = dist/2; .

What restrictment says is technically correct, but since you have the return values (and only need 1 per function) you can go ahead and get them in the traditional way. If you wanted to, you could create a reference variable dist and send it in with your arguments, but just stick with what you have for now.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do your liters to gallons conversion _after_ you've read in the liters. As of now you're doing that calculation on the 6th line with whatever garbage is in memory. (so in other words convert the value down in your function)