1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
class President
{
private:
string first_name;
string last_name;
int begin_year;
int end_year;
string party_affil;
public:
President();
void setFirstName(string);
void setLastName(string);
void setBeginYear(int);
void setEndYear(int);
void setPartyAffil(string);
string getFirstName();
string getLastName();
int getBeginYear();
int getEndYear();
string getPartyAffil();
};
void displayPresident();
void outputPresident(fstream &outFile);
void loadData(President pres_array[], const int SIZE, int count);
void outputData(President pres_array[], int count);
int main()
{
const int SIZE = 40;
int count = 0;
President pres_array[SIZE];
loadData(pres_array, SIZE, count);
outputData(pres_array, count);
return 0;
}
//********************************************************************
void President::displayPresident()
{
cout << left;
cout << setw(15) << "First Name: "
<< first_name << endl;
cout << setw(15) << "Last Name: "
<< last_name << endl;
cout << setw(15) << "Begin Year: "
<< begin_year << endl;
cout << setw(15) << "End Year: "
<< end_year << endl;
cout << setw(15) << "Party: "
<< party_affil << endl;
cout << endl;
}
//********************************************************************
void outputPresident(fstream &outFile)
{
fstream outFile;
outFile.open("a5.txt", ios::app);
outFile << left;
outFile << setw(15) << "First Name: "
<< first_name << endl;
outFile << setw(15) << "Last Name: "
<< last_name << endl;
outFile << setw(15) << "Begin Year: "
<< begin_year << endl;
outFile << setw(15) << "End Year: "
<< end_year << endl;
outFile << setw(15) << "Party: "
<< party_affil << endl;
outFile << endl;
outFile.close();
}
//********************************************************************
void loadData(President pres_array[], const int SIZE,
int count)
{
fstream inFile;
inFile.open("prez_data", ios::in);
string first,
last,
party;
int begin,
end,
tempn;
while (!inFile.eof() && count < SIZE)
{
getline(inFile, first);
pres_array[tempn].setFirstName(first);
getline(inFile, last);
pres_array[tempn].setLastName(last);
inFile >> begin;
pres_array[tempn].setBeginYear(begin);
inFile >> end;
pres_array[tempn].setEndYear(end);
inFile.ignore();
getline(inFile, party);
pres_array[tempn].setPartyAffil(party);
tempn = pres_array;
system("pause");
++count;
}
inFile.close();
}
//**********************************************************************
void outputData(President pres_array[], int count)
{
fstream outFile;
outFile.open("a5.txt", ios::out, ios::app);
outFile << "President Listing: " << endl;
outFile << endl;
for (int i = 0; i < count; i++)
{
outFile << left;
outFile << setw(15) << "First Name: "
<< pres_array[i].getFirstName() << endl;
outFile << setw(15) << "Last Name: "
<< pres_array[i].getLastName() << endl;
outFile << setw(15) << "Begin Year: "
<< pres_array[i].getBeginYear() << endl;
outFile << setw(15) << "End Year: "
<< pres_array[i].getEndYear() << endl;
outFile << setw(15) << "Party: "
<< pres_array[i].getPartyAffil() << endl;
outFile << endl;
}
outFile.close();
}
//**********************************************************************
void President::setFirstName(string f)
{
first_name = f;
}
//**********************************************************************
void President::setLastName(string l)
{
last_name = l;
}
//**********************************************************************
void President::setBeginYear(int b)
{
begin_year = b;
}
//**********************************************************************
void President::setEndYear(int e)
{
end_year = e;
}
//**********************************************************************
void President::setPartyAffil(string p)
{
party_affil = p;
}
//**********************************************************************
string President::getFirstName()
{
return first_name;
}
//**********************************************************************
string President::getLastName()
{
return last_name;
}
//**********************************************************************
int President::getBeginYear()
{
return begin_year;
}
//**********************************************************************
int President::getEndYear()
{
return end_year;
}
//**********************************************************************
string President::getPartyAffil()
{
return party_affil;
}
//**********************************************************************
President::President()
{
first_name = "";
last_name = "";
begin_year = 0;
end_year = 0;
party_affil = "";
|