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 ();

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

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.
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