-
Notifications
You must be signed in to change notification settings - Fork 7
/
mailing_addresses.cpp
70 lines (61 loc) · 1.34 KB
/
mailing_addresses.cpp
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
/*
File name: mailing_addresses.cpp
Date: 13 Jan 2017
Author: Andrew Roberts
*/
#include <iostream>
#include <fstream>
using namespace std;
//create a new datatype for holding addresses
struct Address
{
string fullName;
char houseNum[5];
char streetName[30];
char city[30];
char state[3];
int zipcode;
};
void writeToFile(Address m[], int size);
int main()
{
int numees;
string fullname;
string fname, lname;
cout<<"How many employees do you have? \n";
cin>>numees;
Address mailing[numees];
for(int i = 0;i < numees;i++)
{
cout<<"Please enter first name: \n";
cin>>fname;
cout<<"Enter last name: \n";
cin>>lname;
fullname = fname + " " + lname;
mailing[i].fullName = fullname;
cout<<"Enter house number: \n";
cin>>mailing[i].houseNum;
cin.ignore();
cout<<"Enter street name: \n";
cin.getline(mailing[i].streetName, 30);
cout<<"Enter city: \n";
cin>>mailing[i].city;
cout<<"Enter state: \n";
cin>>mailing[i].state;
cout<<"Enter zipcode: \n";
cin>>mailing[i].zipcode;
}
writeToFile(mailing,numees);
}
void writeToFile(Address m[], int size)
{
ofstream output;
output.open("mailingaddress.txt", ios::out);
for(int i = 0; i < size; i++)
{
output<<m[i].fullName<<endl;
output<<m[i].houseNum<<" "<<m[i].streetName<<endl;
output<<m[i].city<<", "<<m[i].state<<" " <<m[i].zipcode<<endl;
output<<endl;
}
}