SHARE
TWEET

Untitled

a guest Jan 27th, 2020 110 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. typedef char mystring[30];
  7.  
  8. struct date
  9. {
  10.     int m, d, y;
  11. };
  12.  
  13.  
  14. struct Entry
  15. {
  16.     mystring name, address, cellno, email;
  17.     struct date bday;
  18. } contact;
  19.  
  20. void display(struct Entry e)
  21. {
  22.     cout << "\nName      : " <<e.name << "\n";
  23.     cout << "Address   : " << e.address << "\n";
  24.     cout << "Cell No   : " << e.cellno << "\n";
  25.     cout << "Email     : " << e.email << "\n";
  26.     cout << "Birthday  : " << e.bday.m <<"/" << e.bday.d
  27.     << "/" << e.bday.y << "\n";
  28.     cout << "Age       : " << (2020-e.bday.y) << "\n";
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35. void saveContact(struct Entry e)
  36. {
  37. //  FILE *fp = fopen("AMIGO.CSV", "w");
  38.     ofstream outf;
  39.     outf.open("amigo.csv", ios::out | ios::app );
  40.  
  41.     outf << e.name <<","
  42.        << e.address << ","
  43.        << e.cellno << ","
  44.        << e.email << ","
  45.        << e.bday.m <<"/" << e.bday.d << "/" << e.bday.y
  46.        << endl;
  47.        
  48.     outf.close();
  49.     cout << "Save successful.";
  50.    
  51. }
  52.  
  53. int main(int argc, char** argv) {
  54.    
  55.     cout << "Welcome to my Phonebook: \n";
  56.     cout << "Enter the following information:\n ";
  57.     cout << "\tName         : ";
  58.     cin.getline(contact.name,30);
  59.     cout << "\tAddress      : ";
  60.     cin.getline(contact.address,30);
  61.     cout << "\tCell No.     : ";
  62.     cin.getline(contact.cellno,30);
  63.     cout << "\tEmail        : ";
  64.     cin.getline(contact.email,30);
  65.  
  66.     cout << "\tBirthday     : ";
  67.     cin >>  contact.bday.m >>
  68.             contact.bday.d >>
  69.             contact.bday.y;
  70.    
  71.     display(contact);
  72.     saveContact(contact);
  73.    
  74.     return 0;
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top