NathanOliver 429 Veteran Poster Featured Poster

Line 69-73 should be

if (list[i] > list[winInd])
{
    winInd = i;
}

What you originally have is if the votes are less then zero then set the index to the number of votes. What I wrote says is if the votes at this index are more than the votes at the first index then set the index to this one.

NathanOliver 429 Veteran Poster Featured Poster

If you run into anything else just post it.

NathanOliver 429 Veteran Poster Featured Poster

It really depends what you want to do. You can read the entire file into a some sort of container like a vector and then pull data out of the vector as needed. Another way is you can just read only the data you want out of the file to keep the size lower. If you read all of the file into a vector and want to just look for a particular day or range of dates then you could do something like

vector<PriceInfo> data // stores the entire file
set<PriceInfo, comparePrice> smallSet // to put only sepecific days to get the lowest price
vector<PriceInfo>::const_iterator it = data.begin(), end = data.end();
string lowerDate, upperDate;  // for storing the date range
while (it++ != end)
{
    if (it->date >= lowerDate && it->.date <= upperDate)
        smallSet.insert(*it);
}

Alternately if you only want to read in from the file only the days you need you could do something like

set<PriceInfo, comparePrice> smallSet // to put only sepecific days to get the lowest price
string lowerDate, upperDate;  // for storing the date range
ifstream fin("somefile.txt");
PriceInfo reader;
while (fin >> reader) // assume you define a >> operator for PriceInfo
{
    if (reader.date >= lowerDate && reader.date <= upperDate)
        smallSet.insert(reader);
}
NathanOliver 429 Veteran Poster Featured Poster

Well you could store the data in a set and define a comparison function that sorts the data by the lowest price. After reading the contents into the set and the first element of the set should be the one with the lowest price.

class comparePrice
{
    bool operator()(const PriceInfo & lhs, const PriceInfo & rhs) const
    {
        return lhs.low < rhs.low;
    }
};

//  inside code
set<PriceInfo, comparePrice> data;
// add data to the set and it will be sorted by the lowest price field.
NathanOliver 429 Veteran Poster Featured Poster

Well what do you have so far? As far as using a c-string or a string object you can have you function take in a char * and then convert it to a string like

void foo(const char * bar)
{
    string temp(bar);
    // do stuff
}

As far as the functionality of the program you might want to look into the count function in the <algorithms> header. you can find a good link here.

NathanOliver 429 Veteran Poster Featured Poster

Well you can read the Mcust_num of masterfile into some sort of array like a vector or a plan old array. Then you can loop through the array and using the find function from the <algorithms> header call find on the current record that you are on and if you find another one then you would have a duplicate.

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

You might want to look here

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

Can you post the code you have now?

NathanOliver 429 Veteran Poster Featured Poster

I made the comment about the size because I'm not sure where in the code the actual error is happening at. I also think the OP might want to just have a pointer. Not sure if it is better to have pointer to a 2d array like

double my_a***;

or a pointer for a 2d array as you posted Vernon

NathanOliver 429 Veteran Poster Featured Poster

What is the size of the array that you are using? Are you sure you never try to read past the end of the array? If the array is very large I would suggest putting it into the free store and not into the heap by dynamically allocating the array.

NathanOliver 429 Veteran Poster Featured Poster

I'm pretty sure the problem is coming from the fact that you are mixing input types. What happens if you change line 82 to

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

You will have to include the <limits> header for this to work

NathanOliver 429 Veteran Poster Featured Poster

the reason you are only getting one set of inputs from the file is because you only read it once. On lines 26 and 27 you read in from the files and store the data into your variables and that is the only time you put anything into those variables. I would suggest doing something like

//...
ifstream masterfile ("masterfile.txt");
ifstream transactionfile ("transactionfile.txt");
if (masterfile.isopen() && transactionfile.isopen())
{
    while (masterfile >> Mcust_num >> Mcust_name >> Mlast_name >> Mcust_bal &&
           transactionfile >> Tcode >> Tcust_num >> Titem_name >> Tquant >> Tcostpay)
    {
        // your code here
    }
//...
}
NathanOliver 429 Veteran Poster Featured Poster

well you could do something like

///...
srand(unsigned(time(NULL)));
int prevRoll = 0;
int roll = (rand() % 6 + 1) * 2;
while(prevRoll != roll)
{
    std::cout << "you rolled a: " << roll << std::endl;
    prevRoll = roll;
    roll = (rand() % 6 + 1) * 2;
}
NathanOliver 429 Veteran Poster Featured Poster

What point do you want it to reach. That will determine where you want to put your loop.

NathanOliver 429 Veteran Poster Featured Poster

I believe you need to forward declare one of your classes.

NathanOliver 429 Veteran Poster Featured Poster

before calling rand() you need to use srand(). something like this should help

srand(unsigned(time(NULL)));
//...
number = (rand() % 6) + 1;
NathanOliver 429 Veteran Poster Featured Poster

If you problem is that you are getting the same number every time it is because you are never calling srand()

NathanOliver 429 Veteran Poster Featured Poster

this might help you out

NathanOliver 429 Veteran Poster Featured Poster

Have you tried to do a clean rebuild of the project? I believe it called rebuild all.

NathanOliver 429 Veteran Poster Featured Poster

Please post the code that you have right now.

NathanOliver 429 Veteran Poster Featured Poster

What you have posted here has carraige returns in it. I put it note pad and made it all one line and i was able to paste it into the console. I'm attaching the .txt file I used.

NathanOliver 429 Veteran Poster Featured Poster

I was still able to after pasting it in. I even used your code and I was still able to paste it it and get the whole line back. IDK what is going on. What OS are you using.

NathanOliver 429 Veteran Poster Featured Poster

As far as I can tell it should read as much as much as you type untill it hits a carriage return. I wrote a little test to show this

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string temp;
	cout << "Enter a big line of text: ";
	getline(cin, temp);
	cout << "\nI got: " << temp;
	cin.get();
	return 0;
}

I typed in 5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555 555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555222222222222
and got the same thing back.

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

Well if you read up on using ofstream from the <fstream> header you should be able to figure it out. Here is a good link for <fstream> http://www.cplusplus.com/reference/iostream/fstream/

NathanOliver 429 Veteran Poster Featured Poster

What exactly is this for?

NathanOliver 429 Veteran Poster Featured Poster

Came up with this. Should show you one way of doing it.

template<typename RandomAcessIterator>
bool IsLosePalindrome(RandomAcessIterator start, RandomAcessIterator end)
{
	if (start == end - 1)
		return true;
	end--;
	while (start <= end)
	{
		while (ispunct(*start) || isspace(*start))
			++start;
		while (ispunct(*end) || isspace(*end))
			--end;
		if (tolower(*start) == tolower(*end))
		{
			start++;
			end--;
		}
		else
			return false;
	}
	return true;
}
NathanOliver 429 Veteran Poster Featured Poster

Your arrays are defined as six elements.

NathanOliver 429 Veteran Poster Featured Poster

One thing i see right away is that maxqueue should be 6 and not 5. when you check to see if front or back is 5 and if it is set it back to 0 you are never going to read queue[5].

NathanOliver 429 Veteran Poster Featured Poster

I would try MSVS 2010 express edition. The debugger is very nice.

NathanOliver 429 Veteran Poster Featured Poster

To find out something like your first case you would need to do a couple things. First copy the string backwards into another string. Then start at the beginning of each string and check if the charectures match. I would pass both through either toupper() or tolower() so you can disregard case. If you hit a space or punctuation then skip it and check the next spot in the string.

NathanOliver 429 Veteran Poster Featured Poster

I ran the code through my debugger and it looks like values are not being reset like they should. I also think you need to null out an element after it is deleted. That should help to find out what is going on. If you are using an IDE I really suggest you step through the code and look at the behavior.

NathanOliver 429 Veteran Poster Featured Poster

You can only overload an operator that is defined in c++. You cant make a # operator that swaps 2 numbers for example. As for third question if a is a user defined type you can do such a thing. In fact overloading an operator does just that. Take this for example.

class foo
{
    int bar;
    foo & operator=(const foo &);
};

foo & foo::operator=(const foo & foobar)
{
    bar = foobar.bar;
    return *this;
}

int main()
{
    //...
    foo a,b;
    a.bar = 5;
    // now assign a to b
    b = a;
    // or you could write it like
    b.operator=(a);
    // it is the same thing its just the first version is easier to read
    //...
}
NathanOliver 429 Veteran Poster Featured Poster

Please post the code you have so far. We cant see your screen from here.

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

Do you have to explain code someone else wrote for your exam?

NathanOliver 429 Veteran Poster Featured Poster

IF you want to have 3 colums with 10 rows each then you are going to need 2 loops. One loop controls what row you are on and the other loop will control what colomn you are in. Look at this loop

string foo[41]
for (int i = 0; i < rows; i++)
{
    cout << foo[i];
}

This loop would only print out just the rows. So now we have to put another loop inside the row loop to print the seperate colums.

for (int i = 0; i < rows; i++)
{
    for (int j = 0; j < cols; j++)
    {
        cout << foo[...]
    }
}

I left then index blank for you to figure out. If you go through it step by step you should figure out how to use i and j to get the right value. Look at what index starts each row. In this case it would be 0,3,6,9,12... and the ending index of each row is 2,5,8,11,14...

NathanOliver 429 Veteran Poster Featured Poster

Please use English when posting on this formun. Another thing, you do realize this thread died over 2 years ago?

NathanOliver 429 Veteran Poster Featured Poster

var1, var2, var3 were just example names. for each cout line you need to use the proper variables from the correct class. So line 40 would look like

<< "The volume of box 1 is "<< volume(box1.m_Length, box1.m_Width, box1.m_Height);

And line 43 should be

<< "The volume of box 2 is "<< volume(box2.m_Length, box2.m_Width, box2.m_Height);

I will leave line 46 for you to do. This is why I suggested that you make volume a member function of the CBox class. It is much easier to code if you just have to use box1.volume() .

NathanOliver 429 Veteran Poster Featured Poster

You have a close curly brace after your while statement that shouldn't be there. Please re post your code with code tags to make it easier to read. Also you might want to look up proper indenting and code formatting styles.

NathanOliver 429 Veteran Poster Featured Poster

To make volume a member function you simply need to do this

class CBox
{
   // stuff you already have
   double Volume();
};

double CBox::Volume()
{
    return m_Length * m_Height * m_Width;
}

//now in your code

cout << "The volume is: " << box.Volume();
NathanOliver 429 Veteran Poster Featured Poster

Please post your current code

NathanOliver 429 Veteran Poster Featured Poster

Lines 37,40 and 43 are just using the variable volume not the function. To use the function volume you need to do

cout << endl << "The volume of box 1 is "<< volume(var1, var2, var3);

You might want to rethink your volume function though. It would look cleaner if you were to just pass the CBox object to the function and have it call the members from there. IMHO I would make volume() a class member function and then you could just do

CBox box;
// set sizes;
cout << "The volume is: "; << box.volume();
NathanOliver 429 Veteran Poster Featured Poster

What error are you getting? If you are not getting an error what is happening?

NathanOliver 429 Veteran Poster Featured Poster

My motivation is that there is always something to learn.