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

MENU LAB The idea is to manage multiple lists of names stored on the disk. You c

ID: 3566114 • Letter: M

Question

MENU LAB

The idea is to manage multiple lists of names stored on the disk. You can display and append any list of names stored from a main menu.

Main Menu:

The program will display 'invalid option' if something not on the menu is selected.

If a valid option is selected, the program will do that option,

The program will continue to ask for choices until 'Exit' is selected, then the program will end.

If you ask for numbers as the options, I will only type in numbers. (cin >> nuInteger; has issues with letters, but that's not out problem)

Show a list


When this option is selected the program will prompt for a file name. The program will then open the file and display the contents of that file. You may assume that only text files will be displayed.

Add a name to a list


When this option is selected the program will prompt for a file name AND then prompt for a name. Names always contain an unknown amount of spaces, (see getline).

Exit

When this option is pressed, the program ends. It should not end for any other reason. (Of course you can't control closing the window and things like that)

[optional, Extra Credit] Show all the lists.


When this option is pressed, you can display the contents of the directory with all files ending in .txt and .list

This option is system specific, windows stuff won't work on linux, apple stuff wont work on wondows, etc. Just put in the message area if you did this and what system you're using and I'll deal with it accordingly.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
using namespace std;

void show() // this function displays the file content
{ string file_nm;
cout<<"Enter file name";
cin>>file_nm;
string STRING;
ifstream infile;
if (file.good())
{ infile.open ("file_nm");
while(!infile.eof) // To get you all the lines.
{
   getline(infile,STRING); // Saves the line in STRING.
   cout<<STRING; // Prints our STRING.
}
infile.close();
}
else { cout<< "File doesnot exit"; }
getch();
}


void add() // Appends to the end of the file
{
string txt, file_nm;
cout<<"Enter file name";
cin>> file_nm;
cout<<"enter text to be added";
cin>> txt;
std::ofstream outfile;
outfile.open(file_nm, std::ios_base::app);
outfile <<ENTRY;
}

/***************************************MAIN PROGRAM************************************************/
int main()
{ int l;
while(1)
{
cout<<"Main menu 1) Show a list 2) Add a name 3) exit ";
switch(l)
{
case 1: show(); continue;
case 2: add(); continue;
case 3: exit(1);
default: cout<<"Invalid option";
}

}

return 0;
}

/****If you want the extra credit file list option just message me on facebook.com/arjunishere*******/