#include <iostream> using namespace std; #include <fstream> #include <cstdlib> #
ID: 3528802 • Letter: #
Question
#include <iostream>
using namespace std;
#include <fstream>
#include <cstdlib>
#include <string>
struct person
{
string first, last;
int score;
};
int main()
{
ifstream data1, data2;
data1.open("data1.txt"); // opens the file
if(!data1) // file couldn't be opened
{
cerr << "Error: data1 could not be opened" << endl;
exit(1);
}
data2.open("data2.txt"); // opens the file
if(!data2) // file couldn't be opened
{
cerr << "Error: data2 could not be opened" << endl;
exit(2);
}
person rec1;
data1 >> rec1.last >> rec1.first >> rec1.score;
while (!data1.eof())
{
cout << rec1.last << ", " << rec1.first << " " << rec1.score << endl;
data1 >> rec1.last >> rec1.first >> rec1.score;
}
person rec2;
data2 >> rec2.last >> rec2.first >> rec2.score;
while (!data2.eof())
{
cout << rec2.last << ", " << rec2.first << " " << rec2.score << endl;
data2 >> rec2.last >> rec2.first >> rec2.score;
}
data1.close();
data2.close();
system("pause");
return 0;
}
Explanation / Answer
#include #include #include struct person { string first, last; int score; }; int main() { ifstream data1, data2; data1.open("data1.txt"); if(!data1) { cerrRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.