NathanOliver 429 Veteran Poster Featured Poster

What? Isn't copy and paste a skill?

NathanOliver 429 Veteran Poster Featured Poster

If you need to be able to change a variable at any time why not store everything as tokens? Then the token for a variable can hold onto the variable and the value of it. When you read in the expression you would tokenize the string and create a stack, list or vector of tokens. Then you could change variables at any time.

NathanOliver 429 Veteran Poster Featured Poster

When the function exits are you updating the original expression to be the modified? If not then this will always happen. I think you need to store the modified expression in the class and when you first set the expression set the modified expression to be the same as the original. then whenever you call a function that modifies the expression use the modified expression.

NathanOliver 429 Veteran Poster Featured Poster

modifiedExpr = originalExpr; needs to be moved outside the loop. The way you have it now is every time the loop is executed modifiedExpr becomes the original again erasing what you just did.

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

Try

p = make_pair(112,"one-one-two");
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

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

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

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

Since you are dealing with strings shouldn't ostream_iterator<int> output(cout," "); be ostream_iterator<string> output(cout," ");?

NathanOliver 429 Veteran Poster Featured Poster

Get rid of line 10 and it should work fine.

NathanOliver 429 Veteran Poster Featured Poster

Well you are calling getline and get so you need to hit enter twice. What is the purpose of using cin.get() in your if statement? getline will toss it out so there would be nothing there.

NathanOliver 429 Veteran Poster Featured Poster

Okay I compiled this on my machine at home running MSVS 2012 Ultimate. As I mentioned earlier I had to comment out the functions called in main that were not defined yet to get it to link. I am attaching the files to this so you can see how I have each file. I had to put them in a zip file to attach them.

NathanOliver 429 Veteran Poster Featured Poster

You are correct about the default values. I normally just write my constructors that are defaults in the .h file.

I put the code that you last posted in MSVS 2013 express and it compiled and entered the function correctly. I enven turned wipeRecords() into the following to make sure I had a valid object.

void wipeRecords(fstream& theFile)
{
    HardwareRecord temp; //still get the error here
    temp.setPrice(10.52);
    cout << temp.getPrice() << endl;
    for (int i = 0; i < 100; i++)
    {
        //convert record from binary and assign to temp
        //make temp "wipe itself"
    }
}

I did have to comment out all of the function calls that you haven't declared yet for it to link correctly.

NathanOliver 429 Veteran Poster Featured Poster

You are not including the default values on line 27. The prototype and the definition should match.

NathanOliver 429 Veteran Poster Featured Poster

This is how I would structure the code. If you are going to use OO principles then use them fully.

class Student
{
private:
    string lastName;
    string firstName;
public:
    /// default constructor
    Student() {}
    /// default destructor
    ~Student() {}
    /// getter functions
    string getLastName() const { return lastName; }
    string getFirstName() const { return firstName; }
    /// setter functions
    void setLastName(string ln) { lastName = ln; }
    void setFirstName(string fn) { firstName = fn; }
};

Then you need a classroom that will hold on to the students and where the classroom is located. The classroom should have functions to add and remove a student and also a way to acess the vector so you can get a list of all of the students in the class room. You will need your standard setters and getters as well. I'll leve that for you to code.

class ClassRoom
{
private:
    int floor;
    int roomNumber
    vector<Student> students;
public:
    //...
};

Then your school class will hold a 2D vector of of classrooms.

class School
{
private:
    int floors;
    int rooms;
    vector<vector<ClassRoom>> classRooms;
public:
    /// constructor
    School(int _floors, _int rooms, int seats)
    {
        floors = _floors;
        rooms = _rooms;
        // make the floors
        classRooms.resize(floors);
        // step through each floor and set the rooms
        for (int i = 0; i < floors; i++)
        {
            classRooms[i].resize(rooms);
        }
        // step through each classroom and set the room and floor
        for (int i = 0; i < floors; i++)
        {
            for (int …
NathanOliver 429 Veteran Poster Featured Poster

Line 22 in your header file does not match line 27 in your cpp file.

NathanOliver 429 Veteran Poster Featured Poster

You need another class. You should have a school class that has a vector of classrooms. The classroom class should hold on to what floor and room number it is. It should also have a vector of students that will hold all of the students that are in that classroom.

NathanOliver 429 Veteran Poster Featured Poster

Yeah I was just reading up on that. If a constructor has all default paramaters in the initialization section then it is treated as a default constructor.

NathanOliver 429 Veteran Poster Featured Poster

Do you need the default constructor marked explict? If not I would remove that and see what happens.

NathanOliver 429 Veteran Poster Featured Poster

change line 18 HardwareRecord(int=0,std::string="",std::string="",double=0.); to HardwareRecord(int account=0,string name="",string description="", double price=0.0);. That should fix it.

NathanOliver 429 Veteran Poster Featured Poster

Well you need to do error checking in your program to make sure the input file opened. You could do this

ifstream inFile("TEST.dat");
if (!inFile)
{
    std::cout << "Error with input file!"
    return 0; // exit program
}
NathanOliver 429 Veteran Poster Featured Poster

ifstream in("TEST.dat"); on lines 49 and 70 needs to be just one decleration done before the switch statement.

NathanOliver 429 Veteran Poster Featured Poster

If you are going to use either wchar_t or wstring then you need to use wfstream for file operations.

NathanOliver 429 Veteran Poster Featured Poster

Well â•  is expressible by the ascii code of 204. As far as working with unicode you might want to look into the std::locale library.

NathanOliver 429 Veteran Poster Featured Poster

There was a thread that I participated in a few years back and maybe you will get some insight from it. It was a natural string comparison challenge by Narue. As an FYI I wouldn't post anything to that thread since it so old. http://www.daniweb.com/software-development/cpp/threads/259447/c-challenge-natural-sorting

NathanOliver 429 Veteran Poster Featured Poster

You could pipe the cmd text to a file and then parse that file for the information that you need.

NathanOliver 429 Veteran Poster Featured Poster

@ OP if you have a compiler that supports c++11 than you can use the std::map initializer list constructor. It would change your code to loo like this

void ArcherArmor::ArcherArmor_shop(){
    soldier_armor = {//name, damage, price
            std::make_pair(1, Armor("Meito Ichimonji", 4, 150, 1)),
            std::make_pair(2, Armor("Shusui", 10, 230, 2)),
            std::make_pair(3, Armor("Apocalypse", 16, 300, 3)),
            std::make_pair(4, Armor("Blade of Scars", 24, 550, 4)),
            std::make_pair(5, Armor("Ragnarok", 32, 610, 5)),
            std::make_pair(6, Armor("Eternal Darkness", 40, 690, 6)),
            std::make_pair(7, Armor("Masamune", 52, 750, 7)),
            std::make_pair(8, Armor("Soul Calibur", 60, 900, 8))
        };
}
NathanOliver 429 Veteran Poster Featured Poster

Get rid of line 14. On the last time through your loop you will reach the end node which shouold be null. Then line 14 tries to access it and since it is null it will throw a fault.

NathanOliver 429 Veteran Poster Featured Poster

Try this and let me know If you get the second cout statement

#include <iostream>
using namespace std;

class A
{
private:
   int _dmember;

public:
   void func()
   {
     cout<<"Inside A!! "<<endl;
     cout<<_dmember; // 
   }
};

int main ()

{

    A *a=NULL;

    a->func(); // prints "Inside A!!!" 

    cout << "We are now outside a->func().  If you can see this then your program didnt crash

    return 1;
}
CoolAtt commented: yes it crashed +2
NathanOliver 429 Veteran Poster Featured Poster

On all of your loopps you are running to SIZE. If the user does not enter 100 elemtents then you will be using elements that have not been used. you need to change all of the for loops to run to count and that should fix it.

NathanOliver 429 Veteran Poster Featured Poster

Are you trying to use a shared_pointer which has a count of how many objects hold the pointer?

NathanOliver 429 Veteran Poster Featured Poster

If you want to retain what was held in the vector then before you exit your program you must write that information to a file. Then you also have to change your code so that when the program loads it loads the file into memory. Files are the only way I know of to make data persistent between launches of a program.

NathanOliver 429 Veteran Poster Featured Poster

That's a great attitude to have. To have main() return an int is in the standard for a reason. Some systems need that value returned from main() for them to function correctly. Some compilers will not even compile your code because of it. Just because you use it and you haven't had a problem does not mean it will work everywhere.

NathanOliver 429 Veteran Poster Featured Poster

The fact that the standard forbids it. main() only ever returns an int.

NathanOliver 429 Veteran Poster Featured Poster

What do you need help with? What code do you have so far? If "help me please" is slang for "give me code" then you will find no one is going to "help" you.

NathanOliver 429 Veteran Poster Featured Poster

@Tumlee I know there is one for strings but it does not have a way to control how many characters are received in. The getline for char* does have that ability though.

NathanOliver 429 Veteran Poster Featured Poster

You dont want to use magic numbers. You want to use the constants that are supplied.

NathanOliver 429 Veteran Poster Featured Poster

Have you ever used getline()? you would have to use a char* but it should work nicely.