//------------------------------------------------- // // A program to get patient data from the user and // create a file using it. // // Simon Parsons // 23rd February 2007 // //------------------------------------------------- #include #include using namespace std; //------------------------------------------------ // // The main method int main() { // Initialisation int idNumber; // Declare variables int age; int disease; int zipCode; ofstream outfile; // Set up output stream outfile.open("patient.dat"); // Open file // Get first patient ID cout << "Enter patient id, or -1 to end " cin >> idNumber; // Now read in patient data and send it to a file. while(idNumber >= 0) // As long as we don't { // give a negative ID cout << "Patient age "; // read in patient data cin >> age; cout << "ZIP code "; cin >> zipCode; cout << "Disease "; cin >> disease; outfile << idNumber; // Write data to file outfile << age; outfile << disease; outfile << zipCode; // Enter ID again cout << "Enter patient id, or -1 to end "; cin >> idNumber; } // Tidy up outfile.close(); // Close file return 0; }