Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include "myLibraryBMR.h"
  2.  
  3. using namespace std;
  4.  
  5. struct presidentialInfo
  6. {
  7.     string firstName;
  8.     string middleName;
  9.     string lastName;
  10.     int ageElected;
  11.     string stateOfBirth;
  12.     dateOfBirth *DOB;
  13.    
  14. };
  15.  
  16. struct dateOfBirth
  17. {
  18.     string month;
  19.     int day;
  20.     int year;
  21. };
  22.  
  23. int main()
  24. {
  25.     string readFromFileName = "Lab4c_data.txt";
  26.     ifstream fin;
  27.  
  28.     string strMonth[12] = { "January", "February", "March", "April", "May", "June", "July",
  29.     "August", "September", "October", "November", "December" };
  30.     int monthNum;
  31.  
  32.     fin.open(readFromFileName);
  33.     if (fin.fail())
  34.     {
  35.         cout << "\n\nError opening file " << readFromFileName << " for reading.\n\n";
  36.         system("pause");
  37.         return EXIT_FAILURE;
  38.     }
  39.     int recordSize;
  40.     fin >> recordSize; //gets first line which relates to array size
  41.  
  42.     presidentialInfo* presidentialStats = nullptr;
  43.    
  44.  
  45.     presidentialStats = new presidentialInfo[recordSize];
  46.  
  47.  
  48.     string whitespace;
  49.     getline(fin, whitespace); //gets rid of whitespace after recordSize
  50.  
  51.  
  52.     for (int i = 0; i < recordSize; i++) {
  53.  
  54.         getline(fin, presidentialStats[i].firstName, ':');
  55.         getline(fin, presidentialStats[i].middleName, ':');
  56.         getline(fin, presidentialStats[i].lastName, ':');
  57.         fin >> presidentialStats[i].ageElected;
  58.         getline(fin, whitespace);
  59.         getline(fin, presidentialStats[i].stateOfBirth, '\n');
  60.         fin >> monthNum;
  61.         presidentialStats[i].DOB->month = strMonth[monthNum + 1];
  62.         fin >> presidentialStats[i].DOB->day;
  63.         fin >> presidentialStats[i].DOB->year;
  64.         getline(fin, whitespace);
  65.     }
  66.  
  67.     for (int i = 0; i < recordSize; i++) {
  68.         cout << "President Name: " << presidentialStats[i].firstName << " " << presidentialStats[i].middleName << " " << presidentialStats[i].lastName << endl;
  69.         cout << "Age of Election: " << presidentialStats[i].ageElected << endl;
  70.         cout << "State of Birth: " << presidentialStats[i].stateOfBirth << endl;
  71.         cout << "Date of Birth: " << presidentialStats[i].DOB->month << " " << presidentialStats[i].DOB->day << ", " << presidentialStats[i].DOB->year << endl <<endl;
  72.     }
  73.  
  74.     delete[] presidentialStats;
  75.  
  76.     system("pause");
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement