Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "myLibraryBMR.h"
- using namespace std;
- struct presidentialInfo
- {
- string firstName;
- string middleName;
- string lastName;
- int ageElected;
- string stateOfBirth;
- dateOfBirth *DOB;
- };
- struct dateOfBirth
- {
- string month;
- int day;
- int year;
- };
- int main()
- {
- string readFromFileName = "Lab4c_data.txt";
- ifstream fin;
- string strMonth[12] = { "January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December" };
- int monthNum;
- fin.open(readFromFileName);
- if (fin.fail())
- {
- cout << "\n\nError opening file " << readFromFileName << " for reading.\n\n";
- system("pause");
- return EXIT_FAILURE;
- }
- int recordSize;
- fin >> recordSize; //gets first line which relates to array size
- presidentialInfo* presidentialStats = nullptr;
- presidentialStats = new presidentialInfo[recordSize];
- string whitespace;
- getline(fin, whitespace); //gets rid of whitespace after recordSize
- for (int i = 0; i < recordSize; i++) {
- getline(fin, presidentialStats[i].firstName, ':');
- getline(fin, presidentialStats[i].middleName, ':');
- getline(fin, presidentialStats[i].lastName, ':');
- fin >> presidentialStats[i].ageElected;
- getline(fin, whitespace);
- getline(fin, presidentialStats[i].stateOfBirth, '\n');
- fin >> monthNum;
- presidentialStats[i].DOB->month = strMonth[monthNum + 1];
- fin >> presidentialStats[i].DOB->day;
- fin >> presidentialStats[i].DOB->year;
- getline(fin, whitespace);
- }
- for (int i = 0; i < recordSize; i++) {
- cout << "President Name: " << presidentialStats[i].firstName << " " << presidentialStats[i].middleName << " " << presidentialStats[i].lastName << endl;
- cout << "Age of Election: " << presidentialStats[i].ageElected << endl;
- cout << "State of Birth: " << presidentialStats[i].stateOfBirth << endl;
- cout << "Date of Birth: " << presidentialStats[i].DOB->month << " " << presidentialStats[i].DOB->day << ", " << presidentialStats[i].DOB->year << endl <<endl;
- }
- delete[] presidentialStats;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement