mrnutty 761 Senior Poster

This shouldn't be this hard.

You want to read from a text file of the format :

Firstname;Lastname;178

where the ';' means the word has ended. And you know you will
always read firstname, then lastname, then the value. Now first
you need to open a file. Of course you know how to do that :

ifstream getFromFile("text.txt");

That opens a file to read. Now you have to read.

First lets say this is the file :

Firstname;Lastname;000
Tony;Montana;100;
Best;Forever;99;
Richard;Jones;98;
World;Hello;97;

You now need to read the file. What you can do is read 1 line into a string. Then have a function find all occurrence of ';' and replace it with a space.

Here is a complete example :

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


using namespace std;

//find wherever ';' is and replace it with ' '
void wordReplace(string& source,char find = ';', char replaceWith = ' ')
{
	size_t pos = 0;

	while(true)
	{		
		pos =  source.find_first_of(find,pos);	 //find the position of ';'
		if(pos == string::npos)
			break;
		source[pos] = replaceWith; //replace ';' with a space
	}

}
int main() 
{	
	ifstream iFile("test.txt"); //open file to read
	
	if(!iFile) return -1; //check if file is opened

	string word = ""; 
	
	vector<string> fullNameWithValue;
	
	while( getline(iFile,word)) {		 //get a line into a string
		wordReplace(word); //replace ';' with ' '
		fullNameWithValue.push_back(word); //add word to out list
	}

	for(size_t i = 0; i < fullNameWithValue.size(); i++) //print out word
		cout<<fullNameWithValue[i]<<endl;

	 	
	return 0; …
mrnutty 761 Senior Poster

"Shake sphere game us to be or not to be ", computer gave us 0xFF"


--------------------
2B|~2B = 0xFF
--------------------

mrnutty 761 Senior Poster

Then whats the problem ? Why can't he just use that?

mrnutty 761 Senior Poster

since you are using vectors, and the vectors already contains data, then
all you have to do is jumble up the data into different place. Therefore
there is a function called std::random_shuffle that does just that.

Here is the link. Unsurprisingly, they use vectors as an
example.

mrnutty 761 Senior Poster

Do you know how to declare a template function?

mrnutty 761 Senior Poster

[edit]I don't see any reason at all for reading the file one character at a time. Too much work just to extract individual words.

Yea I know. Just throwing the possibility out there. Reading
character by character might be helpful in some cases though, like
frequency counter, or whatever.

mrnutty 761 Senior Poster

Don't forget, that there are also other methods. For example, you can
extract character by character.

Here is an example of that :

#include<iostream>
#include<string>
#include<fstream>

using namespace std;


int main()
{
	ifstream iFile("test.txt");
	if(!iFile) return -1;

	char ch = 0;

	string content = "";

	while(iFile.get(ch) ){
		content += ch;		
	}

	cout << content << endl;

	return 0;
}

And if you want only the words in the file, then a simple if statement
to check if the char is a space and also using vectors of string will do.

mrnutty 761 Senior Poster

Can you use strings? Since you can access the string as an array with
the indexing operator, [] .

mrnutty 761 Senior Poster

Normally, the delete function should look like this :

void deleteList(Node * headNode)
{
    Node * temp = headNode;

   while(temp != null){
         temp = head->next;
         delete head;
         head = temp;
    }
}

I think that should be correct.

mrnutty 761 Senior Poster

You can use the string's find method.

mrnutty 761 Senior Poster

>>This leaves my wondering if it would be possible to use -= to decrease after each loop in any way ?

Try it. Put Fr->callEvent -= Fr->callEvent after the call to Dt->eventHandler.

mrnutty 761 Senior Poster
#include<iostream>
using std::cout;

struct Test
{
	int i;
	Test(int j) { i = j; }
	void show() { cout << i << "\n"; }
};
int main() 
{
	Test test[3] = { Test(1), Test(2), Test(3) };
	test[0].show();
	test[1].show();
	test[2].show();
  return 0;
}

//prints 1 2 3

Of course you know that struct and classes are almost similar except
for their default behavior, so you can do this with classes as well.

mrnutty 761 Senior Poster

I will write the program out, but it really is not that hard. This is the source code:

#include <stdio.h>
int main() {
char letters[26] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

for (int i=0; i<26; i++) {
char n = rand(letters[i]);
sprintf(letters[n], "%s");
}

I am rusty with C so if anyone wants to look over the code and check that it is right, appreciate it.

Did you try that out ? I see problems with that.

mrnutty 761 Senior Poster

how i can use the library sort method

First by Googling it!

mrnutty 761 Senior Poster

>>Is there a way to delete the content on the left side of += after each loop ?

Can't know for sure without knowing Fr->callEvent type, but
Assumming callEvent is a string ? You can just reset it

for (int i = 0; i < 3; i++)
{
      Fr->callEvent = "";
      Fr->callEvent += gcnew Dt->callingEventHandler(this->callEvent );
}
mrnutty 761 Senior Poster

In my free time I kick puppies and shoot kids with a paintball gun.

Sounds like a good hobby? Is there a team to join for this sort of
stuff.

mrnutty 761 Senior Poster

>>Problem with output went away, but is there any way to change the output from dos to inside a console or something?

Not sure google it.

>>edit: and is there anyway to get rid of the error where it says "iostream cannot be found", but it still compiles fine?

Right now, are you using netbeans for java or c++ or both or others ?

mrnutty 761 Senior Poster

Before I answer, can you show how you tried to do this, so I can get
a better feel of what you are trying to achieve.

mrnutty 761 Senior Poster

Just wondering what other programmer do in their free time.

This is basically what I do in my free time :

1) Procrastinate ( of course )
2) Try to learn more things about programming
3) Practice programing
4) Play NBA2k9 and/or Call of Duty : modern warfare 2 (awesome games)
5) Chill with friends and laugh at stupid things
6) Maybe do some school work.

mrnutty 761 Senior Poster

You can use the .exe file in your project directory.

Intrade commented: I don't know why but this remark to the OP is oh-so-funny XD +0
mrnutty 761 Senior Poster

look at the bottom of the page :
"JDK 6 or JDK 5 is required for installing and running the Java SE, JavaFX, Java and All NetBeans Bundles. You can download standalone JDK or download the latest JDK with NetBeans IDE Java SE bundle.
"

do you have this?

mrnutty 761 Senior Poster

when you download netbeans make sure you download the JVM as well.

Are you creating the project correctly?

mrnutty 761 Senior Poster

Change this :

if (num > largest)
    largest = num; 
    count++;

to this :

if (num >= largest) {
    largest = num; 
    count++;
}

And I think it should work.

mrnutty 761 Senior Poster

For that you need to read multiple books, and even then you won't know
everything. But to start out, C++ primer plus is a good book. It goes in
details of C++.

jonsca commented: That is a good book, one of the most underrated on the market I think. +1
kvprajapati commented: Good advice. +6
mrnutty 761 Senior Poster

Don't worry about that. Just do it with if statements.

For example to sort 2 variable you can do this :

int n = 0;
int m = 0;
cin >> n >> m;

if(n < m )
   cout << n << " " << m;
else
cout<< m << " " << n;

For 3 variables, the concept is similar.

if( num1 < num2 )
	{
		if(num2 < num3 ){
			cout << num1 << num2 << num3 << endl;
		}
		else if(num1 < num3){
			cout << num1 << num3 << num2 << endl;
		}
		else cout << num3 << num1 << num2 << endl;
	}
	else if( num2 < num3 )
	{
		if(num3 < num1){
			cout<< num2 << num3 << num1 << endl;
		}
		else if(num2 < num1 ){
			cout << num2  << num1 << num3 << endl;
		}
		else cout << num1 << num2 << num3 << endl;
	}
	else if( num3 < num1 )
	{
		if(num1 < num2){
			cout<< num3 << num1 << num2 << endl;
		}
		else if(num3 < num2 ){
			cout << num3  << num2 << num1 << endl;
		}
		else cout << num2 << num3 << num1 << endl;

	}
	else
	{
		cout<<"default\n" << num1 << num2 << num3;
		
	}

But there is an easier way . Check the input when you get the data.

int num1(0);
	int num2(0);
	int num3(0);

	int min(0);
	int mid(0);
	int max(0);

	cout << "Enter 3 numbers : ";
	cin >> num1;
	min = max …
FraidaL commented: how would I modify this if I had a 4th variable? +0
mrnutty 761 Senior Poster

Its not. If you wan't to get the users input then get it first, and then
call the createNewObject with the input passed.

mrnutty 761 Senior Poster

Great, thanks, I'll try that :)
Does string define what the lines in the textfile are?

What do you mean?

mrnutty 761 Senior Poster

I'm not quite sure what lexicographically means even after Googling it so please forgive my understanding!

I basically want to add up all the digits and assign it to it's relative word. Sounds simpler than it is because I'm still stuck :-(

you have :

"Pen 1.98"
"Paper 3.00"
"Pad 1.99"

Do you wan't it to sort by the value it has, ex Pen has a value
of 1.98 and is the lowest so its the minimum?

mrnutty 761 Senior Poster

Its not hard.

#include<fstream>
using namespace std;

int main()
{
   ifstream readFromFile("test.txt");
   string var1, var2;
   readFromFile >> var1 >> var2 ;
  return 0;
}
mrnutty 761 Senior Poster

Forgive me if im wrong but wouldn't this be a hell of a lot easier in an array?

string itemsArray[x][y]

itemsArray["pen"][1.99]

or something to this effect?
without writing some code to parse your alphanumeric string you're going to struggle how your doing it right now i think (imo)

Wrong. You can't have string and a float, in a regular array.

@OP, how do you wan't it to be sorted, aside from deleting
the duplicates, lexicographically?

mrnutty 761 Senior Poster

read this

mrnutty 761 Senior Poster

Eminem. The best rapper alive.

mrnutty 761 Senior Poster

Use the ? : operator.

mrnutty 761 Senior Poster

Ok, I got my terminology mixed up. Was thinking insertion but wrote selection.

mrnutty 761 Senior Poster

>>Does that initialize all of the elements to zero?

I guess so. I haven't seen that before either.

mrnutty 761 Senior Poster

replace the && with the ||. You wan't the loop to run if either currentX OR currentY is not equal to toX or toY, respectively.

Also take out the

else { currentX-- } and else{ currentY-- }

there is not point since say currentX will not increment if its 100.

mrPaul commented: very good advise +0
mrnutty 761 Senior Poster

what's the external library? (if you don't mind)

mrnutty 761 Senior Poster

Can you just clear the screen after the call?

mrnutty 761 Senior Poster

Make use of function.

1) Create a function that does this f(34)=17 , for a given value.

Make sure it works.

For use a for loop with from start to finish and just call that function.

It will be more readable, better code/practice and you will
get a better grade.

mrnutty 761 Senior Poster

The simplest sort, although inefficient. Below is a demonstration of
bubble sort and insertion sort.

The bubble sort just consists of 2 for loops and std::swap.

The insertion sort uses 2 loops as well but not as much swap
as bubble sort.

Any questions ?

Ancient Dragon commented: Great job :) +25
mrnutty 761 Senior Poster

Minor fix :

#include<iostream>

int* get_address(int&);

int main()
{
int number = 0;

std::cout << "Enter a number: ";
std::cin >> number;

std::cout << "The memory address for the number is: " << get_address(number);

return 0;
}

int *get_address(int& num_addr)
{
return &num_addr;
}

mrnutty 761 Senior Poster

I feel nice today so I will help you :

Define a Double Linked Lists EmpRank where the data should be of type integer.

#include<iostream >
using namespace std;
int main(){
  cout<<"Here is a double linked list called EmpRank";
  cout<<" that I got from daniweb forumn, Please give me an ++A";
}

Now thats what I call a double liked list!

mrnutty 761 Senior Poster

This is what I mean :

struct Item {
   string Id;
   string Name;
   string barCode;
  //more stuff
};

class Product
{
   Item productInformation;
 //stuff
};

or you can make the Item struct a public inner class.

From there you can have this method in your product class :

bool createNewObject( Item item, string fileName)
{
    std::ostream insertToFile( fileName.c_str() );
   if( ! insertToFile ) return false;
    insertToFile << "Id : " << item.id  << endl;
    insertToFile << "Name : " << item.name << endl;
    insertToFile << "Barcode: " << item.barCode << endl;
 
   return true;
}

Is this what you were going for?

mrnutty 761 Senior Poster

What you should have is make the Product class composed of an another
class. The another class should hold all the data thats needed, like
name or barcode.

Then you can use that as a parameter to in createNewProduct.

Is your createNewProduct creating a temporary(initialized to the
parameters passed) variable an inserting it into a .txt file?

mrnutty 761 Senior Poster

You need to fix your grammar as pointed out earlier.

mrnutty 761 Senior Poster

Most likely its raw definition will be something like this :

void swap(char& a, char& b)
{
   char temp = a;
    a = b;
    b = temp;
}

Think of whats happening.

mrnutty 761 Senior Poster

In bubble sort when every you swap print out the array.

In selection sort, whenever you swap print out the array.

Also your functions : showArray1 and showArray2 is repetitive to each
other. You only need one of them, and pass array1 or array2 whenever
you wan't to print them to one of the function. So keep showArray1 or
showArray2 and discard the other.

mrnutty 761 Senior Poster

Yep If I am reading correctly, then you need to check the collision between
objects in your room, so they "interact" with each other.

mrnutty 761 Senior Poster

If this is what you are looking for :

enter a word :   hello
hello backwords is :  olleh

then all you have to do is use a for loop, start from strlen(str)-1 , to >= 0 and print out at index i.

mrnutty 761 Senior Poster

when you program a game of programming a game in your dream.