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

you mean something like this?

std::vector<std::string> arr;
std::string line;

while( getline(cin,line) && line[0] != '$')
{
    arr.push_back(line);
}

I hope you realize you can't enter "$1,000.00" with that

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

You don't normally put executable code in *.h files because it will cause lots of link problem. So move the function starting in line 12 of the point.h into the *.cpp file then convert line 12 to a prototype like you did at line 11.

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

This is no such concept as multi-line strings. If you want CR/LF in the string then just append "\n" whereever you want a new line to begin when output

std::string hello = "Hello\nWorld\n";
cout << hello;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I increased the array size from 20 to 100 and the program crashes most of the time on the line nth_element (start, end, end+1, less_equal <int> ()); When I change it to this it works every time nth_element (arr.begin(), arr.end()-1, arr.end());

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

no

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

Do you remember the TV miniseries V ? That's my idea of what aliens would be like. They come to Earth to harvest its human population for food.

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

So what have you done for the past two weeks other than stare at the requiremeents in disbelief ? Have you actually attempted to write those two classes ? Have you studied your textbook and listened to your teacher's lectures? I know that every textbook ever written about c++ will teach you how to write a c++ class.

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

So if you want to talk about heat why not leave that nice chair and join the your men in Iraq or Afganestain and then tell me about heat.

Been there, and done that (VietNam). I serverd 23 years in USAF (1962-1985) but I admit I was never shot or a POW. We have no greater respect than for our military and civilians now serving in Iraq and elsewhere around the world. That was not the kind of heat I was talking about.

But this comment will never be seen by you because you turned tail and ran at the first sign of criticism. Oh well.

VernonDozier commented: Well said. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Well lets see this is my second semester of school. How long did you have to become an ass?

If you cant' take the heat then get out of the kitchen. Second semester student is very good, but after you graduate and get your first job you will only begin learning. You will always have supervisors and peers who will criticize you and your work. So get over it and get used to it.

The people at DaniWeb are here to help you and donate their time to do so free of charge. So don't bit the hand that feeds you.

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

You have to find out where frm1 is declared. Is it a member of a class in which the code snippet you posted resides? Look in the *.h files and see where that variable is declared. Or is it even in a header file.

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

I think you are asking when you add a string to the combo box the currently selected string becomes unselected causing ItemIndex to be invalidated ? If that is true then you will want to save the currently selected string in a local variable in your function, add the string, then call SelectString() to reselect the item.

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

>>Is the only around this to use arrays?
Or linked lists -- yes. I would think something like below will work. You will probably want to declare the pointer in the class header file instead of the *.cpp file as shown below so that it doesn't disappear when the function terminates.

CSliderCtrl *tracker = new CSliderCtrl[numControls];
for(int i = 0; i < numControls; i++)
{
       tracker[i].Create(WS_CHILD | WS_VISIBLE,
          CRect(left, top, right, bottom), this, i);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 44: you need to include <ctime>

Otherwise this is what I get. Is it right or wrong? I'm not certain what your code is trying to do but from the looks of the output it looks like you are trying to sort the array

Array before Partitioning(20) -> 943 ,693 ,788 ,192 ,708 ,138 ,116 ,465 ,853 ,2
35 ,754 ,614 ,992 ,425 ,953 ,221 ,758 ,674 ,392 ,242 ,
Pivot chosen is 242
Partitioning Done Array is now -> 116 ,138 ,192 ,221 ,235 ,242 ,392 ,425 ,465 ,
614 ,674 ,693 ,708 ,754 ,758 ,788 ,853 ,943 ,953 ,992 ,
Remember Pivot chosen was 242Press any key to continue . . .

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

If you aren't concerned about portability then the registry would be my first choice because it isn't reall all that difficult for programmers who have a pretty firm grasp of c or c++ language. There's only two or three win32 api functions you need to learn in order to implement this. Of course any half-decent hacker can easily change the registry entry to whatever he wants. I would encrypt the data to make that more difficult to accomplish.

I have written a few things in the *.exe itself, but its very tricky For example in your case the installation program could add a date to the end of the *.exe file and the *.exe file could read that date each time it is executed.

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

>>CWinsockInterface::~CWinsockInterface
Sounds like something that you wrote. To my knowledge there is no such Microsoft class.

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

1) yes -- see ateixt()

2) probably not.

3) No. MS-DOS had terminate-and-stay-resident programs that did something like that.

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

Here and here are real American war tanks :)

Several other pictures here

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

This is how I code a join in Sybase SQL, I assume MySql is nearly the same. Note that if you use the * in the select clause the fields from table2 can not duplicate the names in summercamp. If there is such a duplicate then one or both name have to be changed in the select clause. In the following example both tables have an id field and we want to retrieve both if them. So I coded it to give a unique name to the id field in each table.

SELECT summercamp.id   summid,
            <other fields from summercamp here>,
            table2.table2id,
            <other table 2 fields here>
FROM summercamp, table2
where summercamp.id = '.$id
and table2.id = summercamp.id

I just noticed an error table2.id table2id

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

More info here

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

3. Don't use "\n" rather than use std::endl ? why search about it. what if you compile where newline is is defined as "\r\n"

It doesn't matter because the compiler will make the conversion appropriate to what is required by the file system. On MAC the '\n' is converted to '\r' before saving to the file. MS-Windows/MS-DOS its converted to "\r\n". Other operating systems could be almost anything. Its been standard practice every since C was invented a million years ago to use '\n'.

I rarely use std::endl any more because it also flushes the file system, which can be time consuming when writing a lot of lines to the file.

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

c++ has other more dependable typecasting. C-style typecasting can let you kill yourself if you don't know exactly what you are doing, such as in this example attempting to typecast to normally incompatible data types.

double a = 12.34;
char* b = (char *)&a;
int c = (int)b;

In c++ if you use static_cast you will get a compiler error int d = static_cast<int>(b); // <<<< Error here

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

Where is function getline(). It isn't a standard C function so you must have written it yourself.

I thought you are supposed to write the new text entered from the keyboard into the file? Your program isn't doing that. And you need to rewind the file pointer back to the beginning of the file if you want to re-display the contents of the entire file.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int foo( PetInfo* pInfo)
{
    pInfo->petType = cat;
    // etc. etc

   return 0;
}

int main()
{
    PetInfo MyCat;
    foo( &MyCat );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

1) why use double in the struct since the values in the file are only integers.

2) A linked list would be a better choice because it is easier to add new structs. Here is one of the many tutorials you can find with googler.

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

1) ComplexNumber.h: move the last line down outside the class and code like this: extern void printComplexNumber (const ComplexNumber&); 2) you did not code the class constructor. One was to do it is in ComplexNumber.h ComplexNumber ( ) {realPart = 0; imaginaryPart = 0; } That is called inline code when you put the executable code in the *.h file instead of *.cpp.

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

Welcome to DaniWeb. Hope you have a great time here.

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

I didn't get your results. I compiled and ran your program using VC++ 2008 Express with debug on.

Time elapsed in first= 6.37265
Time elapsed in second= 3.19138
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

okay, experts, i need help.

:icon_eek:

I think the problem is the way you are opening the file.

a+
Open a file for reading and appending. All writing operations are performed at the end of the file, protecting the previous content to be overwritten. You can reposition (fseek, rewind) the internal pointer to anywhere in the file for reading, but writing operations will move it back to the end of file. The file is created if it does not exist.

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

looks ok to me, except in the cin.getline() lines you should use sizeof instead of hardcoding the number cin.getline (text1, sizeof( text1 ) ); And you could declare a const int to define 256 instead of hardcoding it everywhere.

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

do it exactly like it was done to initialize c in lines 64 and 65. Also, did you bother to read the link I posted?

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

In ComplexNumber::ComplexNumber you are supposed to set the values of the class variables to that of the parameters.

ComplexNumber::ComplexNumber(double r, double i) 
{ 
    this->realPart = r;
    this->imagenaryPart = i;
}

in main() move the line ComplexNumber userInput(c1, c2); down to after the user has entered the values if c1 and c2.

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

Also I initialized a and b

Not in the code you posted you didn't. They are still uninitialized at line 67. So if that code worked for you then it was purely by accident.

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

>>When I just run the loop two times without any statements in them, they just give any >>damn value which may have a large difference upto around 25% !!!

If you have optimization enabled and have an empty do-nothing loop then the compile will probably just delete the loop altogether. It will (or might) also delete the loop even it it is not empty but does nothing that changes, such as in the code you posted. For example the compiler will move line 42 up outside the loop and then delete the loop since it does nothing else.

Also lines 42 and 53 are doing something completly different. Line 53 just get the address of the structure (actually depending on implementation it may not even do that), while line 42 actually copies all the members of the structure and you wind up with two idential structure objects.

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

here is an example that uses stringstream as helper.
See this thread for explaination of line 27.

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <limits>
using namespace std;

int main()
{
	std::string one;
    int Number = 0;
    std::string line;
    std::string two;
    std::string three;

    ifstream File("..\\TextFile1.txt");
    if(!File.is_open())
    {
        cout << "Can't open the file\n";
        return 1;
    }
    while( getline(File, line) )
    {
        stringstream stream(line);
        getline(stream,one,',');
        stream >> Number;
        stream.ignore ( std::numeric_limits<std::streamsize>::max(), ',' );
        getline(stream,two,',');
        getline(stream,three,',');
    }
    return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It wouldn't matter because the values in the array would still be wrong. Use a loop to initialize them to 0.

Even then the line b[c[a[j]]] = a[j]; won't work because all values of arrays a and c are 0, so you might as well write that line like this: b[0] = 0;

I'm not sure what you want to put in arrays a and c, but I'm certain it isn't 0.

If you have not see this wiki explaination you should probably read it and the example c program

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

Several ways

  • save values to a file on program exit and read on program start
  • save values in the registry
  • save values in the program *.exe file

All you really need to do is save the installation date in a hidden file somewhere then read it each time the program starts and compare that date with the current computer's clock.

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

this maybe what your looking for

http://www.cplusplus.com/reference/clibrary/ctime/clock.html

Not for this purpose because you can't get keyboard input while that wait function is working.

There is a way to do it with non-standard c functions from conio.h, but they are generally discouraged because most compilers don't implement them.

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

This is how I code a join in Sybase SQL, I assume MySql is nearly the same. Note that if you use the * in the select clause the fields from table2 can not duplicate the names in summercamp. If there is such a duplicate then one or both name have to be changed in the select clause. In the following example both tables have an id field and we want to retrieve both if them. So I coded it to give a unique name to the id field in each table.

SELECT summercamp.id   summid,
            <other fields from summercamp here>,
            table2.table2id,
            <other table 2 fields here>
FROM summercamp, table2
where summercamp.id = '.$id
and table2.id = summercamp.id
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to put the timer code in a second thread then when someone types something in thread1 kill the timer thread. How to construct new threads depends on the operating system.

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

I think it's still crashing

0x08048fbb in countSort (numbers=0xbfea2af0, size=5) at sorting.cpp:69
69 b[c[a[j]]-1] = a[j];

I wish I can help :(

Its because the values in array a are trashed -- it was never initialized to anything.

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

>>I have it defined as an integer because when i try a const like the previous person said
I didn't read what he said but I suspect he meant that classes should be declared as const int only where it appears in the parameter list of a function. All other places do not use const keyword. And you can't use const all by itself because it requires a data type, such as int or char*. All const means is that its value can not be changed.

line 71: you need to pass the value of classes as a parameter to that function. On line 4 you have destroyed the value that was originally entered at line 24 -- don't do that.

[edit]Also what ^^^he said :) [/edit]

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

I have been using the Insert Link button every since I Joined DaniWeb and it always worked perfectly. Until now.

here
The above link shows the results.

The way I do it is first highlight the words I want then hit the InsertLink round button, copy the URL and finally hit the Ok button. This doesn't work any more.

<Edit> Oh nevermind -- I was doing something wrong. </Edit>

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

line 5: where is classes defined?

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

>>Ok, I have made the changes but I still get a crash when running the program.

I'm not supprised because there are compile errors you have to fix.
line 50: you can't allocate an array using an int that is not a const. The way to allocate c is using the new operator int* c = new int[max]; lines 59-69: you are still using the hard-coded value of 8 where you should be using size.

line 62: using unitialized array a, which is the reason your program crashes.

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

That's ok but you still can not count from 0 to and including 8. If you do that is 9 numbers, not 8. If you are required to read a max of 256 integers then set the array size fo the max of 256.

and use the const arraysize declared on line 13 to declare the array on line 14.

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

The loop at lines 28-32 could be better written like this:

int i = 0;
while( i < arraysize && infile >> numbers[i] )
{
    i++;
}

line 34: do you know for a fact that the file contains exactly 8 integers? It would be better to pass the value of i from the above code countSort(numbers, i); line 51: >> for(i = 0; i <= size; i++)
You need to use the < operator, not <= because arrays are counted 0 to but not include the number of elements in the array -- 8 in this program. Same thing goes for all the other loops in that function. They all count beyond the legal array bounds.

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

nuclear tests


Nice movie and music but the tanks appear to be very very ancient.

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

>>void main(void)

Read This
lines 11 and 12: where did you defind MaxNumber and MaxCharLength?

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

The way I wrote logging files was to open and close the file for each log entry. I know it takes a lot of cpu time to do that but it gives other processes a change to jump in and copy or read the file. The logger checks to see when it can open the file for output and exclusive access. If it fails then it sleeps a little while and tries again.

That doesn't matter whether it is a sequential of fixed-length binary file. It all depends on what you want to write in that file.

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

This should give you some ideas how to solve the problem. This just counts the number of inteters until '\n' is detected. You should be able to construct a function that does something similar for what you want.

#include <iostream>
using namespace std;

int main()
{
    int n;
    int count = 0;
    cout << "Enter a number\n";
    while(cin.peek() != '\n' && cin >> n)
        count++;
    cout << "Count = " << count << "\n";
    return 0;
}