The Spring fork amateur golf club has a tournament every weekend. The club president has asked you to design a program. It contains the following menu: Select the task 1. Add new records 2. Read Records 3. End the program If the user enters 1, the program will read each players name and golf score as keyboard input, then save the records in a file names golf.dat If the user enters 2, the program reads the records from the golf.dat file and displays them. While the menu selection is not equal to 3, get the user selection. If the selection is 1, get the number of players in the tournament, open the output file. For each player, get the name and the score, and write them to the file. Close the file. If the selection is 2, open the input file, read the values from the file, display the values, close the file. If the selection is 3, exit the program. I already had a code written from before, but I'm having a hard time turning it into a menu driven code. It does need to have the function prototypes, definitions and function call. I need this in C++. Any advice would be greatly appreciated #include #include #include using namespace std; void golfPlayerDeatils(); int main() { golfPlayerDeatils(); return 0; } void golfPlayerDeatils(){ int players; int score; string name; ofstream outFile; outFile.open("golf.txt", ios::app); cout << "Enter the number of golfers competing: "; cin >> players; for(int i = 0; i < players; ++i) { cout << "Enter the name of the competitor " << (i+1) << ": "; cin >> name; cout << "Enter their score: " ; cin >> score; cout << "Golfer: " << name << " Score: " << score << endl; outFile <<"Golfer: " << name << " Score: " << score << endl; if (outFile.fail()) { cout << "Error creating file. " << endl; exit (1); } } outFile.close ();

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter5: The Repetition Structure
Section: Chapter Questions
Problem 5E
icon
Related questions
Question

The Spring fork amateur golf club has a tournament every weekend. The club president has asked you to design a program. It contains the following menu:

Select the task

1. Add new records

2. Read Records

3. End the program

If the user enters 1, the program will read each players name and golf score as keyboard input, then save the records in a file names golf.dat

If the user enters 2, the program reads the records from the golf.dat file and displays them.

While the menu selection is not equal to 3, get the user selection.

If the selection is 1, get the number of players in the tournament, open the output file. For each player, get the name and the score, and write them to the file. Close the file.

If the selection is 2, open the input file, read the values from the file, display the values, close the file.

If the selection is 3, exit the program.

I already had a code written from before, but I'm having a hard time turning it into a menu driven code. It does need to have the function prototypes, definitions and function call. I need this in C++. Any advice would be greatly appreciated

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void golfPlayerDeatils();
int main()
{
golfPlayerDeatils();
return 0;
}
void golfPlayerDeatils(){
int players;
int score;
string name;
ofstream outFile;
outFile.open("golf.txt", ios::app);
cout << "Enter the number of golfers competing: ";
cin >> players;
for(int i = 0; i < players; ++i)
{
cout << "Enter the name of the competitor " << (i+1) << ": ";
cin >> name;
cout << "Enter their score: " ;
cin >> score;
cout << "Golfer: " << name << " Score: " << score << endl;
outFile <<"Golfer: " << name << " Score: " << score << endl;
if (outFile.fail())
{
cout << "Error creating file. " << endl;
exit (1);
}
}
outFile.close ();
cout << "File is created";
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Graphical User Interface
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
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L