NathanOliver 429 Veteran Poster Featured Poster

In your callback function inside the switch statement you have char A_Function(); . What is this for?

NathanOliver 429 Veteran Poster Featured Poster

You should be returning by reference not by value

std::string & access(int row, int column);

csv_File & grab(int index);
NathanOliver 429 Veteran Poster Featured Poster

I would need to see the code of all of the objects to see what is going on.

NathanOliver 429 Veteran Poster Featured Poster

The function looks good. I did make an error though. After you close out your for loop you should add return false;

bool ZerosRemaning(std::map<int, STreeGenSimple> IndivAuxIDSortedMap)
{
    std::map<int, STreeGenSimple>::const_iterator it5;
    for (it5 = IndivAuxIDSortedMap.begin(); it5 != IndivAuxIDSortedMap.end(); ++it5)
    {
        if(it5->second.auxID == 0)
            return 1;
    }
        return false;  // add this.
}
NathanOliver 429 Veteran Poster Featured Poster

Well if you want to have a condition to where you keep looping until all auxID's are zero I would write a function for that

// function to see if any zeros are left
bool ZerosRemaning(std::map<int, STreeGenSimple> IndivAuxIDSortedMap)
std::map<int, STreeGenSimple>::iterator it = IndivAuxIDSortedMap.begin(), end = IndivAuxIDSortedMap.end();
while (it++ != end)
{
    if ((*it).second.auxID == 0)
    {
        return true;
    }
}

// while loop
while (ZerosRemaning(IndivAuxIDSortedMap))
{
    // your for loop here.
}

I think this might be something your looking for. It does involve a bit of overhead though.

NathanOliver 429 Veteran Poster Featured Poster

When you say you need to update the auxID many times what exactly do you mean? What is meant by "become different of zero"? If you simply want to make sure that auxID for every object in the map is not zero then you can do something like

std::map<int, STreeGenSimple>::iterator it = IndivAuxIDSortedMap.begin(), end = IndivAuxIDSortedMap.end();
while (it++ != end)
{
    if ((*it).second.auxID == 0)
    {
        // do something here to change it
    }
}
NathanOliver 429 Veteran Poster Featured Poster

I think you can accomplish this a little easier than what you are doing. If you read the whole string in all you have to do is find the ' '(space). Once you know that position delete everything in the string to that location. now you are at the first number. Then you find the first ' '(space). now you can copy the string from the start to the space into another string and then convert it to a number. Then search for the next space and delete everything in the string through the space. now the rest of the string is the number.

// using sentence as the string from the file
string temp;
size_t pos;
pos = sentence.find_first_of(" ", 0);
sentence.erase(0, pos + 1);
pos = sentence.find_first_of(" ", 0);
temp = sentence.substr(0, pos + 1);
//...

Something like that should get you the first value from the string. Should be able to figure the second half out.

NathanOliver 429 Veteran Poster Featured Poster

You do know that what you have coded will not give you sum of 1+1/2+1/3+...+1/n

NathanOliver 429 Veteran Poster Featured Poster

With operator overloading one of the types must be a user defined type. reference: http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.10 section: 26.10

NathanOliver 429 Veteran Poster Featured Poster

To do this you need a sum variable that you will add to ever iteration. Then in your for loop all you have to do is add the part to the total.

double sum = 0;
for (int i = 0; i < n; i++)
{
    sum += //calc to get part
}
cout << sum;
NathanOliver 429 Veteran Poster Featured Poster

so you want the system call to say "Net User name"? If that's all then you can use a string and put the two parts together and then pass the whole thing to system.

string command = "Net User ";
string name;
cout << "please enter the user name: ";
cin >> name;
commmand += name;
system(command.c_str());
NathanOliver 429 Veteran Poster Featured Poster

the problem is you are using uninitialized variables to do your computations. in case 2 you are using yearsWorking without ever storing a number in there.

NathanOliver 429 Veteran Poster Featured Poster

Why are you even declaring aonther DAI? If you want to youse the getCountry function all you have to do is

for(int i=0; i < answer; i++)
{
    A.push_back(DAI());
    A[i].getCountry();
}
NathanOliver 429 Veteran Poster Featured Poster

The c++ standard gives no guarantee that a variable will be initialized to zero or null. Some compilers may add this functionality in but it is not guaranteed. You should always initialize your variables when you declare them. This is especially true for counter variables.

NathanOliver 429 Veteran Poster Featured Poster

I would actually break this up into two functions. The function you have now would just be used to parse through the array and handle the return from the helper function. In the helper function I would do the calculations to find out if there was an increase or decrease in profits by simply subtracting the first value in the array from the last value. If the number is positive the profits increased and if its negative they decreased. To determine if it was steady or not will need a loop. Start at the front of the array and then step to the end. As you go through the array check and see if the difference between the values is always positive or negative. if the is a change then you know it is fluctuating.

NathanOliver 429 Veteran Poster Featured Poster

What error are you getting? From the look of it you might need to define a operator= for your mat class. Also it is bad coding practice to define large functions inside the class. You should define them outside like

class Foo
{
    //...
    int Bar(int);
    //...
}

int Foo::Bar(int foobar)
{
    //...
}
NathanOliver 429 Veteran Poster Featured Poster

IMHO any class or function that you write that you use with different data types should be a template so you don't have to keep copy and pasting code and possibly creating an error in doing so. That said if you are writing a simple function for a program and you feel you will only use it there then there really isn't any advantage to template it. I would equate it to non library functions and library functions. with non library functions they get used in one program and that's mostly it. with library function they get used in many programs and should be flexible enough to not be changed.

NathanOliver 429 Veteran Poster Featured Poster

Does this code work? There is no type for the variables first and last.

NathanOliver 429 Veteran Poster Featured Poster

I would have the variable passed into the constructor of each class

NathanOliver 429 Veteran Poster Featured Poster

Check this out.

NathanOliver 429 Veteran Poster Featured Poster

Another use for pointers is for passing to functions. When you pass a pointer to a function anything you do to it inside your function is retained in the calling function

void foo(int a)
{
    a += 5;
}

void bar(int * a)
{
    *a += 5;
}

int main()
{
    int a = 3;
    std::cout << "a is: " << a << std::endl;  // will be 3
    foo(a);
    std::cout << "after foo() a is: " << a << std::endl;  // will be 3
    bar(&a);
    std::cout << "after bar() a is: " << a; // will be 8
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Can you post what you have right now?

NathanOliver 429 Veteran Poster Featured Poster

Thanks for that little tidbit Mike. Didn't know they did that.

NathanOliver 429 Veteran Poster Featured Poster

can you attach you master.dat to the forum so when can have the actual file? You might have to rename it to a .txt file to attach it.

NathanOliver 429 Veteran Poster Featured Poster

this is the data i used for master.dat

jones 44
smith 74
thomas 88
ralph 56
sue 90
jane 73
mavis 77
joyce 33
pete 56
jacob 28
emily 99
michael 89
madison 45
joshua 85
hannah 92
matthew 10
emma 65
ethan 23
alexis 8
joseph 56
ashley 83

and this is what i got in output.dat

alexis 8
matthew 10
ethan 23
jacob 28
joyce 33
jones 44
madison 45
ralph 56
pete 56
joseph 56
emma 65
jane 73
smith 74
mavis 77
ashley 83
joshua 85
thomas 88
michael 89
sue 90
hannah 92
emily 99
NathanOliver 429 Veteran Poster Featured Poster

I cant say what is going on. I would suggest you follow pseudorandom21 advice and change how you read the file in. With that said I did an exact copy and paste of you data file you provided and the code you provided. The only things I changed in your code was to delete line 132 and I commented out lines 94-120 and lines 144-160.

NathanOliver 429 Veteran Poster Featured Poster

I compiled your code and the only thing I had to change was to delete line 132. When working with iterators like you are you don't need to step one back from the the end. I could not get a duplicate of the data in the output though so I'm not sure why you are

NathanOliver 429 Veteran Poster Featured Poster

I would suggest you read the file one line at a time using getline. After you read in the line pass it to a function that will go through the string and check for lowercase letters. Here is a way to get a counter for the lowercase letters

int main()
{
    int lowercase[26];
    for (int i = 0; i < 26; i++)
        lowercase[i] = 0;
    // check string for lowercase letters
    if (letter == lowercase letter)
        lowercase[letter - 97] += 1;
}
NathanOliver 429 Veteran Poster Featured Poster

to sort the list using sort you would have to do

sort(theList.first(), theList.end(), compareFunction);

the compareFunction is one that you would have to write to compare the avg of one object to the avg of another object. this should help you out.

NathanOliver 429 Veteran Poster Featured Poster

well if you have the read the data in from the file. store the names into an array of a string and the gpa into an array of doubles. I'm not exactly how you are supposed to be sorting the information. the trick is that when you are sorting one of the arrays you need to do the swap in the other array. lets say you have

string names[20];
double gpa[20];

when you swap gpa[2] and gpa[5] you also need to swap names[2] and names[5].

NathanOliver 429 Veteran Poster Featured Poster

First yes you would make an associative container. second the reason i made it char[][] is so that you can store all of the words in one array. if it was just char[] you could have only one word. like char temp[] = "five"; . having it as char[][] you can do char temp[3][20] = {"one", "two", "three"}; . the first part is for how many words you need and the second part is for the size for each word.

NathanOliver 429 Veteran Poster Featured Poster

Alright. I would suggest using two arrays then. the first array would be of type char[][] and the second array would be of type int[]. the first array you would populate with all of the cases that you are going to encounter. start it with "one" then "two" and keep going to "nine". then you will need to add "ten" through "ninety". after that you just have to "hundred", "thousand" and so on. with the integer array you would populate it the same way but you would use the actual number. with those two arrays you can then run through the string and match a word in the string to one of the words in the char[] and then you can use the index you found the word in to find the decimal value in the integer array.

NathanOliver 429 Veteran Poster Featured Poster

how are you getting the string in from the user? is it of type string or is it a c-style string i.e. char[]?

NathanOliver 429 Veteran Poster Featured Poster

You are right to assume that there will be some code to write but its not that much. If you are going from a five hundred and fifty to 550 needs 3 tables. If you can use the STL than using a map you would be a great way to go. If you cant use The STL then it gets a little more complicated but not much. Let Me know if you can use STL and I can help you Figure out how to code this.

NathanOliver 429 Veteran Poster Featured Poster

yes you can compare a int to a hex number. this should work

UINT32 foo = 20;
if (foo == 0x14)
    cout << "woot";
else
    cout << "dooh";
NathanOliver 429 Veteran Poster Featured Poster

Why don't you think your first piece of c++ code wont work?

NathanOliver 429 Veteran Poster Featured Poster

if you are asking how to ask for a password then just ask for it inside the while loop. Replace password = "abc123"; with code to ask the user for there password and then retrieve the password.

NathanOliver 429 Veteran Poster Featured Poster

Doing the way you have done would not require 60 cases but why would you want to do it this way? It seems to me that it adds another layer of complexity. Since you are still using the if statements why not do the calculation in the body of the if statement?

//...
if (checks < 20) {check_fees = 0.10 * checks;} 
else if (checks => 20 && checks < 40) {check_fees = 1.90 + 0.08 * (checks - 19)} 
else if (checks => 40 && checks < 60) {check_fees = 1.90 + 1.52 + 0.06 * (checks - 39);}
else {check_fees = 1.90 + 1.52 + 1.14 + 0.04 * (checks - 59)}
//...
NathanOliver 429 Veteran Poster Featured Poster

@ Nathaniel using a switch statement would be less than ideal in this case because you have a large range of numbers to work with. Even with fall through you would still need to have 60 cases.

NathanOliver 429 Veteran Poster Featured Poster

you need to include is_prime.h in your is_prime.cpp file.

NathanOliver 429 Veteran Poster Featured Poster

on lines 15 and 17 you are setting your counter variable to -1. when it tries to access element -1 it throws an error. try setting the variables to 0 and see what happens.

NathanOliver 429 Veteran Poster Featured Poster

This is a nice conversion function at will convert any type that has an << operator.

#include <string>
#include <sstream>

template<typename T>
string ConvertToString(T & value)
{
    std::stringstream ss;
    ss << value;
    return ss.str();
}
NathanOliver 429 Veteran Poster Featured Poster

you need to seperate your while loops.

// you have
while (getline(infile, character)) 
 {
        myStack.push(character);
 

    while (!myStack.empty()) 
	{
       outfile << myStack.top() << endl;
       myStack.pop();           
    }


 }

// should be

while (getline(infile, character)) 
{
        myStack.push(character);
}
 

while (!myStack.empty()) 
{
       outfile << myStack.top() << endl;
       myStack.pop();           
}

also im not sure if you want to use getline. if you want to get each word in the file into its own element in the stack you will have to use ifstream's >> operator like i used in my example.

}

NathanOliver 429 Veteran Poster Featured Poster

lines 19 through 22 are not actually doing anything. you need to get the words from the file in order to push them into the stack. To get the word from the file into your stack you will need to do something like this.

stack<string> Stack;
string word;
ifstream fin("text.txt");
while (fin >> word)
     Stack.push(word);
NathanOliver 429 Veteran Poster Featured Poster

He is using global variables bradonrunyon.

NathanOliver 429 Veteran Poster Featured Poster

all of your function definitions do not name the variables that you are passing to them. You are also declaring the variables that you are passing to your functions globally. You don't need to have any function parameters if you are only using global variables but I suspect that your are supposed to be declaring the variables in main and then passing them to your functions. there also seems to be some accessing of array elements that are out of bounds but its hard to tell without any indention in your code.

NathanOliver 429 Veteran Poster Featured Poster

what happens if you change line 32 to

double root = sqrt(double(number)) + 1;

[EDIT]
I think you might also want to recheck the way you are incrementing your test variable.

NathanOliver 429 Veteran Poster Featured Poster

if you want to take data in as a string and convert it you can do:

// you have to have these
#include <strstream>
#include <string>
int number;
std::string input;
std::stringstream ss;
cout << "enter number: ";
getline(cin, input);
ss << input;
ss >> number;  // now number is filled with the number from input;

Here is a handy little function I wrote that works like this

template <typename T>
void StringToNumber(std::string number, T & output)
{
    std::stringstream ss;
    ss << number;
    ss >> output;
}
NathanOliver 429 Veteran Poster Featured Poster

if you want to store the address of that element in you vector than you can do

vector<int*> stack
stack.push_back(&(array[1][1]))

if you are trying to store the value of x and y values you can use a 2d vector like

vector< vector<int> > stack
vector<int> temp;
if (array[x][y] == something)
{
    temp.push_back(x);
    temp.push_back(y);
    stack.push_back(temp);
    temp.clear();
}

although this might not be the best way to do it.

aravind rao commented: Great helpful post +0
NathanOliver 429 Veteran Poster Featured Poster

Are you sure that ContactPtr is holding a BCorp and that it is getting cast right? Also why are you casting objects to a double * in you contact object.