-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab1Review.cpp
More file actions
59 lines (49 loc) · 1.44 KB
/
Copy pathLab1Review.cpp
File metadata and controls
59 lines (49 loc) · 1.44 KB
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
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cstdio> // for printf
using namespace std;
// Person struct definition
struct Person {
string ssnLast4;
string firstName;
string lastName;
string email;
};
// Function to read person data from file
vector<Person> readPerson(ifstream& inFile) {
vector<Person> people;
Person tempPerson;
while (inFile >> tempPerson.ssnLast4 >> tempPerson.firstName
>> tempPerson.lastName >> tempPerson.email) {
people.push_back(tempPerson);
}
return people;
}
int main() {
// Open the input file stream
ifstream inFile("persons.txt");
if (!inFile) {
cerr << "Error opening file." << endl;
return 1;
}
// Read person data into a vector
vector<Person> people = readPerson(inFile);
inFile.close();
// Loop through and print each person
for (const Person& p : people) {
// Convert first and last names to uppercase for output
string upperLast = p.lastName;
string upperFirst = p.firstName;
for (char& c : upperLast) c = toupper(c);
for (char& c : upperFirst) c = toupper(c);
// Print in required format using printf
printf("%s, %s:%s:%s\n",
upperLast.c_str(),
upperFirst.c_str(),
p.ssnLast4.c_str(),
p.email.c_str());
}
return 0;
}