| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include <cstdlib>
- #include <fstream>
- #include <string>
- #include <cstdio>
- #include <iostream>
- #include "Address.h"
- #include "Date.h"
- #include "Student.h"
- using namespace std;
- const int NUM_STUDENTS = 50;
- int main(){
- // create arrays to store info
- Address * addresses[NUM_STUDENTS];
- Date * birthdays[NUM_STUDENTS];
- Date * graddays[NUM_STUDENTS];
- Student * students[NUM_STUDENTS];
- string names[NUM_STUDENTS];
-
- // create objects to read and write files
- ifstream fin ("students.dat");
- ofstream fullReport ("fullReport.txt");
- ofstream shortReport ("shortReport.txt");
- ofstream alphaReport ("alphaReport.txt");
- // create strings for everything and read the first line
- string lname = ""; getline(fin, lname, ',');
- string fname = ""; getline(fin, fname, ',');
- string line1 = ""; getline(fin, line1, ',');
- string line2 = ""; getline(fin, line2, ',');
- string city = ""; getline(fin, city, ',');
- string state = ""; getline(fin, state, ',');
- string zip = ""; getline(fin, zip, ',');
- string birthday = ""; getline(fin, birthday, ',');
- string gradday = ""; getline(fin, gradday, ',');
- string gpa = ""; getline(fin, gpa, ',');
- string credits = ""; getline(fin, credits);
-
- int i, j = 0;
- // for each student...
- for(i = 0; i < NUM_STUDENTS; i++){
- // ... read the information, ...
- getline(fin, lname, ',');
- getline(fin, fname, ',');
- getline(fin, line1, ',');
- getline(fin, line2, ',');
- getline(fin, city, ',');
- getline(fin, state, ',');
- getline(fin, zip, ',');
- getline(fin, birthday, ',');
- getline(fin, gradday, ',');
- getline(fin, gpa, ',');
- getline(fin, credits);
-
- // ... create objects with the information, ...
- addresses[i] = new Address(line1, line2, city, state, zip);
- birthdays[i] = new Date(birthday);
- graddays[i] = new Date(gradday);
- students[i] = new Student(fname, lname, birthdays[i],
- graddays[i], addresses[i], gpa, credits);
- names[i] = students[i]->getLname() + "," + students[i]->getFname();
-
- // ... write the information full report, ...
- fullReport << students[i]->getLname() << ","
- << students[i]->getFname() << ","
- << students[i]->getAddress().getLine1() << ","
- << students[i]->getAddress().getLine2() << ","
- << students[i]->getAddress().getCity() << ","
- << students[i]->getAddress().getState() << ","
- << students[i]->getAddress().getZip() << ","
- << students[i]->getBirthday().getDate() << ","
- << students[i]->getGradday().getDate() << ","
- << students[i]->getGpa() << ","
- << students[i]->getCredits() << endl;
-
- // ... and write the short report.
- shortReport << students[i]->getLname() << ","
- << students[i]->getFname() << endl;
- }
-
- // bubble sort
- string hold = ""; // temporary variable
- for(i = 0; i < NUM_STUDENTS - 1; i++){
- for(j = 0; j < NUM_STUDENTS - 1; j++){
- if(names[j].compare(names[j + 1]) > 0){
- hold = names[j];
- names[j] = names[j + 1];
- names[j + 1] = hold;
- }
- }
- }
-
- for(i = 0; i < NUM_STUDENTS; i++){
- alphaReport << names[i] << endl; // write the alphabetical report
- delete addresses[i]; // free memory
- delete birthdays[i]; // free memory
- delete graddays[i]; // free memory
- delete students[i]; // free memory
- }
-
- // close file streams
- fin.close();
- fullReport.close();
- shortReport.close();
- alphaReport.close();
- }
|