Greeting,
Here is my code...
The question is that inStream has already been opened as a connection to an input file (data.dat) that contains the following data:
1 -2 3
4 -5 6
7 -8 9
and the the following declarations are in effect
int n1, n2, n3;
double r1, r2, r3;
char
c1, c2, c3,c4;
Code:
#include <iostream> //cin,cout,<<,>>
#include <fstream> //ifstream,ofstream
#include <string> //string, getline()
#include <cassert> //assert()
using namespace std;
int n1, n2, n3;
double r1, r2, r3;
char c1, c2, c3, c4;
int main()
{
cout << "This program computes values assigned to each of the variables \n"
<< "in the input list and places its results in another file.\n\n";
// ------------------input section--------------------------------
cout << "Enter the name of the input file: ";
string inputFileName;
getline(cin, inputFileName); //get name of input file
ifstream inStream; //open an input stream to the input file
inStream.open(inputFileName.data()); //establish a connection
assert(inStream.is_open()); //check for success
inStream >> c1 >> n1 >> r1 >> r2
>> n2 >> c2 >> c3 >> r3; //read a value
inStream.close(); //close the connection
// ------------------------output section-------------------------
while(getchar() != '\n');
cout << "Enter the name of the output file: ";
string outputFileName;
getline(cin, outputFileName);
ofstream outStream(outputFileName.data()); //open an output stream to the output file
// and establish a connection
assert(outStream.is_open()); //check for success
outStream << c1 << n1 << r1 << r2
<< n2 << c2 << c3 << r3; //write a value
outStream.close(); //close stream
cout << "Processing complete.\n";
return 0;
}
I should get the following answers according to the book:
c1 = '1' n1 = 23, r1 = 45.6 r2 = error--real numbers cant contain letters(ie 'X')
My is 1-234-567-8, I am
Can anyone explain why the book cam up with these answers to the practice problems?