NathanOliver 429 Veteran Poster Featured Poster

I think what you are trying to do is input a word and see if any part of that word matches what you have in a text file. now do you want only sequential letters to make the work or can it be any combination of letters in the inputted word?
Example:
sequential search
"individual" has "in", "divi" and "dual"

or any combination
"individual" has "in", "dual" , "dial", "dan" and "lad"

If you only want sequential letters to make words then you are going to need three loops to accomplish this. The first to control where in the string to start from. The second loop will start from there and go on to the end of the string getting sub strings along the way. The third loop would go through the words in the file and see if the sub string matches any of the strings in the file. At least this is how I would go about.

If you want any combination of letters in the inputted word let us know and we can give you a hand thinking it through. Unless my first assumption was wrong and none of this applies.

NathanOliver 429 Veteran Poster Featured Poster

The reason the first letter is missing is because you are calling ignore before you call getline. You still are passing 2 objects to your functions when you should only be passing one object.

void MovieDisplay(MovieData m1)
// instead of
void MovieDisplay(MovieData m1, MovieData m2)
NathanOliver 429 Veteran Poster Featured Poster

Whats your going rate firstPerson?

NathanOliver 429 Veteran Poster Featured Poster

I'm not exactly sure what you mean by adding or multiplying a file. Also what do mean by reducing the file by a few bytes. A AMD 2 GHZ processor single core will do about 3500 MIPS or 3500000000 instructions per second. A 2 GHZ processor will have 2 billion CPS so if you instruction needs 10 cycles to complete you could do it 200,000,000 times in one second. As for what is an instruction its basically anything you tell the processor to do and instructions have different CPI depending on how complex they are.

Ancient Dragon commented: nice answer +28
NathanOliver 429 Veteran Poster Featured Poster

@ oieronle
We are here to help people with there code not give them the code if they don't have any. Secondly if you are going to post code please use code tags. Third your loop wont work like you think it does. When i is 1 it gets decremented to zero and then the for loop evaluates i and comes up false because i is 0 so you never get the last digit.

NathanOliver 429 Veteran Poster Featured Poster

Yes it is unnecessary. Didn't really think about it I just wrote what first came to mind. Thanks for pointing that out invisal. It could easily be written this way and it is probably faster.

void computeCoin(int coinValue, int& number, int& amountLeft)
{
    number += amountLeft / coinValue;
    amountLeft = amountLeft % coinValue;

}
NathanOliver 429 Veteran Poster Featured Poster

Sorry I thought you were talking about metal fuel lines. Plastic ones as far as I know have to be entirely replaced.

NathanOliver 429 Veteran Poster Featured Poster

Yes you can splice the line. They have some nice fittings that you don't even need to flare the end it will do it for you when you tighten the fitting.

NathanOliver 429 Veteran Poster Featured Poster

I think the hint might be for the the change function and not for the user input loop. the change function you wrote could be rewritten like this

void computeCoin(int coinValue, int& number, int& amountLeft)
{
    if (amountLeft % coinValue == 0)
    {
        number += amountLeft / coinValue;
        amountLeft = 0;
    }
    else
    {
        number += amountLeft / coinValue;
        amountLeft = amountLeft % coinValue;
    }
}
NathanOliver 429 Veteran Poster Featured Poster

Was the hint for how to calculate the change or for how to let the user keep entering in more numbers?

NathanOliver 429 Veteran Poster Featured Poster

Sorry forgot about that part. Thanks for adding that Banfa.

NathanOliver 429 Veteran Poster Featured Poster

well if you want the user to be able to keep inputting a number for the change to be computed the you can wrap the whole thing in a while loop

char ch = 'y';
while (ch == 'y' || ch == 'Y')
{
    // lines 17-44 here
    cout << "Enter 'y' to continue 'n' to stop: ";
    cin >> ch;
}
NathanOliver 429 Veteran Poster Featured Poster

yes there is a rule. types are promoted to a higher type if assigned to a higher type. going from a higher type to a lower type works as well but there can be truncation of the number

int foo = 5;
float bar = 3.5;
float result = foo + bar;
// result is now 8.5 because foo gets converted to a float and then added.

float foo = 3.5;
float bar = 2.14;
int result = foo + bar;
// result is now 5 because foo + bar is 5.64 and converting that to an int you get 5
NathanOliver 429 Veteran Poster Featured Poster

If you want to have really big numbers then you will need to use strings. if you dont need more then 12-15 digits than you do this

#include <iostream>
#include <string>
#include <sstream>

using namespace std;


int main()
{
    long double input;
    string number;
    cout << "Enter a number: ";
    cin >>  input;
    cin.ignore(80, '\n');
    stringstream converter;
    converter << input;
    converter >> number;
    if (number.find_first_of(".", 0) != string::npos)
        cout << "\nthe size of the number is " << number.size() - 1 << " digits.";
    else
        cout << "\nthe size of the number is " << number.size()<< " digits.";
    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Then you should be able to make add virtual in your base class and than have another add with a different signature in your derived class

NathanOliver 429 Veteran Poster Featured Poster

do you want to have two separate add methods in you derived class? one that takes an int and one that takes a void pointer?

NathanOliver 429 Veteran Poster Featured Poster

Well I think I have a solution now that will allow the user to \? to have that be an actual ?. I had to change my approach a little bit and added a couple new functions but it works for the test cases I have tried. I'm just attaching the code again.

NathanOliver 429 Veteran Poster Featured Poster

probably because the compiler is using the public method from your derived class. Secondly why are you using a void * ? Third new is used to create objects on the free store. the proper syntax would be

int * number = new int;
int * numberArray = new int[50];
NathanOliver 429 Veteran Poster Featured Poster

if you want to convert a number to a letter that you take that number plus 'A' and that will give to the letter.

int number = 4
char ch = number + 'A'; // ch is now 'E'

doing this over an array with each element being a single digit is pretty straight forward but to go from 526 to FCG is a little more complex. you will need to % 10 to get the last digit of the the number than convert it. then you /= 10 to get rid of the last digit and then keep going until you have all of the digits. This does present the problem that you will only get A-J as you letters.

NathanOliver 429 Veteran Poster Featured Poster

Do you mean 123 to abc?

NathanOliver 429 Veteran Poster Featured Poster

Well ASCII characters run from 0-255 so any number between 0 and 255 will convert right to an ASCII value

int number = 48;
char character = number; // character is now '0'

Numbers larger than 255 should wrap around but you can always use the % operator

int number = 1068
char character = number % 255; // character is now '0'

If this isn't what your looking for let me know.

NathanOliver 429 Veteran Poster Featured Poster

Just start off with a blank vector and push the objects on.

class Foo
{
    // ...
}

int main()
{
    vector<Foo> container;
    for (int i = 0; i < 10; i++)
    {
        container.push_back(Foo());
    }
}
fandango commented: Thanks for the code example as well. +0
NathanOliver 429 Veteran Poster Featured Poster

1. Get a c/c++ compiler. IDE's are nice and some are free.

2. Write the code for the program you want to create. Make sure to follow go techniques.

3. Compile the program.

4. Use the program you just created.

Follow these four easy steps and you will be on your way.

NathanOliver 429 Veteran Poster Featured Poster
NathanOliver 429 Veteran Poster Featured Poster

queue shouldn't inherit from time, it should be separate.

class Queue_time
{
public:
    Queue_time();
    Queue_time(Time);
    // ...
}

The overloaded << operator will use a loop to go through each element in the queue and print it out. the >> operator will take in the values to create a Time object and then add that time object to the end of the queue.

NathanOliver 429 Veteran Poster Featured Poster

I would suggest stepping through your code with the debugger to see where you are exceeding the memory allocation.

NathanOliver 429 Veteran Poster Featured Poster

So you need to create a queue for your time class? Do you have anything yet?

NathanOliver 429 Veteran Poster Featured Poster

Makes sense. Thanks dani.

NathanOliver 429 Veteran Poster Featured Poster

Since the * is on its own line it makes it more difficult. You could have 2 LOAD.get(); calls after getline(LOAD, mov->yr); but you should comment why you are doing that.

while(!LOAD.eof())
{
	movie *mov = new movie;

	getline(LOAD, mov->title);
	getline(LOAD, mov->star);
	getline(LOAD, mov->yr);
		
	LOAD.get();  // this will get rid of the *
        LOAD.get();  // this gets rid of the newline

	movieList.push_back(*mov);
}
NathanOliver 429 Veteran Poster Featured Poster

You should avoid using .eof() as your while condition. I can't remember the post where they do a good job explaining it but you should be able to find it. for your while condition I would do

while (recordFile.read((char*) &temp[i], sizeof (participant)))
{
    //...
}

this will make sure your while loop will read everything in the file because as soon the read function fails it will end the loop.

NathanOliver 429 Veteran Poster Featured Poster

I still think something is off though. Today I saw a post with 3 pop bar and it had 1 reply and 81 views and the post right before it has 1 pop bar and it has 8 replies and 2116 views. the one with more replies and views is older so does that come into play? (replies + views) / time post has been around ?

NathanOliver 429 Veteran Poster Featured Poster

Well you don't need to have a garbage in your struct then. you can just create a temporary string in your function and keep putting the astrix in there.

//...
movieList.clear(); //emptying my stl list object.
string temp;
while(!LOAD.eof())
{
	movie *mov = new movie;

	getline(LOAD, mov->title);
	getline(LOAD, mov->star);
	getline(LOAD, mov->yr);
		
	getline(LOAD, temp); //collect my aterisks

	movieList.push_back(*mov);
}
NathanOliver 429 Veteran Poster Featured Poster

Well the reason I have the vector in the function parameters is that until I looked at your post more closely I wasn't sure if you could return a vector defined in a function. I try not to return something that was defined in a function out of habit for some reason. Can't remember anymore why that is though.

NathanOliver 429 Veteran Poster Featured Poster

How is the file formated? with getline you can set the delimiter a '*'.

NathanOliver 429 Veteran Poster Featured Poster

I also came up with a verson of this. Not quite as nice as firstPersons but it does the job

#include <iostream>
#include <string>
#include <vector>

void Split(std::string word, std::vector<std::string> & pieces, const char * splitChar)
{
    std::string::const_iterator it = word.begin(), end = word.end();
    std::string temp;
    unsigned int counter = 0;
    while (it != end)
    {
        if (*it != *splitChar)
            temp += *it;
        else
        {
            pieces.push_back(temp);
            temp = "";
        }
        it++;
    }
}

int main()
{
    std::string word = "This@is@a@string@to@split.";
    std::vector<std::string> pieces;
    Split(word, pieces, "@");
    for (size_t i = 0; i < pieces.size(); i++)
    {
        cout << pieces[i] << endl;
    }
    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

@ Zoon - The first example you posted with "MyFile*.mat.*" against "MyFileForComputers.mat.php" worked fine with the code I have. The second example you posted with "D?or*.material" against "Door424.material" did return false and it was a variable name error. On line 40 of my second code post it should be

if(parts[0].find_first_of("?",0) != std::string::npos)

Thanks for catching that.

@ nezachem - I understand it might look a little complex but it is pretty self explanatory. I went the STL route and that sometimes make it look a little more complicated. Also I wanted to try and solve this without using recursion.

I will work on adding support for having a ? be a ? as well. Not sure if I'll get to it today though. I'm attaching the updated code this time instead of posting it to save space.

NathanOliver 429 Veteran Poster Featured Poster

Ill look into it later today and see what's goimg on

NathanOliver 429 Veteran Poster Featured Poster

Yes I did mean to type ==. The brain is a little laggy today. Maybe I should run a de-frag ;)

NathanOliver 429 Veteran Poster Featured Poster

Does anyone know how popularity is computed? Is it forum dependent or is it weighted against all post in daniweb? I'm just curious because so far I cant see a pattern.

NathanOliver 429 Veteran Poster Featured Poster

well you can overload the operator= function for Point

bool operator=(const Point & rhs, const Point & lhs)
{
    return ((rhs.x == lhs.x) && (rhs.y == lhs.y) && (rhs.z == lhs.z));
}
NathanOliver 429 Veteran Poster Featured Poster

sorry did realize the array was global. I thought it was part of main.

NathanOliver 429 Veteran Poster Featured Poster

Okay well I believe I have it all sorted out. I added using a ? as a single letter wildcard and it appears to work just fine. I wound up having to write another function that compared 2 strings if one had a ? in it. I just went through the string that had the ?'s in it and where ever there was a ? i replaced it with the letter in the second string at that same spot. The main function has not changed from my first post so I will just post my new WildcardCompare.h. If anyone else finds something it doesn't work for or isn't right let me know so i can try and fix it. Thanks.
test cases

"*this*my*\\**da?.php"
against
"this is my *good day.php"
outcome
true
"???.txt"
against
"bad.txt"
outcome
true

"\\*.txt"
against
"8.txt"
outcome
true

and lastly
"*.php"
against
"MyScript.php"
outcome
true
#ifndef WILDCARDCOMPARE_H
#define WILDCARDCOMPARE_H

#include <string>
#include <vector>

bool SingleWildcardMatch(std::string, std::string);

bool WildcardCompare(std::string searchTerm, std::string checkAgaints)
{
    bool found = false;
    std::vector<std::string> parts;
    std::string temp;
    if (searchTerm == "*")
        return true;
    if (searchTerm.size() - 1 > checkAgaints.size())
        return false;
    std::string::const_iterator it = searchTerm.begin(), end = searchTerm.end();
    size_t counter = 0;
    while (it != end)
    {
        if (*it == '*')
        {
            parts.push_back(temp);
            temp = "";
            it++;
            continue;
        }
        if (*it == '\\' && *(++it) == '*')
        {
            temp += "*";
            it++;
            continue;
        }
        temp += *it;
        it++;
    }
    parts.push_back(temp);
    bool singleWildcardPresent = false;
    if(temp.find_first_of("?",0) != std::string::npos)
        singleWildcardPresent = true;
    std::vector<std::string>::const_iterator …
NathanOliver 429 Veteran Poster Featured Poster

Thank you AD for your reply. The single slash in my code was a typo. As for having a ? act as a any single letter I am implementing that right now and I should have it finished shortly. I'll post the updated code once its done.

@ Excizted I fixed what was causing the problem and when I post the updated code "*.php" for searchFor and "MyScript.php" for word will work.

NathanOliver 429 Veteran Poster Featured Poster

Line 46 says fills array with hex but you are not actually doing that. Could be your problem

NathanOliver 429 Veteran Poster Featured Poster

in your sort function you should be able to do

// ...
while (x < maxSub) 
{
    if (properties_copy[x].price > properties_copy[x + 1].price) 
    {
        temp = properties_copy[x];
        properties_copy[x] = properties_copy[x + 1];
        properties_copy[x + 1] = temp;
        //...
    }
//...
NathanOliver 429 Veteran Poster Featured Poster

Templates are diffidently the way to go then.

NathanOliver 429 Veteran Poster Featured Poster

I don't know why you have to call ignore after consecutive getline calls. Here is a little sample code I wrote and it works just fine.

#include <iostream>
#include <string>

using namespace std;

int main()
{
    string a,b,d;
    int c;
    cout << "enter a string: ";
    getline(cin, a);
    cout << "enter another string: ";
    getline(cin, b);
    cout << "enter an integer: ";
    cin >> c;
    cin.ignore(80, '\n');
    cout << "enter one last string: ";
    getline(cin, d);
    cout << endl << a << endl << b << endl << c << endl << d;
    cin.get();
    return 0;
}
NathanOliver 429 Veteran Poster Featured Poster

Well I had some free time today and this peaked my interest so I created a function that should do the trick. I made it a code snippet and this will take you there.

NathanOliver 429 Veteran Poster Featured Poster

Hey All

This code is for matching a string with a wildcard in it to another string. If you want to have a Astrix in the first string be counted as a character and not as a wildcard put a \ in front of it. I have tested it for quite a few different possibilities and it has worked for what I have tested it with. Include is a short main function demonstrating it working. Fell free to use it if you want but I CAN'T guarantee that it is bug free.

Nathan

Ancient Dragon commented: Good job :) +28
Zoon commented: Very useful :) +1
NathanOliver 429 Veteran Poster Featured Poster

tie works by making the output stream tied to a input stream flush its contents before input is allowed. I really cant give you an example though because that would be doing your homework for you.