Sunday, July 12, 2009

C++ Programming Help?

What expressions would I need to write to complete the following program?





1. Includes %26lt;fstream%26gt; and other required header files.


2. Declares a file variable named inFile of type ifstream.


3. Declares two variables named number1 and number2 that hold whole numbers.


4. Declares a variable named name that holds a string of characters.


5. Opens the input file indata.txt.


6. Checks if the file was opened. If not, it prints the message “Could not open file!” and stops the program.


7. Reads from the file a name and stores it in name.


8. Reads from the file two numbers and stores them in number1 and number2 respectively.


9. Prints on the screen “Hello “ followed by name.


10. If number1 is greater than number2

C++ Programming Help?
#include %26lt;iostream%26gt;


#include %26lt;fstream%26gt;


#include %26lt;string%26gt;





using namespace std;





int main(void)


{


ifstream inFile;


int number1 = 0;


int number2 = 0;


string name;





// open file


inFile.open("indata.txt");





// check for failures


if (inFile.fail())


{


cout %26lt;%26lt; "Could not open file!" %26lt;%26lt; endl;


return 0;


}





// read the data from file


inFile %26gt;%26gt; name;


inFile %26gt;%26gt; number1;


inFile %26gt;%26gt; number2;


inFile.close(); // we're done with the file so close it





// print


if (number1 %26gt; number2)


cout %26lt;%26lt; "Hello " %26lt;%26lt; name %26lt;%26lt; endl;





return 0;


}

flower girl dresses

No comments:

Post a Comment