MCPcopy Create free account
hub / github.com/Rustam-Z/cpp-programming / F_Second_Program

Function F_Second_Program

Lab_19/main.cpp:74–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void F_Second_Program()
75{
76
77 for (int k = 0; k < 1000; k++)
78 {
79 system("cls");
80 cout << "C O N T A C T S\n"
81 << "------------------\n"
82 << "1. Add a contact\n"
83 << "2. Contacts\n"
84 << "0. Back\n"
85 << "Your choice: \n";
86
87 ofstream out_contacts("contacts.txt", ios::app);
88
89 string name, phone;
90
91 switch (_getch())
92 {
93 // case 49 is for adding a new contact into a list
94 case 49:
95 {
96 system("cls");
97 cout << "Adding a new contact. Input a contact info:\n\n";
98
99 cout << "Enter the name: ";
100 cin >> name;
101 cout << "Enter the phone number: ";
102 cin >> phone;
103
104 // storing the data in file
105 out_contacts << left << setw(12) << name << "\t" << phone << "\n";
106 out_contacts.close(); // closing the file
107
108 cout << "Successfully added!\n\n";
109
110 system("pause");
111 }
112 break;
113
114 case 50:
115 {
116 system("cls");
117 ifstream in_contacts("contacts.txt"); // getting data from the file
118 while (in_contacts >> name >> phone)
119 {
120 // displaying the data
121 cout << left << setw(12) << name << "\t" << phone << endl;
122 }
123 in_contacts.close(); // closing the file
124 system("pause");
125 }
126 break;
127
128 case 48:
129 {
130 main(); // to back to main menu
131 }

Callers 1

mainFunction · 0.70

Calls 1

mainFunction · 0.70

Tested by

no test coverage detected