Sunday, July 12, 2009

Help with c++ hw?

how do i write a program that reads data from that file and stores the output in a file named “OutData.txt”. For each employee, the data must be outputted in the following form: firstName lastName updatedSalary. Format the output of floating point numbers to be always displayed using the decimal notation with two decimal places.





here is what i have s far:





#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


using namespace std;





int main()


{


ifstream input;


ofstream output;





input.open("InData.txt");


____________________________


what do i do after this point? can u please show some examples?

Help with c++ hw?
You don't say how the input data file is formatted.


Your code is good so far. Continue with:





output.open( "OutData.txt" );


output.precision( 2 );


string firstName, lastName;


double salary;


input %26gt;%26gt; firstName %26gt;%26gt; lastName %26gt;%26gt; salary;


while (!input.fail()) {


output %26lt;%26lt; firstName %26lt;%26lt; " " %26lt;%26lt; lastName;


output %26lt;%26lt; " " %26lt;%26lt; fixed %26lt;%26lt; salary %26lt;%26lt; endl;


input %26gt;%26gt; firstName %26gt;%26gt; lastName %26gt;%26gt; salary;


}





The "precision" function says you want 2 digits. The "fixed" manipulator says that you always want those digits counted from the decimal place.


No comments:

Post a Comment