NathanOliver 429 Veteran Poster Featured Poster

the startingExpr member of your Expression class holds the final value which is 5 + 3 + sqrt 25 - 3

NathanOliver 429 Veteran Poster Featured Poster
void Expression::instantiateVariable(char var_, int val_)
{
    cout << startingExpr << endl;
    instantiateVariable(startingExpr,var_,val_);
}

Becomes

void Expression::instantiateVariable(char var_, int val_)
{
    instantiateVariable(startingExpr,var_,val_);
    cout << startingExpr << endl;
}

If you want to see what the expression look like after the replacement.

If you cant change the signature of

void Expression::instantiateVariable(string startingExpr, char var_, int val_)

Then you can use

instantiateVariable(string & startingExpr, char var_, int val_)
{
    size_t pos = 0;
    stringstream ss;
    ss << val_;

    while ((pos = startingExpr.find(var_, pos)) != std::string::npos)
    {
        // use one here since a char can only have 1 symbol.
        startingExpr.replace(pos, 1, ss.str());
        pos++;
    }
}

Notice I used a reference for startingExpr so that the function modifies the value. Otherwise you would need to return the string.

NathanOliver 429 Veteran Poster Featured Poster

I take you have something like "x + 5" and you want a function that searches the expression for the variable and replaces it with a number. To do that you can use this:

// make var_ a string to handle variables like "xx", "someval"
instantiateVariable(string startingExpr, string var_, int val_)
{
    size_t pos = 0;
    stringstream ss;
    // load int into string stream
    ss << val_
    // while we find the variable
    while ((pos = startingExpr.find(var_, pos)) != std::string::npos)
    {
        // at the spot of the variable replace the size of the variable
        // with the string contents of ss.
        startingExpr.replace(pos, var_.size(), ss.str());
        pos++;
    }
}

One question you need to ask is do you really need an int for this function or can you pass it a string that represents the value? If you pass it a string then the function becomes:

instantiateVariable(string startingExpr, string var_, string val_)
{
    size_t pos = 0;
    while ((pos = startingExpr.find(var_, pos)) != std::string::npos)
    {
        startingExpr.replace(pos, var_.size(), val_);
        pos++;
    }
}

I have not tested this but it should work.

NathanOliver 429 Veteran Poster Featured Poster

And your qustion is?

NathanOliver 429 Veteran Poster Featured Poster

Honestly I never use the wizzard. I just write the code.

NathanOliver 429 Veteran Poster Featured Poster

Well << is the shift bits to the left operator. Since the default value for FOO_ENUM is 0 you get:

unsigned char sideFilter1 = 1 << FOO_ENUM;
=unsigned char sideFilter1 = 1 << 0;
=unsigned char sideFilter1 = 1;
since 1 left shift 0 is still 1.

Line 4 is a little trickier since you are also using |. | simple says that all bits that are 1 in either number will be 1 in the result. this means 1000 | 1001 becomes 1001. With that line 4 becomes:

unsigned char sideFilter2 = (1 << FOO_ENUM) | (1 << BAR_ENUM);
=unsigned char sideFilter2 = (1 << 0) | (1 << 1);
=unsigned char sideFilter2 = (1) | (2);
// next 2 lines are showing bit representation.
=unsigned char sideFilter2 = (00000001) | (00000010);
=unsigned char sideFilter2 = 00000011;
unsigned char sideFilter2 = 3;
Jsplinter commented: Thank you for the clear explanation. +2
NathanOliver 429 Veteran Poster Featured Poster

Go to Project -> Add Class. That will create a new class and bring up the class wizzard.

NathanOliver 429 Veteran Poster Featured Poster

Are you trying to enter a name like "Nathan Oliver"? if so you need to use getline() and not >>. Don't forget to flush the input stream when mixing getline() and >>

NathanOliver 429 Veteran Poster Featured Poster

Line 6: should be using a string not an int. string nap;

Line 10: get rid of the string decleration. if (nap == "hétfő")

That should clear up some of your errors.

NathanOliver 429 Veteran Poster Featured Poster

string and stringstream need to be qualified with std:: or you need to put using namespace std; in your code after you includes.

NathanOliver 429 Veteran Poster Featured Poster

When I read an unknown amount of data from a file I will use the following

std::vector<int> data;
ifstream fin("sampleData.txt");
int temp;  // used to store the data from the file temporarily

//use >> operator to control the loop so you end on the last good read
while (fin >> temp)
{
    data.push_back(temp);
}

Alternatively you can use std::copy and istream iterators

std::vector<int> data;
ifstream fin("sampleData.txt");

std::copy(std::istream_iterator<int>(fin), std::istream_iterator<int>(), std::back_inserter(data));
NathanOliver 429 Veteran Poster Featured Poster

Here you go.

personally unless I need or want to support command line arguments I just use int main()

NathanOliver 429 Veteran Poster Featured Poster

Try

p = make_pair(112,"one-one-two");
NathanOliver 429 Veteran Poster Featured Poster

Okay. And you resurected an 8 month old thread becuase...?

NathanOliver 429 Veteran Poster Featured Poster

Line 35 should use rowSize not colSize. This is because you are stepping through each row and deleting all of the columns.

NathanOliver 429 Veteran Poster Featured Poster

If you call transform on both haystack and needle and have them both lower case then it should work.

NathanOliver 429 Veteran Poster Featured Poster

You need to transform the strings to all lower case. You can use this to do that.

string input = "AbAbbAbBBaAA";
transform(input.begin(), input.end(), input.begin(), ::tolower);
NathanOliver 429 Veteran Poster Featured Poster

The way I have done it is like:

size_t pos = 0;
int counter = 0;
// loop untill substrng is not found.
while ((pos = strng.find(subStrng, pos)) != std::string::npos)
{
    counter++;
    pos++;  // increment pos so we dont duplicate the last search.
}

I am writing this from memory so there might be a bug I am forgetting about.

NathanOliver 429 Veteran Poster Featured Poster

You need the ingnore outside the while loop like I posted. When cin gets the EOF it set the EOF flag which causes cin >> input to be false and the while loop will not execute the last time. I actually switched how it should be done. You need to call clear before you call ignore so it should look like this:

/... end of first while loop
}
cin.clear();
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n')


cout << "\n\nThe contents of firstList object of type List are: " << endl;
firstList.print();
//...
NathanOliver 429 Veteran Poster Featured Poster

Do cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n') before the clear just to make sure the buffer is empty. I think there is still a newline in the buffer. You will need to include <limits> for this.

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

cout << "\n\nThe contents of firstList object of type List are: " << endl;
firstList.print();
NathanOliver 429 Veteran Poster Featured Poster

I bet you need to clear the stream after the first while loop. Add cin.clear() in between the two while loops.

NathanOliver 429 Veteran Poster Featured Poster

I would suggest that when the program starts you read in all of the data in the file and load it into an collection of "Movie Records". Then you can search that collection for the records you want.

NathanOliver 429 Veteran Poster Featured Poster

Generally speaking read and write are used to read and write binary data in files. Normally that goes hand in hand with serialization.

NathanOliver 429 Veteran Poster Featured Poster

Dido. C++ support so many different programing paradimes that can be related to so many different languages.

NathanOliver 429 Veteran Poster Featured Poster

You can do this much easier with the STL. Here is how I normally read a file by line and separate by word:

std ifstream fin ("file.txt");
std::vector<string> docWords;

std::string line;
// Get each line from the file.  Stops when there are no more lines
while(getline(fin, line))
{
    std::stringstream ss;
    // load line into the string stream
    ss << line
    std::string temp;
    // get each word out of ss using >> since each word is seperated by a " "
    while(ss >> temp)
    {
        docWords.push_back(temp);
        temp.clear();
    }
}

As you can see each time you loop in the main while loop that is another line of the file. To get the number of words you need only to call the size() function of the vector since each element in the vector is a word.

NathanOliver 429 Veteran Poster Featured Poster

Change props.emplace(std::pair<string,string>(tokena,tokenb)); to props.insert(std::pair<string,string>(tokena,tokenb));

NathanOliver 429 Veteran Poster Featured Poster

Something like this would work

vector<string> doc;
vector<string> skipWords;

// fill doc and skipWords from there files.  When doing so convert each word to lower case.  Remove any puctuation as well.

//c++11
for(auto i : skipWords)
    doc.erase(remove(doc.begin(), doc.end(), i), vec.end());
NathanOliver 429 Veteran Poster Featured Poster

becuase the functions are templated so you need to specify in the class what template to use.

NathanOliver 429 Veteran Poster Featured Poster

For your case I think it would be like the following like the following

template <typename el>
class Array
{
public:
    friend std::ostream & operator<< <el>(std::ostream& ouput,const Array& a)
    friend std::istream & operator>> <el>(std::istream& input,Array & list)
    //...
};

template <typename T>
friend std::ostream &operator<<(std::ostream& ouput,const Array<T>& a)
{
    //output private ptr-based array
    for (size_t i=0; i < a.size; i++)
    {
        output << setw(12) << a.ptr[i];

        if ((i+1)%4 == 0)   //four numbers per row of output
            output << endl;
    }

    output << endl;

    return output;
}

template <typename T>
friend std::istream &operator>>(std::istream& input,Array<T>& a)
{
    //output private ptr-based array
    for (size_t i=0; i < a.size; i++)
        input >> a.ptr[i];

    return input;   //enable cin >> x >> y
}
NathanOliver 429 Veteran Poster Featured Poster

Since you do not have using namespace std; in your code you need to prepend std:: to everything you are using that is part of the STL. So throw invalid_argument("Array size must be greater than 0") becomes throw std::invalid_argument("Array size must be greater than 0"). I noticed you had it in your .cpp file.

NathanOliver 429 Veteran Poster Featured Poster
do
{
    your_homework();
} while (in_school)
NathanOliver 429 Veteran Poster Featured Poster

Depending on the compiler you are using you might have to have everything in the header file instead of splitting it up like a normal class. I would put everything into the header file and see if that fixes the error.

Also on line 15 in the cpp file you have ptr[i]=NULL; //undefined value. What happens if ptr is of type that can not be equal to NULL? This is why the STL uses allocators

NathanOliver 429 Veteran Poster Featured Poster

As an FYI prerequisite programing classes are very important. Everything you do in higher level programing classes builds off of them.

NathanOliver 429 Veteran Poster Featured Poster

Post the code that you have now.

NathanOliver 429 Veteran Poster Featured Poster

Line 6 in you .cpp is Nvector::Nvector(int Size) : velicina(Size); it should be Nvector::Nvector(int Size) : velicina(Size)

NathanOliver 429 Veteran Poster Featured Poster

Can you show it with the file extensions shown?

NathanOliver 429 Veteran Poster Featured Poster

So rework the class to be a struct.

NathanOliver 429 Veteran Poster Featured Poster

I would suggest you work on getting part one working first and then go on from there.

NathanOliver 429 Veteran Poster Featured Poster

@ tinstaafl You wouldn't write a function like void push (stack *, std::string) if the function is a member of the class. You would write it like void push (std::string) and externally it would be void stack::push (std::string)

NathanOliver 429 Veteran Poster Featured Poster

It looks like that is how your instructor wants this done. Why he would want it like this I have no idea. IMHO he should be cited for endangering the education of a student. You could do this with a class but since you functions need to have access to everything the stack contains I would just use a struct for the default public specifier.

NathanOliver 429 Veteran Poster Featured Poster

Can you post a screen shot of the contents of newproject2 directory in detail view?

NathanOliver 429 Veteran Poster Featured Poster

No doing a print screen will remove the mouse icon. You could always draw on the picture though to show where the mouse was when you took the print screen. I do agree with triumphost that you really need to post a picture of what is happening.

NathanOliver 429 Veteran Poster Featured Poster

For an example using strings and arrays and searching through the array.

//...

const int arraySize = 20;
char string commands[arraySize] = {"quit", "open", "save", "close"};
string command = "save";
cout << in_array(commands, command, arraySize);

//...

int in_array(const string commands[], cont string command, cont int arraySize)
{
    for(int i=0;i<arraySize;i++)
    {
        if(txt==array[i])
        {
          return i;
        }
    }
    return -1;
}

You can get information on std::list here. This site contains a lot of good reference material on the STL.

NathanOliver 429 Veteran Poster Featured Poster

I am asking does O_PSIMP.cpp have #include "O_PV.cpp" in it. If not copy and paste the exact error output here.

NathanOliver 429 Veteran Poster Featured Poster

Why not use an enum class?

In C++ it is possible to create real enum types that are neither implicitly convertible to int and that neither have enumerator values of type int, but of the enum type itself, thus preserving type safety. They are declared with enum class (or enum struct) instead of just enum:

enum class Colors {black, blue, green, cyan, red, purple, yellow, white};

Each of the enumerator values of an enum class type needs to be scoped into its type (this is actually also possible with enum types, but it is only optional). For example:

Colors mycolor;

mycolor = Colors::blue;
if (mycolor == Colors::green) mycolor = Colors::red; 

You can read some more about this Here.

NathanOliver 429 Veteran Poster Featured Poster

Is o_psimp.cpp trying to included o_pv.cpp?

NathanOliver 429 Veteran Poster Featured Poster

You need to set the included directory in your project to wherever "lh_dllnex.h" is located. That header file appears to be from a third party library so you need to make sure you have the library and that it is being included in your projects include directory.

NathanOliver 429 Veteran Poster Featured Poster

Navigate to the folder where the header file is located and then pick "select folder".

NathanOliver 429 Veteran Poster Featured Poster

I would have to agree with deceptikon on this. Read in the database into your code and then figure out where the free slot is.

NathanOliver 429 Veteran Poster Featured Poster

the OP doesnt have any code to pause between the output and the window closing so I would guess that was the issue.