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

Are you using a third party library? If so you need to tell visual studio where those header files are. You can do that going to [ Project -> Properties -> C/C++ -> General -> Additional Include Directories ].

7d01513d51bacda2fd1dcff839c04a84

NathanOliver 429 Veteran Poster Featured Poster

Is the image you poseted the inventory table?

NathanOliver 429 Veteran Poster Featured Poster

what are the actual columns in the database? What are the types and what do they store?

The query just gives the lowest slot number availible in the inventory table where there is no item in that slot. This is if slot is a column.

NathanOliver 429 Veteran Poster Featured Poster

Get rid of line 10 and it should work fine.

NathanOliver 429 Veteran Poster Featured Poster

You can use Code::Blocks, Visual Studio Express or a host of others.

NathanOliver 429 Veteran Poster Featured Poster

Do you actuall have a slot column in the database? if so you can use

select min(slot)
from inventory
where item_id is null

I'm not quite sure if that is correct for MySQl since I use Oracle PL/SQL but that should be the gist of it.

NathanOliver 429 Veteran Poster Featured Poster

If you go to [ view -> error list ] is there anything in the error list?

NathanOliver 429 Veteran Poster Featured Poster

Yes. Now you need to compile it.

NathanOliver 429 Veteran Poster Featured Poster

If the files were not part of a previous project then you need to create a new blank project and then add the files to it.

NathanOliver 429 Veteran Poster Featured Poster

Don't use that code. That code is terrible. What are you trying to do? Oh yeah did I mention DON'T USE THAT CODE.

NathanOliver 429 Veteran Poster Featured Poster

Here you go.

NathanOliver 429 Veteran Poster Featured Poster

What is your definition of "not working"?

NathanOliver 429 Veteran Poster Featured Poster

Try making if(index>=childcontrolsindex) if(index>childcontrolsindex)?

NathanOliver 429 Veteran Poster Featured Poster

Without running your code the one thing that sticks out to me is

for (forwardTIterator=theRef.cbegin(), backwardTIterator=(theRef.crbegin()+1);
     forwardTIterator!=theRef.cend();
     forwardTIterator++,backwardTIterator++)

Why are you using backwardTIterator=(theRef.crbegin()+1)? Shouldn't it be backwardTIterator= theRef.crbegin() since crbegin() points to the last element of the container. Here is a good link for crbegin(). It is for vectors but is the same throughout the STL.

NathanOliver 429 Veteran Poster Featured Poster

That's not a question. What is your question? We only give homework kelp to those that show effort.

NathanOliver 429 Veteran Poster Featured Poster

What is the code you are using now? Is it not working?

NathanOliver 429 Veteran Poster Featured Poster

What is the code that you have and what is the error the compiler is giving you?

NathanOliver 429 Veteran Poster Featured Poster

Well thats easy enough to change the code to do that. I am not writing your program for you. I am showing you how it could be done. You should be able to handle getting user input and putting it into a string.

NathanOliver 429 Veteran Poster Featured Poster

This would be the simplest way I can think of to do it.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string info = "R Y, 123-45-6789, ya123, abcd1234";
    // social starts 2 places after the first coma
    size_t ssStart = info.find_first_of(",", 0) + 2;
    info.erase(ssStart, 11);
    info.insert(ssStart, "XXX-XX-XXX");

    // password starts 1 place after the last space
    size_t passStart = info.find_last_of(" ") + 1;
    size_t passSize = info.size() - passStart;
    // get rid of the password
    info.erase(passStart);
    // make a string with all X's the size of the password and ad it to the end
    info += string(passSize, 'X');
    cout << info;
    cin.get();
    return 0;
}

All done in 24 lines with comments and blank lines(fist pump).

NathanOliver 429 Veteran Poster Featured Poster

The way I would do it without using the stl would be like this

#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin("data.txt");
    int scroes[101];

    // make all scores 0
    for (int i = 0; i < 101; i++)
        scores[i] = 0;

    // read file and fill array
    int temp;
    while (fin >> temp)
        scores[temp]++;

    // display
    for (int i = 0; i < 101; i++)
        if (scores[i] > 0)
            cout << i << "\t" << scores[i];
}

If you need to output to contents of the file at then end then you would need a second array and you would put each score into that array inside the while loop.

NathanOliver 429 Veteran Poster Featured Poster

You can use the functions that I descrided in my previous post. Check this reference out for everything you can do with a string object.

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
arrySize = 1;

for(int i = 0; !scorFil.eof(); i++ && arrySize++)//for loop for the readable file, collect the scores
{                                                //the array size is incremented as well
    scorFil >> score;
    arry[i] = score;
}

Becomes

arrySize = 0;
int i = 0;
while(scorFil >> score)
{
    arry[i++] = score;
    arrySize++;
}
NathanOliver 429 Veteran Poster Featured Poster

You dont need to. You can use the functions of the string and do all of this with the string and then just output the string when completed.

NathanOliver 429 Veteran Poster Featured Poster

Well if you assume that no name has a number in it then to find the social in the line you would do size_t spot = line.find_first_of("0123456789"). Once you have that you can erase the social from the string and then insert into it "XXX-XX-XXXX". After that you would have to find the password and you can get that by doing line.find_last_of(",") since the last comma in the string comes right before the password. Once you know where the password starts then you need to find out how long that is by taking the size of the string minus where the password start. Then you erase the end of the string where the password is and add to the end of the line string(passwordSize, 'X'). All total this would be like 10 to 20 lines of code.

As a side note you are using at() in your program. since [] = at() for the most part I doubt your teacher will let you use it as well.

NathanOliver 429 Veteran Poster Featured Poster

Okay, lets break this down a little. If we want to print the backwards Z and we have a nested for loop like you have what are the conditions of i and j that would print an X

   jjjjj
   01234
i0 XXXXX
i1  X      
i2   X    
i3    X  
i4 XXXXX

From the above picture we can see that if i == 0 or i == 4 print X so that coves the top and bottom rows. Now to get the diagonal you can see that i and j equal each other where there is an X so that would be if i == j print X. So to pat that all together we get (this is pusedo code):

for i = 0 to i == 4
    for j = 0 to j == 4
        if i == 0  or i == 4 print "X"
        else if i == j print "X"
        else print " "

For printing the normal Z the first if is still code but wee need to change the second one.

   jjjjj
   01234
i0 XXXXX
i1    X    
i2   X    
i3  X    
i4 XXXXX

From the above we can see a patter amerge with when to print an X. The X's are at (i, j): (1, 3) , (2, 2) , (3, 1). If you add the pairs for each one of those you get 4 so you would have an if like if i + j == 4 print …

NathanOliver 429 Veteran Poster Featured Poster

That still doesnt show us what you have. Even if it doesnt compile show us what you are doing and we can help to get it to work.

NathanOliver 429 Veteran Poster Featured Poster

Make the access for all of the class members public in the nested class and declare the nested class in the private part of the main class. this way you can access the members directly but only from within a function of the main class. If you don't want the nested class data to be public you could make it private and make the main class a friend of the nested class to get direct access.

NathanOliver 429 Veteran Poster Featured Poster

What do you have so far? We only give homework help to those that show effort.

NathanOliver 429 Veteran Poster Featured Poster

With arrays I am in favor of having the caller suppling the 1d array to the function. That way the caller knows they are responsible for the array. It's a shame that dont just start of with using the STL and after they are comfortable with it teach them how it works under the hood.

NathanOliver 429 Veteran Poster Featured Poster

Out of curiosity what happens if you define your constructor in the class in the header file instead of the .cpp file?

NathanOliver 429 Veteran Poster Featured Poster
cout<<" Inode number: "<< sb.st_ino;

You only need the long if you want it explicitly cast to a long. If you do want to cast and you want the code to be c++ then you could do this:

cout<<" Inode number: "<< static_cast<long>(sb.st_ino);
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

You can use cout to debug. Just output parts that are questionable or you are not sure what the value is. You don't need to actually step through a debugger to debug code.

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

What is the error you are getting?

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

I would take a look at this. I have reads some review though that call this a second class citizen compared to MS C#

NathanOliver 429 Veteran Poster Featured Poster
if (!(assignment == complete))
    if (today > dueDate)
        return failure;
    else
        output << "Get working on your code.  We only give help to those that show effort and code!!"
ddanbe commented: Witty! +15
NathanOliver 429 Veteran Poster Featured Poster

What do you have so far?

NathanOliver 429 Veteran Poster Featured Poster

Java being programmed to make bad code harder to write

I don’t think there is a language on earth that makes bad code harder to write. I do understand why the designer decided to not let it in It just kills me that people think it is the language feature that is dangerous when in actuality it is inexperienced programmers that are dangerous.

NathanOliver 429 Veteran Poster Featured Poster

I have stepped through your code and it is working and putting new players in open slots. One thing with it is that every time you enter the function SelectRandomSlot(vector<Player> &Draw) the seed is the same for the random number generator and it is generating the same sequnce every time. this could cause some very long delays as you get father down the list of players. You might want to look at creating enough players to fill the open spots in the vector and then using random shuffle to mix them up and then just insert them into the first blank spot you get to. The why I have your code when i tested it is as follows:

#include <iostream>
#include <string>
#include <random>
#include <algorithm>
#include <functional>
#include <vector>

using namespace std;

class Player
{
public:
    Player()
    {// initialize to 0.0 to indicate 'empty'
    Strength = 0.0;Ranking = 0.0;ATPPoints = 0.0;}

    Player(double val){Strength = val;Ranking = 0.0;ATPPoints = 0.0;}

    virtual ~Player() {}

    double GetStrength() const{return Strength;}

    void SetStrength(double val){Strength = val;}

    int GetRanking() const{return Ranking;}

    void SetRanking(int val){Ranking = val;}

    int GetATPPoints() const {return ATPPoints;}

    void SetATPPoints(int val){ATPPoints = val;}

protected:
private:
    double Strength; //!< Member variable "Strength"
    int Ranking; //!< Member variable "Ranking"
    int ATPPoints; //!< Member variable "ATPPoints"
};

// function prototypes
void GeneratePlayerStrengths(vector<Player> &Players);
bool SortMethod(const Player &i, const Player &j);
int SeedPlayer(int rank, int partSize);
int SelectRandomSlot(vector<Player> &Draw);
void CreateTournament(vector<Player> &Players, std::vector<Player> &Draw);

int SelectRandomSlot(vector<Player> &Draw)
{
    for (Player& p : Draw)
    {// outputz …
NathanOliver 429 Veteran Poster Featured Poster

There is nothing wrond with using the function provided by the STL. You are using string so you might as well use what string offers.

char stri[]="hello";
cout<<sizeof(stri);

In the above code you get six becasue if you look at stri in memory it looks like this 'h', 'e', 'l', 'l', 'o', '\0' where '\0' is how null is represented as a string character. Now the array that the string objects holds onto may or may not be the same but since it is a class it can have a member variable that keeps track of the size. With c style strings aka char stri[]="hello"; you need the null at the end to mark where the string ends when passing it to functions. Otherwise you would need to always keep track of the size of the array and pass it to functions like you do when dealing with arrays of numbers.

As a side note when you write char stri[]="hello"; it is exactly the same as writing char stri[] = {'h', 'e', 'l', 'l', 'o', '\0'};.