daviddoria 334 Posting Virtuoso Featured Poster

You should definitely separate the user input from the computations. An added benefit of doing this is that you can hard code some values for testing purposes. Also, your function should return something and then you should output the answer from main.

daviddoria 334 Posting Virtuoso Featured Poster

Thanks, that is a very important step, so others can see the solution as well.

There should be a section at the bottom of the thread that says "Has this thread been answered?" with a link that says "Mark this Thread as Solved". The idea is that people won't waste time reading your question and trying to answer it because then they can see that it has already been taken care of.

daviddoria 334 Posting Virtuoso Featured Poster

Great! Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

This is quite a complicated function. It is almost impossible to follow - you have multiple nested loops, one letter variable names, and NO comments!! Just because it is called "code" doesn't mean it has to look like an encrypted document! Every one of those nested loops could probably be broken out into function. I bet you that code contains something like a SumRow(int) function and SumDiagonal(), etc. If you write it modularly like this, then you can test each function individually and see exactly which piece is going wrong.

daviddoria 334 Posting Virtuoso Featured Poster

You can always do a system() call to make c++ do it the way you would do it from the command line. In linux, I would use wget:

system("wget yourURL");

I'm not sure what you would use in Windows.

David

daviddoria 334 Posting Virtuoso Featured Poster

There is no difference between "the compiled code" and "the executables created". The code compiles INTO the executables! Can you explain how you are running these "different versions"?

daviddoria 334 Posting Virtuoso Featured Poster

You call this:

string = zipCode;

before you have defined zipcode. Did you mean to say

string zipCode;

?

Also, you can access individual characters in a string with the [] operator. That is, you can check if the first digit is a '6' by doing:

if(yourString[0] == '6')

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

Sure thing - glad it's working. Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

Well closer to what you had before would be a pointer gc object:

int* a = new int;
  GarbagePointer<int>* myGC = new GarbagePointer<int>(a);

but the syntax you had originally posted doesn't make sense - you can't instantiate a class of one type with an object of a different type!

daviddoria 334 Posting Virtuoso Featured Poster

This compiles for me:

int* a = new int;
  GarbagePointer<int> myGC(a);

And it makes sense given this constructor:

explicit GarbagePointer(T* p = NULL) : value(p) { next=this;prev=this;
    };
daviddoria 334 Posting Virtuoso Featured Poster

Shouldn't this

GarbagePointer<int> myGC=new int;

be more like

GarbagePointer<int> myGC=new GarbagePointer<int>;
daviddoria 334 Posting Virtuoso Featured Poster

You need to abstract the problem wayyy past "Monsters Inc". You should ask the question generally so it helps the most people. Here are some details and specifics:

http://daviddoria.blogspot.com/2010/05/problem-abstraction-helping-others-help.html

Maybe something more like "I have two objects and I want to transform them together" or something like that. You should also post the code that you have tried that did not work and explain what is going wrong.

David

daviddoria 334 Posting Virtuoso Featured Poster

I don't think the conditional on HYS_GLOBAL_VARIABLES is necessary because it is true in exactly the same case that the outer HYS_MAIN_HEADER_H is true. Also, why are you including those windows.h files?

daviddoria 334 Posting Virtuoso Featured Poster

Are you sure its supposed to be capitalized? The name of the header is 'mysql', so I would try mysql *conn;

daviddoria 334 Posting Virtuoso Featured Poster

No problem, glad it's working. I hope you see the process a little bit though - break up the problem into the absolute smallest pieces you can. Often that will lead exactly to the solution.

Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

Is this a "visual studio" list box? (I'm not even sure of the terminology). Can you send a link to the documentation page of the list box? Surely there is a function to do this.

daviddoria 334 Posting Virtuoso Featured Poster

Well there is your problem. What is it returning? It is probably some actual object which contains the items. Is there a GetNumberOfItems() or similar function you should be using instead?

daviddoria 334 Posting Virtuoso Featured Poster

Yes, I understand what you are trying to do - did you break it up into two parts like I suggested? Which part didn't work as you would expect?

daviddoria 334 Posting Virtuoso Featured Poster

Please keep the discussion on the forum so everyone can help and benefit.

I suggest you make a compilable program no longer than 25 lines that demonstrates the issue. You should also put output statements at every place possible inside 'inttohex' so you can see exactly where it is going wrong. You should also do the calculation by hand so you can check the values along the way.

daviddoria 334 Posting Virtuoso Featured Poster

My point was we can't help you get what you want if you don't tell us what that is! Are there compiler errors? Does the message box not show what you want it to?

Try this:

int a = 5;
MessageBox::Show(string(a)); // or however you were converting your number to a string

and this :

std::cout << "number of list box items: " << listBox1->Items << std::endl;

Once you get those working properly, you can try to combine them.

daviddoria 334 Posting Virtuoso Featured Poster

I'm confused. Your title says "string to int to string", so I was looking for StringToInt() and IntToString() functions, but instead found hex and dec and those things. Can you remove all of the unnecessary code and hardcode the input so we can take look at only relevant material?

daviddoria 334 Posting Virtuoso Featured Poster

What do you mean by "no luck"? Can you show us the error message?

My first guess is that I would image Show() takes a string, not a numeric value.

daviddoria 334 Posting Virtuoso Featured Poster

As Agni said, you need to be using cout if you want to see something on the screen. Also, you seem to be reading in the line as an int which doesn't make sense. You should read it as a std::string.

Also, you should not expect people to run your code. If they do, that is a great bonus, but you should try to explain your problem clearly enough that they do not have to run it to see what you are talking about.

daviddoria 334 Posting Virtuoso Featured Poster

As Agni said, you need to be using cout if you want to see something on the screen. Also, you seem to be reading in the line as an int which doesn't make sense. You should read it as a std::string.

Also, you should not expect people to run your code. If they do, that is a great bonus, but you should try to explain your problem clearly enough that they do not have to run it to see what you are talking about.

daviddoria 334 Posting Virtuoso Featured Poster

You mean there is nothing in the output file? It is not supposed to show anything on the screen...

daviddoria 334 Posting Virtuoso Featured Poster

Can you use the getline function insetad?

string filename;
    getline(cin, filename);

David

daviddoria 334 Posting Virtuoso Featured Poster

Great. Please mark the thread as solved.

daviddoria 334 Posting Virtuoso Featured Poster

What kind of problems? Hardcode some input, show us the current output, and tell us the expected output.

daviddoria 334 Posting Virtuoso Featured Poster

You're on the right track. In the snippet below, the stringstream acts just like your file stream.

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

int main(int, char *[])
{
  std::string line = "11/29/2010 S 2907 1";

  int myInt;
  char myChar;
  std::string myString;
  
  std::stringstream ss;
  ss << line;
  ss >> myInt >> myChar >> myInt >> myChar >> myInt >> myString >> myInt;

  std::cout << myInt << std::endl;
  return 0;
}

Please try to simplify your problem down to something as close to this length as possible. It makes it easier for you to figure out what is going on and easier for us to help you :)

David

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when posting code.

Also, please try to simplify your code before showing us. Surely it doesn't take 125 lines to demonstrate this error. I bet you can get it down to 20 :)

daviddoria 334 Posting Virtuoso Featured Poster

Is the problem with reading them from the file? Or displaying them to the screen? I would separate this problem.

1st program) read the file and inspect its contents in memory

2nd program) hard code values and output them to the screen

By doing this you will isolate the problem and allow us to help you more easily.

David

daviddoria 334 Posting Virtuoso Featured Poster

The first thing you posted there doesn't do anything better than what you were doing before. The second version is good, but you must dereference the 'this' pointer:

for (int c = 0; c <= 2; c++)
{
*(this)[r][c] = temp[c][r];
}
daviddoria 334 Posting Virtuoso Featured Poster

The first thing you posted there doesn't do anything better than what you were doing before. The second version is good, but you must dereference the 'this' pointer:

for (int c = 0; c <= 2; c++)
{
*(this)[r][c] = temp[c][r];
}
daviddoria 334 Posting Virtuoso Featured Poster

Say you have the matrix:

1 2 3
4 5 6
7 8 9

When you do this:

_Mx[0][1] = _Mx[1][0];

you now have

1 4 3
4 5 6
7 8 9

You have lost the 2 forever!

I'm suggesting that the first thing you do is

matrix::transpose()
{
 matrix temp = *this;
 for (your loop...)
 {
   this[i][j] = temp[j][i];
 }
}

This way you won't lose any numbers :) This has nothing to do with why you aren't outputting more than 1 row, but it must be fixed as well.

David

daviddoria 334 Posting Virtuoso Featured Poster

You need to make a temporary matrix. When you do this:

_Mx[0][1] = _Mx[1][0];

then later this:

_Mx[1][0] = _Mx[0][1];

you won't have changed anything.

daviddoria 334 Posting Virtuoso Featured Poster

You should look into using a revision control system (svn, or the latest and greatest, git). There is certainly a lot of work at the beginning figuring out how to use it, but once you get used to it it will allow you to "undo" any of your changes. E.g. in this case you could revert back to a working version :)

daviddoria 334 Posting Virtuoso Featured Poster

Can you post the latest code?

daviddoria 334 Posting Virtuoso Featured Poster

This syntax seems awkward:

m2.trans(m2);

If you call the function trans() on an object, it shouldn't take any parameters and it should return void:

m2.trans();

Only if you called the function as a static function would take seem right:

m2 = trans(m1);

Also, if the goal of your project is not to write a matrix class, I strongly suggest you do not do so, but rather use an existing library. I use VNL (part of the VXL package), but there are many others (Eigen, etc).

David

daviddoria 334 Posting Virtuoso Featured Poster

ImageMagick has a c++ API: http://www.imagemagick.org/script/index.php that could certainly do this.

Otherwise, libjpeg sounds like a reasonable choice: http://www.ijg.org/ though I've never used it.

David

daviddoria 334 Posting Virtuoso Featured Poster

When in doubt, you should always remove the user input stuff. There is nothing wrong with your use of the Movie vector (except the name - you should call the vector Movies and the individual movie Movie, not M1 and M2):

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

using namespace std;

class Movie
{
    private:
         string movieTitle, studioName;
         string Actors[2];
         int yearMade, numOfActors;
         double grossIncome;

    public:

    void SetDemoProperties()
    {
      movieTitle = "TestTitle";
      studioName = "TestStudio";
      Actors[0] = "David";
      Actors[1] = "Joe";
      yearMade = 2000;
      numOfActors = 5;
      grossIncome = 1000;
    }

};

int main()
{

  vector<Movie> M1;
  Movie M2;

  
  M2.SetDemoProperties();
  M1.push_back(M2);
  return 0;
}

You must be doing something wrong in the Read function.

David

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

I think this question is better posed here: http://www.opengl.org/discussion_boards/

daviddoria 334 Posting Virtuoso Featured Poster

Look at #2 in my last post. You did not change this.

parth27987 commented: Helped a lot! Soleved the problem. +1
daviddoria 334 Posting Virtuoso Featured Poster

1) Line 56:

return (symbol);

you can't return something in a void function.

2) Your ambiguous function is because you declare it like:

void func1(int rows,int column,int blocks,char symbol);

and define it like

void func1(int &rows,int &column,int &blocks,char &symbol)

(Note that one has &'s and the other doesn't). These must match exactly.

3) You should always use more descriptive function names. Func1 and func2 doesn't really help anyone know what is going on :)

David

daviddoria 334 Posting Virtuoso Featured Poster

What is the error? What is the expected output? What is the current output?

daviddoria 334 Posting Virtuoso Featured Poster

I have no idea what is going on there, but if it is in an infinite loop then flag is never getting set to 1.

I STRONGLY suggest breaking a lot of this code out into functions. I.e.

void GenerateRandomNumbers(int rands[][])
{
	    rands[i][0] = 600.0 * rand()/RAND_MAX;    // for the room number.
	    rands[i][1] = 100.0 * rand()/RAND_MAX;    // for the wumpus.
	    rands[i][2] = 100.0 * rand()/RAND_MAX;    // for the pit.
	    rands[i][3] = 100.0 * rand()/RAND_MAX;    // for the bat.
}

It looks like you have have at least 5 or 10 of this size functions. Then your main function should be easy for us (and you, more importantly) to follow:

main()
{
  getInput();
  while(some condition)
    {
    doSomething();
    doSomethingElse();
    if(a condition)
      {
      doAnotherThing();
      }
    }
}

David

daviddoria 334 Posting Virtuoso Featured Poster

Your + operator should return the same type as the inputs:

Homework Homework::operator+ (const Homework rhs) const {
   
    Homework result;
    int a = this->time;
    int b = rhs.time;
    result.SetTime(a+b);
    return result;
}
brandonrunyon commented: Thanks for your assistance, good clearity, sorry to make you repeat yourself :-\ +4
daviddoria 334 Posting Virtuoso Featured Poster

The problem is that your + function returns an int. Your templated function was trying to return the same type as your inputs. So when you add a Homework to a Homework, it was trying to return a Homework, but your + function was returning an int, so it didn't make sense. Check out the working version below.

#include <iostream>
 
 class Homework
 {
   int time;
   
   public:
     void SetTime(int t){time = t;}
     int operator+ (const Homework rhs) const;
 };
 
template <class T>
int sum (T a, T b) {
  int result = a+b;
  return result;
}

//lhs.time + rhs.time = int result

int Homework::operator+ (const Homework rhs) const {
   
    int result;
    int a = this->time;
    int b = rhs.time;
    result  = (a+b);
    return result;
}

int main(int argc, char *argv[])
{
  Homework hw1;
  hw1.SetTime(1);
  
  Homework hw2;
  hw2.SetTime(2);
  
  {
  int total = hw1 + hw2; 
  std::cout << total << std::endl; 
  }
  
  int total = sum<Homework> (hw1, hw2);
  std::cout << total << std::endl; 

  return 0;
}

See what I mean?

David

daviddoria 334 Posting Virtuoso Featured Poster

The templated sum() function tries to add a to b. Your + overload adds a.time to b.time. It should work if you call:

int total = sum<int> (hw.time, hw2.time);

David

daviddoria 334 Posting Virtuoso Featured Poster

It seems like you are explaining two things. The first is that the program opens, reads a file, updates the file, then closes. The second is that you are doing this read/write in a while loop?

fstream is definitely the way to go for the file IO. Then you should use a stringstream to convert the string you read to the type (int) you want.

These may help you with some syntax:
http://programmingexamples.net/index.php?title=CPP/IO/ReadingLines
http://programmingexamples.net/index.php?title=CPP/IO/FileOutput
http://programmingexamples.net/index.php?title=CPP/IO/FileInput

David