Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- typedef char mystring[30];
- struct date
- {
- int m, d, y;
- };
- struct Entry
- {
- mystring name, address, cellno, email;
- struct date bday;
- } contact;
- void display(struct Entry e)
- {
- cout << "\nName : " <<e.name << "\n";
- cout << "Address : " << e.address << "\n";
- cout << "Cell No : " << e.cellno << "\n";
- cout << "Email : " << e.email << "\n";
- cout << "Birthday : " << e.bday.m <<"/" << e.bday.d
- << "/" << e.bday.y << "\n";
- cout << "Age : " << (2020-e.bday.y) << "\n";
- }
- void saveContact(struct Entry e)
- {
- // FILE *fp = fopen("AMIGO.CSV", "w");
- ofstream outf;
- outf.open("amigo.csv", ios::out | ios::app );
- outf << e.name <<","
- << e.address << ","
- << e.cellno << ","
- << e.email << ","
- << e.bday.m <<"/" << e.bday.d << "/" << e.bday.y
- << endl;
- outf.close();
- cout << "Save successful.";
- }
- int main(int argc, char** argv) {
- cout << "Welcome to my Phonebook: \n";
- cout << "Enter the following information:\n ";
- cout << "\tName : ";
- cin.getline(contact.name,30);
- cout << "\tAddress : ";
- cin.getline(contact.address,30);
- cout << "\tCell No. : ";
- cin.getline(contact.cellno,30);
- cout << "\tEmail : ";
- cin.getline(contact.email,30);
- cout << "\tBirthday : ";
- cin >> contact.bday.m >>
- contact.bday.d >>
- contact.bday.y;
- display(contact);
- saveContact(contact);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement