jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You can use the degree of the polynomial to allocate an array of size degree+1 (to hold the constant) for each line. Your degree will let you read ahead to see how many times you should go through a loop collecting coefficients and then just grab the last 2 values.
Using your example:
3 1.3 0.9 4.7 2 -5.4 5
1) Read in 3
2) Create a matrix of size 4
3) Have a loop that reads in just 1 coefficient value, repeat it the degree of the poly + 1
4) Read the last 2 values for the bounds
5) Do the integral
6) Delete the array

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try changing line 32 to while(inFile >> inValue) and remove line 33.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Take the infile into not str (as that has your users word) but tempstring or something like that.

while(infile >> tempstring)
{
     if(tempstring == str)
         num++;

     count++; //do this regardless
}
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I would use 1 while loop (just like your second one) and put an if/else in there to distinguish between matched words and regular words and then up the count on each when appropriate.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Prototypes are not required to be at file scope.

Noted. I'd never seen it done that way, false assumption on my part. Thank you.

There's absolutely nothing wrong with it.

The prototype doesn't match the definition, unless I'm missing something again. I do agree about the call being wrong.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

if (next == '#N#') '#N#' is not valid. Single quotes are for a single character (but can hold escape sequences like '\n' for newline). Make next a string, use a getline to read it in and then compare it with "#N#" instead.

Also, don't use feof. Use your getline(fin,next) (see first paragraph) to drive the loop.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

The first question to ask is where do function prototypes belong? Not in main(). After that you should compare the prototype for the function list with the definition of it down below. They don't match. After that it's some minor adjustments once you decide whether you're passing the pointer or not.


And please learn to use code tags -- http://www.daniweb.com/forums/announcement118-3.html

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What I meant was that if you wanted to step by +1 for your loop that you could do 10-m so for 0,1,2,3 it would go 10,9,8,7 but CP's method is more straight to the point.

So what do you need on the code you have just posted (not sure what happened with the code tags it seems like they skipped)? For the + sign (surprise) you need the nested for loop again. Spaces can be used to your advantage, plot it out on paper. I'm not sure what kind of error trapping you are looking for.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, I think since you do not know where the //// will be then you have limited choices. I think if you tried to designate what those variables should be and one of the numerical ones reads //// then the stream will go bad and the rest of the reads will fail.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Ok, so you want the second side to be at the top rather than the bottom?
****
***
**
*
(I'm assuming)
So for your second loop say number was 10, you'd want to have rows of length 10,9,8,7... (with the m=0, (ignore the stop condition it's not correct), m++ your loop would be going ___? (from what to what).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could you post up a larger portion of the code so I can see what you're extending. If this is the ToString() for your class specifically then you'll have to get all the information from the individual rectangles themselves. I'm not sure what the rectangle ToString method outputs.

In all likelihood you'll need a foreach statement and then return the myRectangle.Height.ToString() and myRectangle.width.ToString() where myRectangle is your object.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you want to leave setEl intact what you could do is have your methods return an object of type matrix that you create and put your summed values into (same idea for subtraction). That way your counts are right and it might even be a bit cleaner than overwriting.

Otherwise, decouple setEl and the nent counter and have a "shell" method to use from main() that calls setEl and then increments the counter when it's necessary (so in your add method you would call the plain setEl without the counter).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

If you adjust your function's signature to: void addNames(ifstream& fin, ofstream& fout) (the parameters used in the function body must match those in the signature)
you can avoid the global variables.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

@tetron
Some additional material for this thread can be found here as well

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Aside from all the rest of the situation you've got semicolons after your for statements. The loops definitely won't run then.

Just my $0.02, sit down away from the PC with your text and study the for loop because you're just going to frustrate yourself at this rate. I'm referring to things like for (triangle = 0 ; symbol = ' '; number++) . The second position there is evaluated as true or false and if it's false the for loop stops (hint: that will never be false).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

(fill in the name of your own output file for outFile)

Was incorrect, my apologies. I had meant to say the name of your output filestream for outFile.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Try this:

#include <sstream>
string filename;
stringstream ss;
cin >> filename;
ss<<filename<<".dat";
outFile.open(ss.str().c_str());

The first str() gets the string from the string stream and the c_str() you already know.
(fill in the name of your own output file for outFile)

After further consideration I'm not sure why CP's solution would not work. What was the specific error you were getting?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

In the first case up above it would be rects[i].getWidth() but in the second case you'd have to downcast it like

(go[i] as Rectangle).getWidth()
or 
((Rectangle)go[i]).getWidth()

of course in all of the above cases i is the index for which you are looking.
Also, if you just had a plain old Rectangle object Rectangle myrectangle = new Rectangle(0,0,10,5); you could access it like myrectangle.getWidth() which is close to what you have there but unless the getWidth() member is static you cannot access it without instantiating (using new to make your own object).

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

See my edit up above too. Glad it worked.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change line 29 to:

if(i !=num) 
    cout << "(" << num-i << ")" << "";

Or better you could set factorial to num in your function and change your loop to go from for(i = num-1;i>=1;i--) and only display i.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster
gcc PerfectCalculator.c -o PerfectCalculator -ansi -Wall -pedantic
PerfectCalculator.c: In function `main':
PerfectCalculator.c:13: warning: unused variable `myChar'
PerfectCalculator.c: In function `PerfectCalculator':
PerfectCalculator.c:34: warning: ISO C90 forbids variable-size array `factor'

So the way you have it doesn't compile under standard C. That was more my point. It comes up as a warning but to ensure portability (i.e., your compiler was able to put it through due to an extension) you should probably avoid constructs like that.

But back to the errors you are getting. I'm confused as to where the -1 is coming from? Is that the "value" of array[g+1] because that's two positions too far over the boundary of the array(array[g-1] is the last existing member).

I excluded dividing the number by one

You can fix that by initializing your sum to one on line 38 that way that factor always accounted for. It seems to work for 28 when I run it.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Non-dynamic arrays must have their sizes known as the file is compiling. That is there must be a "compile time constant" value for the size (I don't believe it can even be a const int declared earlier in the program, but I may be wrong about that) is either:

arraytype arrayname[10];

or you can 

#define MAX_SIZE 10
and have 
arraytype arrayname[MAX_SIZE];

Otherwise you need to declare the memory dynamically using a function like malloc which will give you a pointer to a block of memory.

Anyway, post the code and I'll give it a shot. You don't seem not knowledgeable, I'm not impatient. I just want to make sure I understand the problem.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You don't actually return anything from Init(), make it void.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

It's because array indexes must be known at compile time (unless you are using malloc to create dynamic memory). Try putting it in as a constant value. I'm not sure what was giving you -1 but it's a good bet it is a compiler extension as that should have given an error.

By the way, how are you using bool in C. Do you have a library?

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Can you post your code? (or a representative snippet from it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

All you've done there is put the names into a string array. I think what you mean is if you had the class Rectangle, you could create an array of rectangles by saying

Rectangle [] rects = new Rectangle[5];
rects[0] = new Rectangle(10,10,1,1);
rects[1] = new Rectangle(5,5,1,1);
etc.

(just made up a constructor signature there)


Now if all your classes derive from GeometricObject you can create an array of GeometricObjects and store any of the derived shapes in there.

GeometricObject [] go = new GeometricObject[7];
go[0] = new Square(10,10):
go[1] = new Triangle(0,0);
etc.

(also made up constructor signatures)

I believe these objects in the container (those derived of the parent class) can be downcasted to access their members but I am not 100% sure when this will work (I have excluded the GeometricObject since they cannot be downcasted safely).

kvprajapati commented: I like your approach. +7
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think you just need the SuppressKeyPress member of the EventArgs, so simply placing e.SuppressKeyPress = true; on line 3 should work.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Could your professor have meant something like disabling them as well? That was the first thing that came to my mind, but maybe that's oversimplifying it a bit.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What are the specific errors that you got (the first 5-10 are good for now). Also, I see you tried on the code tags but it has to be

[code]

//code here

[/code]

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Everybody will probably give me guff for saying this but if this isn't your assignment and you are trying to process a lot of real data try "preconditioning" it in Excel or the like.
It looks like maybe that's what someone had done with the -999 but I'm not sure of that. If that's the case already then you'll just have to deal with that type of situation in post-processing by sorting the outliers together and either treating them differently or ignoring them.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

What I would do is use a low-tech method: read the line into a string using getline() and step through it to count the spaces. If you don't have all the numbers you need, record the line number of the bad data, throw out the string and read another line.

Otherwise knowing whether something is of the proper nature for that element of the struct would be kind of tricky.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You're making a bigger deal out of the arrow operator than you need to.
When you have a class you access the (public) members via the dot operator. myClass.MyMethod() for example.
But when you have a pointer to a class you need to dereference it first via the * operator. So

ClassName * myClass = new ClassName();
*myClass gets you the class object back and
(*myClass).MyMethod() calls the method (note the parentheses which are necessary for doing the deref first and then the . operator)
The shorthand for 
(*myClass).MyMethod()
is
myClass->MyMethod()

So every class has a pointer to itself known as this. To get at one of your methods you need to dereference and dot, so this->MyMethod() Without the pointer you just use the dot but the pointer is what we have to work with.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Is there a reason for returning 0 from your methods regardless of the outcome. Also in your definitions you need to put the return type

int Complex::Set_C(double x,double y) though I suspect you made them ints to make the compiler happy anyway which isn't the right approach. If you're not actually returning anything from your methods make them void.

Try and make some of those changes. I'm sure there's going to be stuff that still isn't working but see what happens.

EDIT: Also, hint: some of your methods will need to return an object of complex type.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Good luck with it. There were a couple of false starts there on my part but it should be fine now. Post back if you have probs.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Since your numbers are characters all must be enclosed in single quotes

int firstChoice()
{
    char choice;
    cin >> choice;

    if(isdigit(choice))
    {
        if (choice=='1' || choice=='0')
        {
            return choice;
        }
        while(choice!='0' && choice !='1')

is what I meant. Goes for anytime you are comparing characters.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, sorry, I missed the real problem. See my edit above. (choice == '1' etc.)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

You need to check versus '1' etc. (with the single quotation marks). Ignore any of my previous edits.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yes, that would work. Eventually you might want to put that if else sequence into a while (or do/while) loop so that you can get the user to re-enter.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Do you actually need the numbers for calculation within your method? If not just take them in as char and check versus '1' (etc.) in lines 10-17.
If you really need the numbers themselves, take them in as char and convert to the numerical value by subtracting '0'

e.g.,

char one = '1';
int ione = one - '0';  //a char is really a 1 byte int anyway

Check an ASCII table to see why this works.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Change your while loop to a do/while loop with the same loop condition. Move your prompt for the salesperson number into the loop. That way it's called the first time through and any subsequent times.

Line 20 has the incorrect format specifier for a double, it should be %lf
instead of %d.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

This goes very much in depth but seems to have some good background in the beginning. Lex is a specific lexer but the concepts are the same.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Use some of the methods from iomanip (#include <iomanip>). Pay particular attention to "fixed" and "setprecision," they'll give you what you need.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

FWIW, nobody's mentioned it yet -- but check out http://gmplib.org/

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I think I misinterpreted your requirement. You could either go back a step or you can still use what we were just doing.
From your code before:

int usednumbers[365];
int filledcount = 0;
int count = 0;
for(i=0;i < numStudents ;i++)
{
      tmp=array[i];
      for(int j=i+1;j<numStudents;j++)
      {
         if(array[j]==tmp )
        {
           if (filledcount >0)
           {   
                 [check and see if the number is already in the array and if not add it in and up the count of dates with multiple bdays.  ]
           }
           else
                usednumbers[fillcount] = array[j];
 }
  double frequency = (double) count /numStudents;
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Yet another way to keep the count:

Have an array of 366, maybe call it bdays[366] (one extra to skip day 0)
In your code, array[] keeps track of which b'day each person has...

So, if array[0] has a b'day on 122, increment it: bdays[array[0]]++; You've just counted that b'day.
Next person's b'day on 68 - bdays[array[1]]++; etc.

When done, if bdays[5] == 3 then 3 people had b'day on day #3.

I think what WaltP was saying and what I was saying has gotten jumbled together. You have to adopt something like the following. Let's assume we have an array, 366 elements long called bdays that goes from day number 1 in slot one (skipping 0) to day 365 in slot 365.
You find a birthday on the 22nd day of the year. The 22 goes into the first array called array. You go to the int value in slot 22 of bdays and you increment it(array[j] is 22, do bdays[array[j]]++;) so we're building up these counts.
Then if we encounter a birthday on the 126 day of the year, array[j] = 126 then we go to bdays[array[j]]++; and increment that one.
Initially I was saying line them up so if the first element of the days array was 126 then we'd keep the count for array[j] = 126 in the first slot of the bdays array instead. So the setup can be either

|126|73|24|9|239| in the "array" array and
|count126|count73|count24|count9|count239| in the …
jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

for(int j=1;j<numStudents;j++) We've already told you that this is not correct... bdays[array[0]]++; You're only updating the count for the day number that is associated with the first element of the array.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Which part?
Well the counts one you should be filling in your code where you were proposing to add cnt++ before (you need to keep track of which date is which in the end so just keeping one number will only get you the total which you can derive from the other array anyway).

So you have an array (you can safely call it of dimension 365 even though you won't need it). Make a second array that has 365 elements to hold the counts.
You find a birthday on the 26.
|26|
You find a birthday on the 122 day
|26|122|
You find a second birthday on the 122, so in your other array you have
|1|2|
Find a birthday on the 200 day
|26|122|200|
other array
|1|2|1|

So now we want to find the probabilities. Probability of the 26 is 1/(1+2+1) = 1/4. Probability of the 122 day is 2/(1+2+1) = 1/2

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

I didn't compile and run your program yet, but try putting the srand() call out in main() so it's only done once.

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Just match them up:

Keep the dates in one |26|5|140|156|10| Counts in the other |1|3|2|6|4| So the (approximation to the) probability of someone having a birthday on 26th day of the year is 1/(1+3+2+6+4) (but use the 1.0 etc when you enter it)

jonsca 1,059 Quantitative Phrenologist Team Colleague Featured Poster

Make yet another array of ints that runs parallel to your duplicate values matrix and increment a particular entry when it comes up more than once. I know how much you enjoy parallel arrays from your other post. The asterisk part should be straightforward from there.