Question: / / * * * * * * * * * * * * * * * * * * * * * * *

//*****************************************************************************************************
//
// File: NameReport.cpp
//
// Student: Benjamin Russell
//
// Assignment: Program #9
//
// Course Name: Programming II
//
// Course Number: COSC 1560
//
// Due: November 10,2024
//
//
// Description:
//
// Other files required:
//1. names.txt
//
//*****************************************************************************************************
#include
#include
#include
using namespace std;
//*****************************************************************************************************
void handleMenu(ifstream& fin);
void displayFirstFive(ifstream& fin);
void displayLastFive(ifstream& fin);
int count(ifstream& fin);
void addNewNames();
//*****************************************************************************************************
enum MENU
{
FIRSTFIVE,
LASTFIVE,
COUNT,
ADDNEW,
QUIT
};
//*****************************************************************************************************
int main()
{
ifstream file("names.txt");
if (file.fail())
{
cout << "Cannot open names.txt"<< endl;
}
cout
<<"*********************************************
"<<
"1. Display first five names
"<<
"2. Display last five names
"<<
"3. Count the number of names
"<<
"4. Add a new name
"<<
"5. Quit
"<<
"*********************************************
";
handleMenu(file);
file.close();
return 0;
}
//*****************************************************************************************************
void handleMenu(ifstream& fin)
{
int choice;
choice =-1;
while (choice != QUIT)
{
cout << "Enter a choice: ";
cin >> choice;
if (choice == FIRSTFIVE)
{
displayFirstFive(fin);
}
else if (choice == LASTFIVE)
{
displayLastFive(fin);
}
else if (choice == COUNT)
{
cout << "There are "<< count(fin)<<" names";
}
else if (choice == ADDNEW)
{
addNewNames();
}
else if (choice == QUIT)
{
cout << "QUIT";
}
else
{
cout << "Invalid Choice";
}
}
}
//*****************************************************************************************************
void displayFirstFive(ifstream& fin)
{
fin.clear();
fin.seekg(0L, ios::beg);
char name[100];
int lineCount =0;
while (lineCount <5 && fin.getline(name,100))
{
cout <<(lineCount +1)<<"."<< name << endl;
lineCount++;
}
}
//*****************************************************************************************************
void displayLastFive(ifstream& fin)
{
fin.clear();
fin.seekg(0L, ios::beg);
char name[100];
int totalCount = count(fin

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!