Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

luonline.blackboard.com 1-Intro Computers. https:/luonline.blackboard.com/bbcswe

ID: 3764867 • Letter: L

Question


luonline.blackboard.com 1-Intro Computers. https:/luonline.blackboard.com/bbcswebdav/pid-190591 ELEN 1301-01 Due date: Please Hand in: Programming Assignment #12 (10 pts) November 23, Monday (At the beginning of the class.) 1. Printout of your C++ program with a heading comment (Do not forget to add comments within your program). You must use both input and output files in order to receive any credit. 2. Printout of an output file, and screenshot (start with your name) 3. If your name is not in the input file, modify the file manually so that your name is included. LN 1301-01Png A 6 points) (4 points) Programming Assignment #12 Name Student ID Due date : Your name Your student ID# :November 23, 2015 objective of this assignment Read the input file information as a name 1ist. Compare the entered name with the names in the list. step 1. Open an input and an output file. Step 2 Read contents (26 names) from the input file. (input12.txt) Step 3. Receive a name from a user and compare it to the names in the list. Show the index number if the name is found in the list. If not found, state that. (See the output example below Step 4 Repeat step 3 until the user decides to quit by typing "quit. Step 5. Record the entire session to the output file Step 6. Close both input and output files.

Explanation / Answer

Answer:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

string user;


int Check (string user)
{
ifstream file;
string username;
int n=0;
file.open("output12.txt");
if (file.is_open())
{
while (!file.eof())
{
file >> username ;
n++;
if (user==username)
cout<<"User Exists Already"<<endl;
return n;
}
}
else
{
cout << "file not open" << endl;
}
return 0;
}


int main()
{
int c=0;
ifstream userfile;
userfile.open("output12.txt");
string userset;
if (!userfile.is_open())
{
cout << "file not found" << endl;
}
else
{
cout << "1.Login"<<endl;
int option;
cin >> option;
if (option==1)
{
while (Check(user)==0)
{
c++;
cout << "Username: ";
cin >> user;
  
  
if (Check(user)!=0)
cout << "Welcome " << user << "." << endl;
else if (c==3)
{
cout << "User Already exists"<<endl;
break;
}
else
{
cout << "Invalid username/password combination" << endl;
}
}
userfile.close();
}

}
int k;
cin >> k;
return 0;
}