I have written a program that requires entering 3 first and last names and generates a file entitled, "ACL.txt" (Screenshot Below). Now I need a program that goes and searches the names I have typed in the "ACL.txt" file. For the program, the instructions are: A. First, read the names from the “ACL.txt” file. B. Next, create a loop to do the following: i. Query the user to enter a name. ii. Search the 3 names for the first and last name that the user entered. iii. If the user’s name is found in the “ACL.txt” file, 1. Display, “ACCESS GRANTED…! On the screen. iv. Else 1. Display “ACCESS DENIED…!” On the screen. v. Ask the user if he/she would like to search for another name in the “ACL.txt”. vi. If the user enters ‘Y’, 1. Go back to the top of the loop. vii. Else 1. Exit program

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I have written a program that requires entering 3 first and last names and generates a file entitled, "ACL.txt" (Screenshot Below).

Now I need a program that goes and searches the names I have typed in the "ACL.txt" file.

For the program, the instructions are:

A. First, read the names from the “ACL.txt” file.
B. Next, create a loop to do the following:
i. Query the user to enter a name.
ii. Search the 3 names for the first and last name that the user entered.
iii. If the user’s name is found in the “ACL.txt” file,


1. Display, “ACCESS GRANTED…! On the screen.
iv. Else
1. Display “ACCESS DENIED…!” On the screen.
v. Ask the user if he/she would like to search for another name in the “ACL.txt”.
vi. If the user enters ‘Y’,
1. Go back to the top of the loop.
vii. Else
1. Exit program.

**C++ Program to Write Names to a File**

This example demonstrates how to write names to a file using a C++ program. The program allows the user to input a set number of names, which are then stored in a file named "ACL.txt".

### C++ Code

```cpp
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

const int MAX_NAMES_IN_ACL = 3;

int main()
{
    string asACLNames[MAX_NAMES_IN_ACL];
    string strACLFileName = "ACL.txt";
    ofstream ptrACL(strACLFileName);
    
    for (int i = 0; i < MAX_NAMES_IN_ACL; i++)
    {
        cout << "Enter ACL name #" << i + 1 << ": ";
        getline(cin, asACLNames[i]);
        cout << endl;
    }

    if (ptrACL.is_open())
    {
        for (int i = 0; i < MAX_NAMES_IN_ACL; i++)
            ptrACL << asACLNames[i] << endl;
        
        ptrACL.close();
        cout << "ACL entries successfully written to file: " << strACLFileName << "." << endl;
    }
    else
    {
        cout << "\n\nUnable to open file: " << strACLFileName << "\n\n";
    }

    return 0;
}
```

### Explanation

1. **Includes and Namespace**: 
   - `#include <iostream>`, `#include <fstream>`, `#include <string>`: These header files are included to facilitate input-output operations and string handling.
   - `using namespace std;`: Allows usage of standard library classes and functions without the `std::` prefix.

2. **Constants and Variables**:
   - `const int MAX_NAMES_IN_ACL = 3;`: Declares a constant for the maximum number of names.
   - `string asACLNames[MAX_NAMES_IN_ACL];`: Declares an array to hold the names.
   - `string strACLFileName = "ACL.txt";`: Specifies the file name.

3. **Main Function**:
   - Collects names from the user and stores them in the `asACLNames` array.
   - Opens the file "ACL.txt" for writing.
   - Writes each collected name into the file if the file is successfully opened.
   - Closes the file and outputs a success message
Transcribed Image Text:**C++ Program to Write Names to a File** This example demonstrates how to write names to a file using a C++ program. The program allows the user to input a set number of names, which are then stored in a file named "ACL.txt". ### C++ Code ```cpp #include <iostream> #include <fstream> #include <string> using namespace std; const int MAX_NAMES_IN_ACL = 3; int main() { string asACLNames[MAX_NAMES_IN_ACL]; string strACLFileName = "ACL.txt"; ofstream ptrACL(strACLFileName); for (int i = 0; i < MAX_NAMES_IN_ACL; i++) { cout << "Enter ACL name #" << i + 1 << ": "; getline(cin, asACLNames[i]); cout << endl; } if (ptrACL.is_open()) { for (int i = 0; i < MAX_NAMES_IN_ACL; i++) ptrACL << asACLNames[i] << endl; ptrACL.close(); cout << "ACL entries successfully written to file: " << strACLFileName << "." << endl; } else { cout << "\n\nUnable to open file: " << strACLFileName << "\n\n"; } return 0; } ``` ### Explanation 1. **Includes and Namespace**: - `#include <iostream>`, `#include <fstream>`, `#include <string>`: These header files are included to facilitate input-output operations and string handling. - `using namespace std;`: Allows usage of standard library classes and functions without the `std::` prefix. 2. **Constants and Variables**: - `const int MAX_NAMES_IN_ACL = 3;`: Declares a constant for the maximum number of names. - `string asACLNames[MAX_NAMES_IN_ACL];`: Declares an array to hold the names. - `string strACLFileName = "ACL.txt";`: Specifies the file name. 3. **Main Function**: - Collects names from the user and stores them in the `asACLNames` array. - Opens the file "ACL.txt" for writing. - Writes each collected name into the file if the file is successfully opened. - Closes the file and outputs a success message
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Stack operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education