mitrmkar 1,056 Posting Virtuoso
employee[6]->printreport();
report->printheaders();

You cannot make the above function calls because the pointers are not pointing to allocated objects. I.e. you need to do e.g.

report = new payroll();
// ... now you can utilize the 'report' pointer 
report->printheaders();

Note that the indexes are zero-based i.e. if you have employee[ [B]6[/B] ] , then the last valid index is 5 (not 6).

mitrmkar 1,056 Posting Virtuoso

You might try something like the following, it removes all spaces that precede an '>'.

const std::string srch = " >";
std::string::size_type pos;

while(std::string::npos != (pos = Line123.find(srch)))
{
    Line123.erase(pos, 1);
}
mitrmkar 1,056 Posting Virtuoso

Can anyone please help? Thank you very much :).

You might post the current (nicely formatted ;)) code and explain in more detail what you are stuck with...

mitrmkar 1,056 Posting Virtuoso

I would also like its modified time and date.

See e.g. RegQueryInfoKey()

Ancient Dragon commented: You're right :) +32
mitrmkar 1,056 Posting Virtuoso

In brief, the code establishes the ownership of Form2 i.e. Form1 is said to own Form2.
Quoting MSDN here:

* An owned window is always above its owner in the z-order.
* The system automatically destroys an owned window when its owner is destroyed.
* An owned window is hidden when its owner is minimized.

http://msdn.microsoft.com/en-us/library/ms632599(VS.85).aspx#owned_windows

mitrmkar 1,056 Posting Virtuoso

Is it correct now?

Not quite, array indexes start from zero, not from one, i.e. you have to change

// from 
questions[1] = "What is the net?";
// to 
questions[ 0 ] = "What is the net?";

// and so on ...
mitrmkar 1,056 Posting Virtuoso

I dont know why this is happening and what could be done about that.

form2->TopMost::set(true);

It is happening because that is what the above line does.
Maybe you could instead try to use the Form2's Owner property, i.e.

Form2 ^form2 = gcnew Form2;
// Form1 owns the form2 ...
form2->Owner::set(this);
form2->Show();

That way Form2 stays above Form1, but won't get in the way of any other windows.

mitrmkar 1,056 Posting Virtuoso

Are you sure about the input file's name ??

fin.open("readLab5.cpp");

You almost got the code tags right, however next time you might want to utilize the "Preview Post" button to make sure that the code tags really are right.

mitrmkar 1,056 Posting Virtuoso

... The exception to this rule is when the member is static and integral.

The exception to this rule is when the member is static and integral and const.

mitrmkar 1,056 Posting Virtuoso

^^^
EDIT: became obsolete

mitrmkar 1,056 Posting Virtuoso

The prototype and the definition mismatch ..

int ConvertANSI(char sChar [] );
int ConvertANSI(char szText [] )
{
	return static_cast<int>(szText[0]);
}
mitrmkar 1,056 Posting Virtuoso

Hey,

I have been trying to learn C++ for a few months know but I'm still not 100%. I've got a good book and all that just do get a bit confused. The thing is I want to learn GUI but i'm not sure what to do. Should I go straight onto GUI or stay on basic C++ and learn that until 100%.

Write back. Thanks.

Maybe get a good book teaching you how to program GUIs and take your time to learn both C++ and GUIs.

mitrmkar 1,056 Posting Virtuoso

Would the corrections be to make the code printreport(); and printheaders();?

I do need to clean up my code, and will as soon as I have a couple of hours to sit and do it. I am trying to get the program to execute correctly. Thank you kindly.

You'd probably just want to delete those two faulty lines altogether, since you don't have any data gathered yet.

mitrmkar 1,056 Posting Virtuoso

At least a couple of severe errors ...

...
payroll *employee[6], *report;
// here you call printreport() through an uninitialized/unallocated pointer, 
// it is a big no-no 
employee[0]->printreport();
int i=0;
char aemployeename[14],apaystat;
double ahoursworked, ahourlyrate, minnp,maxnp, netpays[6];
void sortnetpays(double netpays[], int i);
// here you do it again ...
report->printheaders(); 
...

Last but not least, I'd really suggest you to format the code in order to make it readable. You'd be doing a favour to yourself first and foremost, I think.

Nick Evan commented: A lot of people underestimate the benefit of code-formatting +6
mitrmkar 1,056 Posting Virtuoso

it gives an error while using vc++:
'stringstream' : undeclared identifier

#include <sstream>

mitrmkar 1,056 Posting Virtuoso

I think the problem is with GNU being Dev C++.......looks like it is something to do with the virtual functions?

There is no implementation of findgrosspay() in the payroll class.

mitrmkar 1,056 Posting Virtuoso

You have obviously gotten confused about the syntax of returning a value in VB, e.g.

Instead of doing

GetRandomNumberInRange = szS + Lower;

you should return the resulting value at that point. And change the GetRandomNumberInRange() 's signature too, so that it returns int.

mitrmkar 1,056 Posting Virtuoso

why wont this one work???????....

Be more specific about what is not working, spend some time trying to describe the exact problem(s), instead of just posting slightly modified code time after time (without code tags).

Then about arrays and indexes, assuming that you eventually choose to have an array of 5 integers, as suggested by niek_e, i.e.

int candidate[5] = {0,0,0,0,0};

Now to iterate through all the 5 indexes using a for loop, goes from 0 to 4

for (int i = 0; i < 5; i++)
{
     cout << "candidate[" << i << "] is: " << candidate[i] << '\n';
}
mitrmkar 1,056 Posting Virtuoso

I have to compare the third value in each line.it will be a string(eg:name).
this name will be selected from a combo box.this has to be compared with the file contents and then deletion performed.

You can probably use stringstream to split an input line into three parts.

mitrmkar 1,056 Posting Virtuoso

i want to delete a particular row from the file.i have three values written in the single line.
i have to select a value from a combo box where one of the values was written at the time of writing it to the file.how could i accomplish this?ie,how could i delete the line with the selected item from the combo box?i use vc++

Open a new file for output, into which you write all the lines except for the one that contains the value you wish to delete. Then eventually replace the original file with the new file.

mitrmkar 1,056 Posting Virtuoso

how to initialize this...
STARTUPINFO stInfo;

At minimum, you need to initialize the STARTUPINFO structure's cb member.

PROCESS_INFORMATION pi = {0};
STARTUPINFO stInfo = {0};
// set the size of the struct
stInfo.cb = sizeof(stInfo);

PS. Please use code tags when you post code.

mitrmkar 1,056 Posting Virtuoso

Hi thanks for responding me and i just check as u told...if i select the "Release Mode" from IDE then i Compile and run the application then it works fine..But if i run the application with the exe (Clicking the exe)which i got from release folder,i got the user defined message "Cannot spawn the Child process"...The following is the code which i have used for creating a process...

CreateProcess( NULL , "C:\\windows\\notepad.exe", NULL, NULL, FALSE, 0 , NULL, NULL, &stInfo , &pi);
Kindly help me ...Sherin

When CreateProcess() fails, call GetLastError() to get the reason for the failure.

mitrmkar 1,056 Posting Virtuoso

im using the ios::nocreate in a fstream with vc++ 2008 express but its say its not a member of std::basic_ios...

That flag is not available anymore, so simply don't try to use it. (The same goes for ios::noreplace )

mitrmkar 1,056 Posting Virtuoso

I'd suggest you to take an hour or two and format the code properly, as of now it is very difficult to read. Consider the following two blocks ...

class hourly: public payroll{
   public: double findgrosspay(){
   if(hoursworked > 40){
   overtimehours=hoursworked-40;
   regularpay=hoursworked*hourlyrate;
   overtimepay=overtimehours*(hourlyrate*1.5);
   grosspay=regularpay+overtimepay;}
   else{
   grosspay=hoursworked*hourlyrate;
   regularpay=grosspay;
   return grosspay;
   }//IF
    };//findgrosspay
    };
class hourly : public payroll
{

public: 

    double findgrosspay()
    {
        if(hoursworked > 40)
        {
            overtimehours  = hoursworked - 40;
            regularpay     = hoursworked * hourlyrate;
            overtimepay    = overtimehours * (hourlyrate * 1.5);
            grosspay       = regularpay + overtimepay;
        }
        else
        {
            grosspay   = hoursworked * hourlyrate;
            regularpay = grosspay;

            return grosspay;
        }
    };
};
mitrmkar 1,056 Posting Virtuoso

this problem i fixed \o/

now... it wont let me declare more variables :S

It's really best if you just post the code you are having problems with, explaining what the trouble is.

mitrmkar 1,056 Posting Virtuoso

Post the current code.

mitrmkar 1,056 Posting Virtuoso

Please use code tags when you post code.

Mostly you have there comments not marked as comments, and also a couple of semicolons were missing ...
Use the VC++ editor to edit code, so you'll benefit from its syntax colouring, effectively meaning less errors.

#include "stdafx.h"
#include <iostream>

using namespace std ;

int main()
{

// Declare x, y, temp, remainder as Integer.
int x;
int y;
int temp ;
int remainder = 1;

// read in the two integers

cout << endl ;
cout << "Enter the first number (positive integer) : " ;
cin >> x ;
cout << "Enter the second number (positive integer) : " ;
cin >> y ;

//echo inputs

cout << "Input numbers are: " << x << " , " << y << endl ;

// Write a C++ if statement to determine if x < y.

if ((x == 0) || (y == 0))
{
cout << "ERROR: Value of 0 has been entered." ;
return (-1);
}

if (x < y)
{ // exchange values of x and y
temp = x;
x = y;
y = temp;
}

/* At this point we will always have x >= y */


// Initialize remainder.

while ( remainder != 0 )
{

/*
Write the loop expression and loop body code in C++.
In C++, the expression (x % y) gives the remainder
after dividing x by y.
*/

// value of q
temp = x / y; …
mitrmkar 1,056 Posting Virtuoso

I am confused as to where and how I have to declare the variables........

Before you use them, i.e.

int main()
{
...
string aemployeename;
char apaystat;
double ahoursworked, ahourlyrate;
while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate)
...
mitrmkar 1,056 Posting Virtuoso

You haven't declared the variables you use in the main()'s while loop ... while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate){ You still an extra semicolon in the while loop of ... payroll::printreport() You have a member variable paystat but not stat

mitrmkar 1,056 Posting Virtuoso

You have an extra semicolon in couple of places, e.g.

// the following effectively first reads all the available input and only after that advances further ...
while(fin>>aemployeename>>apaystat>>ahoursworked>>ahourlyrate);{

If you would have a do/while construct, then you'd need the semicolon, i.e.

do
{
    // something
}
while(something) [B];[/B]
mitrmkar 1,056 Posting Virtuoso

Why all of the sudden old threads are renewed ?
I made a reply to an old thread by accident & I did apologize for that. Now 2 more have been renewed.

I think it just happens quite easily, consider a newbie who reads a thread and maybe sees something relevant/interesting in the "Similar threads" section (at the bottom of the page), clicks on a link there, and eventually posts a (more or less late) helpful reply, without thinking about when the OP posted. The keyword here is newbie, I think.

mitrmkar 1,056 Posting Virtuoso

yes, i do full path & put it in the same folder
both the same problem

Could it be that the current working directory (the lpDirectory argument) is not what it should be at the time you call ShellExecute(), i.e. proto1 does not find the files?
Note that you should specify NULL for lpDirectory in order to use the calling program's working directory (now you are using a zero-length string).

http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx

mitrmkar 1,056 Posting Virtuoso

Doesn't seem to work. Umm... i guess what i'm really looking for is an example to play a sound file while the user is going through the program and an example that would stop the sound.

Maybe you tried it the wrong way, the following plays a .wav file

// start playing the file continuosly and asynchronously
PlaySound("C:\\WINNT\\Media\\Ctmelody.wav", 0, SND_FILENAME|SND_LOOP|SND_ASYNC);
// Listen to it for 5 secs
Sleep(5000);
// Stop playing
PlaySound(0,0,0);
mitrmkar 1,056 Posting Virtuoso

Perhaps SEPARATOR?

mitrmkar 1,056 Posting Virtuoso

I'd suggest you to read a single whole line inside the while(), i.e.

while (inFile >> employee >> hours >> payrate >> taxbracket >> exemptions)
{
   ...

and then remove the line you have at the end of the while loop inFile >> employee >> hours >> payrate >> taxbracket >> exemptions;

mitrmkar 1,056 Posting Virtuoso

It is #define CLIP_MOUSEOUT 0 instead of #define CLIP_MOUSEOUT = 0

mitrmkar 1,056 Posting Virtuoso

Thanks for your reply, but I have Visual C++ 2005 (professional) on the computer, but it won't compile it for me anyway, so that's when I tried it on the 2008 express edition( which didn't work). Is there anything radically wrong with the code or is it the program?

Are you just missing ...

static std::ostrstream m_oStream( m_szString, MAX_DIGITS );
mitrmkar 1,056 Posting Virtuoso

You have to check against std::string::npos the return value of the find() method.

std::string::size_type pos = string1.find("*");

if(std::string::npos != pos)
{
    // found a match at 'pos'
}
else
{
    // not found
}

For information on std::string::npos see
http://www.cplusplus.com/reference/string/string/npos.html

mitrmkar 1,056 Posting Virtuoso

You only have storage for two CTreeComponent pointers ... CTreeComponent* m_children[2]; the add(...) method could check that you are not using out of bounds indices.

mitrmkar 1,056 Posting Virtuoso
#define NUMBER 0
clips[ NUMBER ].x = 240

Would you mind posting the error message(s) that you get using the above non-working construct? And what is your compiler?

mitrmkar 1,056 Posting Virtuoso

It has to be ...

fstream file_op2(filename.[B]c_str()[/B], ios::out);
mitrmkar 1,056 Posting Virtuoso

i wan to write into different files......i am using a loop so i wan the name to be generated automatically...and not as in the coding.....if its like in the coding then the classes will be written in 1 file....i wan to be like, when the first class is found i want it to write into a new file maybe test.1 so it continues till the last class is detected..but i wan it in the loop format....i wan the path of the file to be generated automatically with different names so each class will be written inside different files..

Then put the filename together like

[B]int[/B] counter = 1;
stringstream sstrm;
sstrm << "c:\\file#" << counter << ".txt";
string filename = sstrm.str();
cout << filename;
mitrmkar 1,056 Posting Virtuoso

Not sure what the actual problem is, but maybe you are missing ios::ate so that the file does not get truncated each time you open it, i.e.

file_op2("c:\\arun.txt", ios::out|[B]ios::ate[/B]);
mitrmkar 1,056 Posting Virtuoso

It still gives "error...program has to close" unless I put the ios::ate back in. For some reason, that makes it stay open, but it's not printing out anything. Like the vector is empty.

Didn't your compiler complain about the following line?

for (iter == data.begin(); iter != data.end(); ++iter)
// it should be ...
for (iter = data.begin(); iter != data.end(); ++iter)

Since you opened with ios::ate , the vector ended up empty because there was nothing to read in the first place. And the iterator being a global variable was initialized to NULL, so the for() loop was skipped altogether (i.e. iter was initially equal to data.end() ).

mitrmkar 1,056 Posting Virtuoso

I've changed the whole functions in LinkList class and Node Class to take this kind of parameter (const string &x)

and I ended up with two error messages from the compiler *they're the same*
: error C2678: binary '=' : no operator defined which takes a left-hand operand of type 'const class std::basic_string<char,struct std::char_traits<char>,cla

!!! what should I do?

For example the remove() function cannot be passed in a [B]const [/B]string & , because the function modifies the argument. So you need to have ... bool remove ( std::string & x );

Q8iEnG commented: Perfect member :) +1
mitrmkar 1,056 Posting Virtuoso

for (const string &x)
should I change the type of the parameters of the whole functions under LinkList to take (const string &x)?

Use [B]const [/B]string & with any function that will not modify the argument it receives, e.g. the Node class's constructor and the insert() function.

Why we did pass it as a reference?

To avoid temporary string objects from being generated.

because I don't want the original data in the file to be changed!

Assuming you have the following constructor Node ( [B]const [/B]std::string [B]&[/B] x ); The following insert() works without changing x

bool insert ( [B]const[/B] std::string & x )
{
    // x comes in as const and hence its value
    // cannot be changed in this function

    if ( !(tmp= new Node(x) ) )
        return false;

    count++;

    if ( !head )
    {
        head = last = tmp;
        return true;

    }

    last -> link = tmp;
    last = tmp;
    tmp = NULL;
    return true;

} // end function insert
mitrmkar 1,056 Posting Virtuoso

do you advice me to use what you said insert( const char * lib ) ???

Not anymore. You might change the type of the data member from char to std::string .
And make the necessary (similar) changes throughout the LinkList and Node classes.

The insert() function, for example, would change to LinkList::insert( const std::string & x ); And you would use it ...

while( getline( fin, lib, '\n' ) )
{
    game.insert( lib );
    cout << lib;
}

And the Node class would look like ...

// Begin Class Node
class Node
{
public:
    std::string data;
    Node *link;

    Node ( const std::string & x )
    {
        data = x;
        link = NULL;

    } // end constructor for class Node

}; // end class Node
mitrmkar 1,056 Posting Virtuoso

If you have LinkList::insert( const char * lib ); You have to use it with std::string like

while( getline( fin, lib, '\n' ) )
{
    game.insert( lib.c_str() ); // <- passes the data as const char *
    cout << lib;
}

Whether it really works as intended depends on what the insert() function actually does.

mitrmkar 1,056 Posting Virtuoso

This can be dangerous, if OnOK() and OnCancel() do different things...

It was sort of assumed that there is only one button and its handler, only the caption changes and the program is aware of the 'state'.

mitrmkar 1,056 Posting Virtuoso

(maybe just change the caption of the button? I guess)

Use
SetWindowText()