|
|
|
|
|
|
#include <iostream> #include <fstream> using namespace std; class DATA { private: int key; string firstName; string lastName; float GPA; public: friend ifstream &operator >>(ifstream & ,DATA &); friend ostream &operator <<(ostream &,DATA); int getkey() { return key; }; }; ifstream &operator >>(ifstream &in,DATA &d) { int KEY; string FIRST, LAST; float gpa; if( in >> KEY >> FIRST >> LAST >> gpa ) { d.key = KEY; d.firstName = FIRST; d.lastName = LAST; d.GPA = gpa; } return in; } ostream &operator <<(ostream &out,DATA d) { out << d.key << " " << d.firstName << " " << d.lastName << " " << d.GPA; return out; } class List { private: DATA **p; int y; public: List(); void insertDATA (DATA); DATA getDATA(DATA); }; DATA List::getDATA(DATA d) { for (int y = 0; y < 3; y++) { d = *p[y]; } return d; } void List::insertDATA(DATA d) { int i = 0; if (i < 10) { p[i] = new DATA(d); i++; } } List::List(void) { p = new DATA*[10]; } int main(int argc,char *argv[]) { DATA d; List list; char option; if (argc == 3) { ifstream in; in.open(argv[1]); while (in >> d) { list.insertDATA(d); } cout << list.getDATA(d) << "\n"; ofstream out; out.open(argv[2]); } else { cout << "can't open input file and output file: put input file name then follow by output file name"; } } |