Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where do I put the for-next loop?? Within the constructor??

Well Duuuah! of course you put it in the contructor -- afterall that was your original question wasn't it.

delete line 70 of your original post (I added line numbers to make it easier to refer to it). Then put a for-next loop there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Duoas already told you how to do it -- create a for-next loop and set each element to 0

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of examples right here at DaniWeb. Just search for ifstream and getline()

#include <fstream>
#include <string>
#include <vector>
using namespace std;

int main()
{
   vector<string> strings
   string line;
   ifstream in("filename");
   while( getline(in, line) )
        string.push_back(line);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sadly, the c++ compiler i have to use at uni must use those headers, as it isn't a very new program. So I do have to use them :(

Oh, that's unfortunate that your school is making you learn something that will never be used in the real world. We tossed out those compilers 15 years ago.

I've never come across any examples of this before.

Well, then you didn't read the POST #6 very well, if at all, because it has exactly what you need.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

House.

House isn't a sitcom.

My varorite sitcom from UK is Ivory Towers, although Red Dwarf was very good too. From USA is I Love Lucy and The Jeffersons. I don't like any of the current ones.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you don't need lines 25-29 to zero out the array. Do it when the array is declared, like this: int matrix[101][5] = {0}; >>What alterations/additions do I make to the code to import the .txt file into the array?
Code that reads the text file. Start by deleting lines 1 to 3 -- al those files are obsolete in C++. Most likely all you need is this:

#include <iostream>
#include <fstream>
using namespace std;

Next declare an ifstream object Then in a loop read the integers into the array. See Vernan's post #6 above, which is an example of how to read the file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
41.	do
42.	{
43.	        cout << "Enter employee gross sales ( -1 to end )" << endl;
44.	        cin >> sales;
45.	} while(sales >= 0);
46.

you don't need variable sales. You can enter the values directly into the money array by using a loop counter, comething like below. Note you also have to test the value of the loop counter to make sure it doesn't go beyone the bounds of the array.

int i = 0;
do
{
    cout << "Enter employee gross sales ( -1 to end )" << endl;
    cin >> money[i];
    
} while( i < 10 &&  money[i] >= 0);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

do mean VC++ 2008 Express? All C++ compilers support command-line interfaces, its part of the c++ ISO standards. int main(int argc, char* argv[]) In the above line, argc is the number of command-line arguments and argv is an array of the arguments.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The other file you need to write is the *.cpp file that implements the functions in that class, and main() which all standard C and C++ programs have to have. When you created that Dev-C++ project it already created the main.cpp and main() function shell. So now all you have to do is add the implementation code for the Person class, specifically the functions that appear on lines 13, 15 and 16. For example, so start you out, put this in main.cpp

Person::Person(const string & ln, const char * fn)
{
   // put the implementation code here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>So why doesn't this work?
You'll have to be just a tad bit more specific.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 1: you forgot to add the includes

you can delete lines 17 and 21, and just use variable k in line 20.

Here is a simplified version of your program

#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<string> strings;
bool done = false;

int main()
{ 
string sentence;
sentence = "This is sentence Two\n";    
strings.push_back("This is sentence One\n");
strings.push_back(sentence);
strings.push_back("This is sentence Three\n");
for(int k = 0; k < 3; k++)
{
    cout<< strings[k] << "\n";
}
system("pause");
return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>//static double AnnualInterestRate
static class variables are just like global variables with a class scope. They have to be declared at the top of a *.cpp file just as if they were normal global variables.

// account.cpp file
#include "StdAfx.h"
#include "Account.h"

double Account::AnnualInterestRate = 0;
// rest of code goes here
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>THe only thing that seperates each sentence would be a new line.
Those are not sentences. Those are just lines, and getline() is what you want to use.

using a vector is the easiest way to do it when you don't know how many lines there are. If you know you only want two lines then just create an array of 2 strings.

There are lots of ways to do your program. I gave you a start and will leave the rest for you to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might try using named pipes. I have not tried it but you might experiment with it to see if it will work for you.

jonc commented: Thanks for the URL, much appreciated :) +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you use std::string and std::ifstream, then you can loop through the file using getline(). Store each string in a std::vector array. The code is very simple, like this: If you only want certain line numbers then just count them inside the loop.

#include <vector>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    vector<string> array;
    string line;
    ifstream in("filename");
    while( getline(in,line))
    {
           array.push_back(line);
    }
}

>>but I am wanting to be able to have control over each sentence itself.
Do you mean each line? getline() knows nothing about sentences. Is there something unique that separates one sentence from another, such as a blank line?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Cody: if you want to post code, that is ok, but please

  • Use code tags [code=c++] /* code goes here */ [/code]
  • Don't use ancient header files with .h extension
  • Don't use eof() as you did in line 12 because it doesn't work like that

>> This reads the text in as characters
Why? it could read into integer variables just as easy. By reading in as strings the strings have to be converted into ints before they can be used. That just extra unnecessary work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Everything compiled ok, that error message just means it could not find the class constructor. Make sure method.cpp is part of the dev-cpp project.

One error is that the project has two main() functions. you need to delete one of them.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

go to www.microsoft.com and type in CopyFile in the search box.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I get a linker error with the above code
What is the error message ?

>>So why cant i declare my Employee employee_list[100] in the main.cpp file?
I thought you said you are getting a link error? link errors will not produce this error, but a compile error will. What is the exact compile error?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can call the win32 api function CopyFile() -- look it up in MSDN for details

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

My guess is you should leave it in the junk. Someone tossed it away for a reason -- most likely because it doesn't work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you don't know how to start the project then you are not ready to write something as difficult as a chat program. There are lots of VB tutorials -- start there.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

As I said before, learn to use google

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

- There have been many reports of dead people voting in elections, most of them were (are) Democrats. I know it has happened in St Louis MO and NY. This phenomena has probably occurred elsewhere too.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean the code you originally posted in post #1? Well, for starters, numbersuffix is undefined.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I made no other changes. Just to make sure, I copied it all over again and just made that one change. I used VC++ 2008 Express. What compiler are you using?

Attached is my project if it will help you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

When I comment out lines 138-141 I get an error at line 178 that says "... error C2664: 'CartesianPoint::CartesianPoint(const CartesianPoint &)' : cannot convert parameter 1 from 'double' to 'const CartesianPoint &' ". To me, the initial error is cause by something very simple to be missing. But, I can't see the "tree thru the forest"....Anyone got an eagle's eye as to the cause?

Yup -- the problem has nothing to do with lines 138-142. Read my previous post for the correction to that error. The problem is mismatched parentheses.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you need to keep track of the last valid pointer as the loop is iterating through the linked list. Then after the loop terminates reset pWalker to the value of the last known good value. Something like this will probably work.

int Count_Words(word *&pWalker, int &count)
{
    int numWords = 0;
       
    pWalker = letter[count];
    word* pTail = pWalker;    
    while (pWalker != NULL)
    {
        letter[count]->back = pWalker->next;
        pTail = pWalker;
        pWalker = pWalker->next;
        numWords++;
    }
    pWalker = pTail;     
    return numWords;     
}

>>shouldn't walking backwards in a double linked list be just as easy as walking forward
Yes, but you have to start out with the last node in the linked list (or tail) -- NULL is not a valid pointer. Then when iterating backwards you can check for NULL because it need to check for the head of the linked list. So there are some differences in how you have to code it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is elsewhere. I tried to compile with VC++ 2008 Express and got errors on FindPerpBisector(). When I recoded like this everything compiled ok. The problem seems to be mismatched parenthases.

void LineSegment::FindPerpBisector()
{ 
   LineSegment perpBis;
   double x = (first.X() + last.X())/2.0;
   double y = (first.Y() + last.Y())/2.0;
   CartesianPoint midPt(x,y);

<snip>

Another suggestion: you header files and class declarations would look a lot better by actually using inline code in the class instead of writing separate functions using the inline keyword

class CartesianPoint
{
 public:
    CartesianPoint() {myX = 0.0F; myY = 0.0F;}
    CartesianPoint(double xVal, double yVal)
        { myX = xVal;  myY = yVal;}
    double X() const {return myX;}
    double Y() const {return myY;}
   void SetX(double xVal) {myX = xVal;}
   void SetY(double yVal) {myY = yVal;}
 
 private:
   double myX, myY;
 };
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

in the code you posted, marray is an array of uninitialized integers, which could have any random values. Consequently the code you posted makes absolutely no sense at all. To add up all the values in the array

int sum = 0;
for(int i = 0; i < numbers; ++i)
    sum += array[i];
cout << "sum = " << sum;
jonathanasdf commented: thanks for your attempt. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 124 looks a bit strange.
CatesianPoint is a class, but you are using it like a typedef?

That line is ok. Class objects are declared like that.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The compiler doesn't know how to output the CartesianPoint class. You probably need to write an overload operator >> for it. You didn't post that class so we have no idea how to help you.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's not right. Look at function Display_Results(). pWalker is declared in that function and never set to anything. Its just a pointer that points to some random memory location, unless of course you changed the program since the last post.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are hundreds of program source code on the net. All you have to do is learn how to use google. There are several ways to do what you want, the oldest and most supported method is via ODBC.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can download the C source code for QStat from here. All you have to do is port it to VB and you won't have to hack away at it. Or port it to C# which might be even easier to do.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Which of the 232 lines does that error occur on ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

search in your old pc the 'olepro32.dll' then try to save/copy it in your new laptop... (that's what I did when my program have a trouble on .dll's

That's pretty dangerous because the old version is probably not the same as the version installed by Vista. You could wind up crashing your whole operating system, causing you to reinstall everything. Better to just download the newest version of VB which everyone knows runs ok on Vista.

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

go to some news web site such as www.cnn.com and select 5 articles. Copy/past a paragraph from each article into your program.

In main() make a menu with the 5 titles and number them a) b) c) d) and e). Then ask for title input. After that create a simple switch statement and which prints the paragraph that is associated with the selected title.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

However, when you imagine to see living/moving things others can't see, and you are sober and call them real, then you are a troubled mind at best.

Who ya gona call ?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Julius Caesar must not have been much of a politician
You are right -- he wasn't any kind of politician because he was born into that position. People of royalty don't have to be politicians.

[edit]Well, I guess I was wrong -- wikipedia[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>the fact that a ship of any kind cannot travel faster than the vacuum speed of light (due to the laws of physics

We don't know if that hold true throughout the universe. Who says we can not travel at worp speed like they do in Star Trek?

>>Yes, I meant walking around the world. Walking around the world is not much of a stretch at all
Dave Kunst has already done that; riding on ships/boats only to cross large bodies of water.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you already have examples posted. use function pointers.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you will need a get function for each of the variables so that you can do this:

writer<<name[x].getID() << " " << writer<<name[x].getLastName() << " "
   << writer<<name[x].getFirstName() << "\n";

[edit]Or do it like Nurue said above[/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

one way to do it is to create an array of function pointers with associated strings for the name of the function. For example, support you type in "add", you would search the array for that word and when found call the associated function, something like this:

struct functions
{
    std::string function_name;
    void *fn();
};

functions fns[] = {
  {"add", add},
  {"subtract", sub},
 // etc etc for each function
};

int main()
{
   std::string cmd;
   cout << "Enter command\n";
   cin >> cmd;
   // now search the array for the command and call the associated function
   // not shown here.
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There is actually nothing very interesting in CotG; every significant factoid mentioned in the book that was not an outright lie has been debunked - thanks for pointing to the wiki, rather than, say - pointing to one of these sites.

Yes, I know, but its interesting reading anyway. I don't really believe what I seen in Start Trek either, but I like to watch it.

I visited that link you posted -- wow what a bunch of nasty stuff.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

operating system? compiler? You can't do that with 32-bit os like MS-Windows or *nix without writing kernel-level code

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>i want tell you evry body sign in this web you give the solution
We all know that is a lie.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

One of the two of you need to stop posting and have only one thread to discuss the issue. You can both post in the same thread, so I'm going to close this one.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you the same person as this one? Not very often we get two people working on the same problem.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

This c++ code also uses FileSystemWatcher