daviddoria 334 Posting Virtuoso Featured Poster

Is this for a class assignment or you need it for work?

daviddoria 334 Posting Virtuoso Featured Poster

I don't think it makes sense to use << on an ifstream.

I think you should look into the getline() function. You shouldn't have to overload the >> operator to do this.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I think you'd have a lot better luck on the OpenCV forum.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

This might go better in the Game Development subforum:

http://www.daniweb.com/forums/forum71.html

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I didn't look at the code - but maybe you want to make an std::vector<Player> ?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I think this would go better in the Game Development subforum: http://www.daniweb.com/forums/forum71.html

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Since this is a non-native c++ thing, I would recommend using system() to call the appropriate system command to get the terminal size (I don't know what it is, but I'm sure one exists). Include in the command writing this result to a file. Then read the file in your c++ program.

In bash it is:

system("echo $COLUMNS $LINES > file.txt");

Hope this helps.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I would start by looking at the set of equations on wikipedia that you have every step for. This will let you know if/where you have gone wrong. Then once it works on the case that you have the solution for, you can run it on your actual class problem.

It will be tough to write this for general sets of equations, but I would imagine your instructor would be OK with you writing it for "nice" cases of sets of equations - that is, when you can do the whole thing and come out with integers in each step.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What is the problem? What is the current output? Are there any compiler errors?

daviddoria 334 Posting Virtuoso Featured Poster

1) please use code tags

2) is this for an assignment (i.e. are you wanting help writing the sort?)? If not, then look at the STL algorithm sorting functions:

http://www.cplusplus.com/reference/algorithm/
http://www.cplusplus.com/reference/algorithm/sort/

Dave

daviddoria 334 Posting Virtuoso Featured Poster

abdulsaboor30 - please use code tags and do not do peoples assignments for them!

daviddoria 334 Posting Virtuoso Featured Poster

1) Please make your titles informative - "Gaussian elimination" is much more informative than "Help. Gr11 array chap project"

2) This should get you started
http://en.wikipedia.org/wiki/Gaussian_elimination#Algorithm_overview

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please try to replicate the problem in as few lines as possible - I'm guessing you can start paring down the code and get it to < 20 lines to produce the same problem. This process will probably magically point out the problem! If it doesn't, then we'd be happy to help.

Dave

Fbody commented: That's for sure :) +1
daviddoria 334 Posting Virtuoso Featured Poster

This may be partially my fault - I told him to start this thread because the discussion in a previous thread now had nothing to do with the title.

daviddoria 334 Posting Virtuoso Featured Poster

May I suggest a new thread titled "How do you catch F5 key?"

daviddoria 334 Posting Virtuoso Featured Poster

Look into fstream/ofstream

Dave

daviddoria 334 Posting Virtuoso Featured Poster

No one is going to help you unless you have tried it yourself first!

daviddoria 334 Posting Virtuoso Featured Poster

Please be much more specific. You want to color words in a terminal? Or are you using a GUI?

daviddoria 334 Posting Virtuoso Featured Poster

'outfile' doesn't seem to be defined.

This code works fine for me:

#include <iostream>

using namespace std;

int main()
{
    string text;
    int nl = 0;

    cout<<"Press enter twice in a row to quit: ";

    while (nl < 2 && getline(cin, text))
    {
        if (text.empty())
        {
            ++nl;
        }
        cout << text << endl;
    }
       
    return 0;
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

It looks like a good way is to direct the results of the command to a file and then read the file in c++:

http://www.cplusplus.com/forum/general/1253/

daviddoria 334 Posting Virtuoso Featured Poster

So you want me.txt to open in notepad and you.exe to execute?

daviddoria 334 Posting Virtuoso Featured Poster

When I click the "Unanswered" tab to see all of the posts that have 0 replies, I get a page of threads that indeed have 0 replies. When I click on the "2" (for page 2) or the "next" button at the bottom to go to the next page of unanswered threads, the page that is displayed is threads that DO already have responses.

Can anyone verify this?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Try to cut out code until it is short enough to post here using code tags (< 30 lines). That will help you find the problem, as well as help us fix it if you can't.

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

I use Qt's QFileDialog.

daviddoria 334 Posting Virtuoso Featured Poster

replace x>sizl with x<sizl

daviddoria 334 Posting Virtuoso Featured Poster

Some of you may have noticed that I am always harping about "abstracting the problem" and "posting the smallest compilable piece of code that demonstrates a problem."

I rambled a bit about why this is important if anyone cares to read:
http://daviddoria.blogspot.com/2010/05/problem-abstraction-helping-others-help.html

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What language is this? Please try to abstract your problem - if you need help with a loop, then write a simple loop and show us where the problem is. "How do I give a player weapons?" is not a c++ question. "How do I loop over an array?" is much better :)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Some other good keywords are "parsing" and "delimiter".

daviddoria 334 Posting Virtuoso Featured Poster

I always recommend trying to abstract the problem. Here, your problem has nothing to do with translation. You simply want to know "How do I display a string in a text box?", right?

Unfortunately I don't do any windows gui programming, but surely someone can help if you post a tiny (< 20 line) example of a program that is supposed to put text in the text box but fails.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Why do you need global variables to do this?

daviddoria 334 Posting Virtuoso Featured Poster

This compiles and runs fine for me:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

class Hardware
{
  int a;
};

int main()
{

	Hardware tool1;
	ofstream st("Hardware.dat", ios::out | ios::binary);
	if(!st)
	{
		cout << "File not found.";
		exit(-1);
	}
	for(int i=0; i<100; i++){
		st.write(reinterpret_cast<const char*>(&tool1),sizeof(Hardware));
		}
	cout << "\nCreated 100 blank tools.";
    
    return 0;
}

If you can make something approximately this length that produces the out of range error that would be very helpful.

daviddoria 334 Posting Virtuoso Featured Poster

That would just write the same tool 100 times, right?

Please clearly define what is going on - what is your expected output? What is the current output? Are there compiler errors?

daviddoria 334 Posting Virtuoso Featured Poster

You're right, of course how you're exiting doesn't matter to your real problem. I was just pointing it out in parallel.

Another thing - I would highly recommend explicitly using the "this" pointer to indicate when you are addressing member variables:

void Hardware::setToolName(string tn)
{
	for(int i=0; i < 15; i++)
		this->toolName[i]=tn[i];
}

It will really improve code readability.

This is the demo I have for writing a binary file:

float fnum[4] = {11.22, -33.44, 55.66, 77.88};
	int i;

	ofstream out(Filename.c_str(), ios::out | ios::binary);
	if(!out)
	{
		cout << "Cannot open file.";
		exit (-1);
	}
	
	out.write((char *) &fnum, sizeof(fnum));
	out.close();

Maybe this will help you get a bit further?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't know if everyone here agrees, but I am much more inclined to help when the code is immediately compilable:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

class Hardware
{
  int a;
};

int main()
{
    Hardware tool1;
	ofstream st("Hardware.dat", ios::in | ios::out | ios::binary );

	if(!st)
	{
		cout << "File not found.";
		exit(0);
	}

	int myRecordNumber;
	char tname[15];
	int myQuantity;
	double myCost;

	cout << "Enter tool number: " << endl;
	cin >> myRecordNumber;

	cout << "Enter tool name: " << endl;
	cin >> tname;

	cout << "Enter the quantity: " << endl;
	cin >> myQuantity;

	cout << "Enter the cost: " << endl;
	cin >> myCost;

	st.seekp((myRecordNumber)*sizeof(Hardware));

    st.write(reinterpret_cast<const char*>(&tool1),sizeof(Hardware));
    
    return 0;
}

First - I think you should typical exit(-1) to indicate an error, right? I think exit(0) ( like return 0) means "everything went ok" (but maybe I'm wrong about this?)

When I run this code, I get "File not found". Since you are using ofstream, this should be trying to write (create) the file, right? So it shouldn't matter if the file is already created?

daviddoria 334 Posting Virtuoso Featured Poster

Yes yes, too long! haha - Try to abstract the problem to < 20 lines that we can look at.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags to post the smallest compilable example of the problem. Subscript out of range means you are doing something like myArray[5] when the array only has 3 elements, or something like that.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is this a c++ question?

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags to post the relevant parts of the code - no one wants to look through 10 files!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd suggest using a library that can deal with images. For example, VIL (part of VXL) or VTK (vtk.org).

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Sounds like you need to make a "Fraction" class and then make an array (I'd recommend a std::vector) of Fraction objects.

std::vector<Fraction> fractions;

I hope this gets you started - once you get some code written post it here and I'm sure someone can help you with any difficulties.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You're going to have to show some effort before anyone is going to help you with your project. Have you written any code so far? I'm not sure how they're expecting you to know the form/shape of the letters - do you have any additional input files? (b/w images of letters, etc)?

Dave

Laurentius Dion commented: not bad +0
daviddoria 334 Posting Virtuoso Featured Poster

You should look for the opencv forum (maybe it is a google group, I forget exactly). This is not a c++ question so you probably won't find much help here :(

daviddoria 334 Posting Virtuoso Featured Poster

I would use VTK - it is basically a wrapper around openGL that allows you to do things much more easily. For either OpenGL or VTK, there is a pretty extreme learning curve - shouldn't you be learning something like this in your class???

daviddoria 334 Posting Virtuoso Featured Poster

Ah, didn't see that app|ios::binary.

daviddoria 334 Posting Virtuoso Featured Poster

This does not look like standard/modern c++. You should #include <iostream> instead of #include<iostream.h> Then you should do the reading with the >> ifstream operator instead of .read and the << ofstream operator instead of .write.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Is this for a course or for real use? If you intend to actually use the code - I would highly recommend going with an already developed mathematical toolkit for c++, such as VNL (part of VXL). It will most definitely be very optimized an provide all of the functionalities you are looking for.

daviddoria 334 Posting Virtuoso Featured Poster

1) Please use code tags
2) Please use a reasonable indention scheme for your braces (maybe not using code tags affected this?)
3) Try to narrow down your question to the smallest piece of code possible. Maybe make a 10 line example that fills a vector and then ask "how do I output all the values in the vector?" or something like that. Abstracting the problem really helps people help you, because many people won't want to read about all these classes (student, course, etc), but they may take 2 seconds to read that you want to output items in a vector. See what I mean?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

First, please use code tags.

Instead of writing a "header", I think you mean you need to write the "class" called extRoman. at the very least you have a bunch of operator overloading to do (--, ++, +, <<, *). Sounds like you'll also need some functions for averages etc.

Give it a shot and maybe someone will help you, but just posting your assignment isn't going to get you anywhere.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You should post the reply here - so if someone has a similar question they can also find the answer :)