// creating a file total for storingthe total sum of numbers
ofstream out_total("total.txt");
out_total << total << endl;
out_total.close();
// reading the file and outputing it on the screen
ifstream in_total;
in_total.open("total.txt");
cout << "All three Files are created!\n";
in_total >> total;
cout << "TOTAL: " << total << "\n\n"; // displaying the total in console
in_total.close(); // closing the file after executing
}
voidF_Second_Program(){
for (int k = 0; k < 1000; k++) {
system("cls");
cout << "C O N T A C T S\n" << "------------------\n" << "1. Add a contact\n" << "2. Contacts\n" << "0. Back\n" << "Your choice: \n";
ofstream out_contacts("contacts.txt", ios::app);
string name, phone;
switch (_getch())
{
// case 49 is for adding a new contact into a list
case49: {
system("cls");
cout << "Adding a new contact. Input a contact info:\n\n";
cout << "Enter the name: "; cin >> name;
cout << "Enter the phone number: "; cin >> phone;
// storing the data in file
out_contacts << left << setw (12) << name << "\t" << phone << "\n";
out_contacts.close(); //closing the file
cout << "Successfully added!\n\n";
system("pause");
}
break;
case50: {
system("cls");
ifstream in_contacts("contacts.txt"); // getting data from the file
while (in_contacts >> name >> phone) {
// displaying the data
cout << left << setw(12) << name << "\t" << phone << endl;
}
in_contacts.close(); // closing the file
system("pause");
}
break;
case48: {
main(); // to back to main menu
}
break;
default: {
cout << "Your choice is not available in Menu.\nPlease try one more time\n";
system("pause");
}
break;
} // switch
} // for loop
}
voidF_Third_Program(){
for (int k = 0; k < 1000; k++) {
system("cls");
cout << "S E A R C H I N G F O R N U M B E R \n" << "------------------------------------\n" << "1. Add numbers\n" << "2. Search for number\n" << "0. Back\n" << "Your choice: \n";
ofstream out_numbers("numbers.txt", ios::app); // the list could be contiunied after the program execution
int numbers;
switch (_getch())
{
case49: {
system("cls");
cout << "ENYER NUMBERS\n";
// inputing numbers
for (int i = 1; i <= 20; i++) {
cout << "[ " << i << " ] -> "; cin >> numbers;
out_numbers << numbers << endl;
}
out_numbers.close(); //closing the file
system("pause");
}
break;
case50: {
system("cls");
ifstream in_numbers("numbers.txt");
cout << "SEARCHING A NUMBER\n";
int search_number;
bool isAnswerHere = 0; // for finding the searching number from available list
cout << "Enter the number to search: ";
cin >> search_number;
while (in_numbers) {
in_numbers >> numbers;
if (search_number == numbers)
isAnswerHere = 1;
} // while loop
if (isAnswerHere == 1)
cout << "\nThe number is available in list.\n\n";
else
cout << "\nThe number is NOT in list\n\n";
system("pause");
}
break;
case48: {
main();
}
break;
default: {
cout << "Your choice is not available in Menu.\nPlease try one more time\n";
system("pause");
}
break;
} // switch
} // for loop
}
intmain(){
for (int k = 0; k < 1000; k++) {
system("cls");
cout << "M A I N M E N U\n"<< "-------------------\n" << "1. First Program\n" << "2. Second Program\n" << "3. Third Program\n" << "Your choice: \n";
switch (_getch())
{
case49:
system("cls");
F_First_Program();
system("pause");
break;
case50:
system("cls");
F_Second_Program();
system("pause");
break;
case51:
system("cls");
F_Third_Program();
system("pause");
break;
case48:
return0;
break;
default:
cout << "Your choice is not available in Menu.\nPlease try one more time\n";