daviddoria 334 Posting Virtuoso Featured Poster

Can you explain what you are trying to do a bit more. I ran the program and didn't understand what I was trying to do. Looking at the code, you read 4 colors from the command line, then you try to compare the input colors to the ordered list of colors you hard coded? I don't get the point?

Also, you should use compare() to compare strings:
http://programmingexamples.net/index.php?title=CPP/Strings/Compare

David

daviddoria 334 Posting Virtuoso Featured Poster

A priority queue acts just like a queue but rather than maintain the order that the items were added to the queue, the priority queue sorts the items as they are added. Here is an example:
http://programmingexamples.net/index.php?title=CPP/STL/PriorityQueue

As I understand, a heap is the same as a priority queue.

Good luck,

David

daviddoria 334 Posting Virtuoso Featured Poster

I encourage you (or someone else) to put a simple TCPSocket example here:

http://programmingexamples.net/index.php?title=CPP/TCPSocket

then we can address your specific problem. You say "every thread to do something else". Does that mean you want different functionalities for specific clients? I'd say there has to be some finite set of client ids or types then, you probably need a thread1(), thread2(), etc.

daviddoria 334 Posting Virtuoso Featured Poster

I will denote the husbands with the following notations h1 = 11, h2=12, h3=13 and their respective wives with the numbers w1 = 21, w2 = 22, w3 = 23

Why assign these ints to the people? Why not use something like this:

struct Person
{
public:
 enum SexEnum {Husband, Wife};
 enum SideOfRiverEnum {Start, End};
 int sex;
 int sideOfRiver;
};

...
std::vector<Person> Husbands;
Person temp;
temp.sex = Husband;
temp.sideOfRiver = Start;
Husbands.push_back(temp);

std::vector<Person> Wifes;
...

that keeps everything very understandable?

David

daviddoria 334 Posting Virtuoso Featured Poster

I will denote the husbands with the following notations h1 = 11, h2=12, h3=13 and their respective wives with the numbers w1 = 21, w2 = 22, w3 = 23

Why assign these ints to the people? Why not use something like this:

struct Person
{
public:
 enum SexEnum {Husband, Wife};
 enum SideOfRiverEnum {Start, End};
 int sex;
 int sideOfRiver;
};

...
std::vector<Person> Husbands;
Person temp;
temp.sex = Husband;
temp.sideOfRiver = Start;
Husbands.push_back(temp);

std::vector<Person> Wifes;
...

that keeps everything very understandable?

David

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when posting code.

What is the problem? Please provide a sample input, the current output, and the expected output. I also suggest decoupling your file input from your algorithm. Hard code some values and make sure the statistics code works first before introducing another challenge of the file input.

daviddoria 334 Posting Virtuoso Featured Poster

You are storing the names as int's which doesn't really make sense. I suggest using a std::vector<std::string> .

I suggest breaking your problem into two programs for the moment. One which reads your data, and the other which sorts a list of names.

1) For the input, checkout these examples:
http://programmingexamples.net/index.php?title=CPP/IO/ReadingLines
http://programmingexamples.net/index.php?title=CPP/IO/FileInput

2) For the sorting, check this out:
http://programmingexamples.net/index.php?title=CPP/STL/Sort

Good luck,

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

You'll probably have much better luck finding a forum dealing with serial communication in C - on a c++ forum I wouldn't expect many answers :(

daviddoria 334 Posting Virtuoso Featured Poster

Please explain the draw condition and errors that you hope to check for in a paragraph form. Then convert this to pseudo code. Then you can write real functions. Also, I would probably store the board as a std::vector<std::vector< char > > so the squares can be accessed like a matrix (e.g. board[0][1] ) instead of a linear array (0-9). It will make the logic seems more natural. Then you can write loops like:

RowHasWinner(int row);
...
for(int i = 0; i < 3; i++)
{
RowHasWinner(i);
...
}

Good luck,

David

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

You may have better luck looking for a Visual Studio forum as this is just a general c++ forum.

daviddoria 334 Posting Virtuoso Featured Poster

The goal shouldn't be to get this to work, it should be to learn something :)

I would separate the averaging computation from the input. There should be a inputData() and a computeAverage() . This will help you track down the error, as well as help the next reader of your code follow what is going on.

daviddoria 334 Posting Virtuoso Featured Poster

It looks to me like you have copied and pasted that code from another thread (the numbers in your text). This means you haven't compiled it. I also don't see a main() or the definition of mystruct.

daviddoria 334 Posting Virtuoso Featured Poster

I would definitely suggest using a std::vector<std::string> to store the player names. Also, if you hard code an example input that will eliminate one source of errors (the input). It will also let us copy/paste/compile/run your code to help you find the problems. It is much harder when you have to also give us an input file and we have to confirm your input function works, etc.

daviddoria 334 Posting Virtuoso Featured Poster

You're going to have to show us that you have tried before you will get any help. What exactly are you struggling with? I'd suggest breaking it down into little pieces. At first, simple, short stand alone programs, which you then convert into function in your actual program.

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags when posting code.

The way you are accessing it with temp->key; indeed requires key to be a public member. Nested classes don't get any special privileged (i.e. just because you have defined a class inside of a class doesn't mean it gets access to the outside classes private members). You would have to make an accessor like sorted_list::GetKey(){return this->key;} David

daviddoria 334 Posting Virtuoso Featured Poster

Try installing the libstdc++* packages.

daviddoria 334 Posting Virtuoso Featured Poster

Works like a charm, thanks!

daviddoria 334 Posting Virtuoso Featured Poster

Great, thanks Dragonbaki! For future readers, the problem was just with not properly closing tags of nested tables. The code was a mess so I don't think it's worth posting here.

daviddoria 334 Posting Virtuoso Featured Poster

"0" is kind of arbitrary. It makes more sense to return EXIT_SUCCESS if everything went well, and EXIT_FAILURE otherwise. The 'system pause' I think is because some IDEs close the terminal right away so you can't inspect the results. I always thought this was pretty silly...

daviddoria 334 Posting Virtuoso Featured Poster

I have a style:

.title1
{
color: #0000BB;
font-size: 25pt; 
text-align: center;
}

but when I use it with:

<span class="title1">Schenectady Section of the IEEE  More Words</span>

it doesn't center the text!

You can see this behavior here:
http://ewh.ieee.org/r1/schenectady/New/

Surely I am just doing something silly...

Thanks!

David

daviddoria 334 Posting Virtuoso Featured Poster

Currently at the top of every page I have this:

<HTML>
	<HEAD>

	<TITLE>Schenectady Section of the IEEE</TITLE>


	<META NAME='url' CONTENT='http://www.ewh.ieee.org/r1/schenectady/'>
	<META NAME='author' CONTENT='Authorname'>
	<META NAME='email' CONTENT='author email'>
	<META NAME='expires' CONTENT=''>
	<META NAME='revision-date' CONTENT='6-Sep-1999'>
	<META NAME='keywords' CONTENT='Schenectady Section'>
	<META NAME='description' CONTENT='Schenectady Section of the IEEE'>
</HEAD>

If I move this to a "meta.php" and

<?php
include 'meta.php';
?>

At the top of each page, will it lose any function? I.e. will the search engines that are looking for meta tags still see them?

Thanks,

David

daviddoria 334 Posting Virtuoso Featured Poster

Your structs look fine. I suggest hard coding some inputs so you can show us an example input, the output it produces, and tell us the output you would expect it to produce.

David

daviddoria 334 Posting Virtuoso Featured Poster

It runs fine for me. I just had to change two things where you had 'const' twice:

int SortedType::GetLength() const const

to

int SortedType::GetLength() const

Can anyone else produce sharifyboy7's problem?

daviddoria 334 Posting Virtuoso Featured Poster

Which if statement? If you could make the smallest compilable example that demonstrates the problem and tell is exactly what is happening and what you would expect to happen, that would be very helpful.

daviddoria 334 Posting Virtuoso Featured Poster

It looks fine to me. I removed the user input for easier testing and gave two test cases:

#include <iostream>
#include <stdexcept>
#include <exception>
using namespace std;
using std::runtime_error;

int main(int argc, char* argv[])
{
int totalPay = 0;
//int hours = 0; // throws exception
int hours = 1; // doesn't throw exception
int avgPay;

try
{
 if (hours == 0)
 {
  throw exception();
 }
 avgPay = totalPay / hours;
 cout << "Your average pay per hour is: $" << avgPay << endl;
}
catch (exception &p)
{
 cout << "OOPS!!!!!" << endl;
}


return 0;
}

What is the problem?

David

daviddoria 334 Posting Virtuoso Featured Poster

This is the important line:

test.c:1:19: error: fstream: No such file or directory

It means your system is not setup correctly. I would try

sudo yum install glibc* gcc* libc*

and then see how it goes.

David

daviddoria 334 Posting Virtuoso Featured Poster

That should show you exactly how it works :) If you don't follow it, break it up into smaller statements: int m=n=j++ + j++; If you have specific questions let us know.

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

Mike -

If you could take a look here:
http://programmingexamples.net/index.php?title=CPP/Boost/Threads
http://programmingexamples.net/index.php?title=CPP/Boost/ThreadsMember

and either confirm these are a good demo or fix/improve them that would be great!

David

daviddoria 334 Posting Virtuoso Featured Poster

I don't follow you. You say you run it and it work, but then you say you run it and it crashes?

daviddoria 334 Posting Virtuoso Featured Poster

If you're looking for a basic example of pthreads, this shows how to create a thread: http://programmingexamples.net/index.php?title=CPP/PThreads

If anyone can make that example more informative, that would be great!

David

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

Please use code tags to post code. Also, did you try it? I suggest hard coding the input. Then show us the output and tell us the expected output.

David

daviddoria 334 Posting Virtuoso Featured Poster

I have two pages, header.php and sidebar.php which I want to include on several pages using:

<?php
include 'header.php';
?>
<?php
include 'sidebar.php';
?>

However, there are two different issues.

On this page http://ewh.ieee.org/r1/schenectady/New/index.php , the included text is put BELOW the text on index.php, even thought it is included BEFORE the index.php text.

On this page http://ewh.ieee.org/r1/schenectady/New/events.php , you can see that the sidebar is "messed up" (the yellow part is much wider than it should be, and the table starts below the sidebar rather than to the right of it.

Any suggestions on how to fix these things?

Thanks!

David

daviddoria 334 Posting Virtuoso Featured Poster

Ah, I had the syntax a bit wrong (an extra space: http://www.daniweb.com/forums/thread326784.html) - php is indeed installed. It is working perfectly. If I need to do it without php that link looks like it'll do the trick.

Thanks!

daviddoria 334 Posting Virtuoso Featured Poster

Wow that is pretty sensitive! I removed the space and it worked correctly - thanks :)

daviddoria 334 Posting Virtuoso Featured Poster

I don't believe php is enabled on my webserver. Is there a way to do this without php?

daviddoria 334 Posting Virtuoso Featured Poster

I put a simple script:

<? php
print "Hello world";
?>

here: http://ewh.ieee.org/r1/schenectady/HelloWorld.php

When I go to the page, I don't see "Hello world" displayed. Does that mean PHP is not enabled on the server?

Thanks,

David

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

You'll have to elaborate. You just want a video? Or you want code to open a 3D data file and produce a video of it rotating? This is definitely a fairly complex task, so you'll have to specify your operating system, which graphics library you want to use (OpenGL, I'd suggest VTK myself, etc).

daviddoria 334 Posting Virtuoso Featured Poster

You can fix the warning:

The source directory

    C:/ne7ssh-1.3.2/src

  does not contain a CMakeLists.txt file.

by commenting:

#add_subdirectory ( src )

Other than that, cmake ran fine for me (Fedora 13). I couldn't build it because I didn't install Botan, but the Makefile was generated successfully.

daviddoria 334 Posting Virtuoso Featured Poster

That is definitely the best way, I agree! You can go to github.com, gitorious.org or http://code.google.com/ and search for projects (they are just like sourceforge). I'm sure people would be happy to have some help.

Good luck,

David