Question

C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position p...

C++ Language

Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position played, and at least 3 stats. Positions are small forward, power forward, center, shooting guard and point guard. 1. A.) Design a class with member variables and appropriate member functions Data should be stored in a read/write file consisting of team member’s names, jersey number, position played, and at least 3 stats. Use an enumeration for at least one member variable 2. Use a header file for all declarations Create at least two constructors and initialize Create a destructor Create a text based menu to perform the following functions which will loop until the user selects Number 8 for Quit: 3. Enter “1” OPEN ( Add any function you need for your team) 4. Enter “2” Add or replace team members as needed along with their information. 5. Enter “3” Identify the top players based on stats. The number to identify depend on the number needed i.e. for basketball there are 5 players who will be the starters. 6. Enter “4” search by player name and other stats as requested by user. 7. Enter “5” sort by player name or stats as requested by user. 8. Enter “6” to print all data. to screen Display sports team member’s names, jersey number, position played, and at least 3 stats Example stats: on the basketball team there are points scored, assists, rebounds and errors. 9. Enter “7” to print all data to file. 10.Enter “8” to Quit Add any classes, variables or member functions as needed to round out your program. The minimum requirements above must be included.

Mandatory Inclusion of programming concepts:

  1. Object Oriented design
    1. Header files
      1. classes
      2. constructors at least two
      3. destructor
  2. Input from user
  3. processing based on your requirements to include arrays to store data as needed.
  4. Output to screen
    1. Decision structure at least one of the following
      1. IF then else structure
      2. Switch
    2. Repetition structure or loop
  5. Output to file
  6. Functions
    1. Set or Mutators parameters passed in
    2. Get or Accessor functions
    3. Other functions as needed
  7. Menu which loops until user selects QUIT
0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION :-

// File name: basketball.h
#ifndef BASKETBALL_H
#define BASKETBALL_H

#include <string>
#define MAX 10
using namespace std;

enum statsPlayer {FGA = 1, EFG, FTA, FT, DREB, OREB};
class Basketball
{
string name;
int jerseyNumber;
string position;
string stats[3];
public:
Basketball();
Basketball(string, int, string, string[]);
void readFile(Basketball[], int &);
void addRecord(Basketball[], int &);
void topFive(Basketball[], int);
void searchPlayer(Basketball[], int);
void sortPlayer(Basketball[], int);
void displayAll(Basketball[], int);
void writeFile(Basketball[], int);
};

#endif

....................................

// File name: basketball.cpp

#include "baskeball.h"

#include<iostream>

#include<fstream>

#include<cstdlib>

using namespace std;

Basketball::Basketball()

{

name = position = stats[0] = stats[1] = stats[2];

jerseyNumber = 0;

}

Basketball::Basketball(string na, int jn, string po, string st[])

{

name = na;

jerseyNumber = jn;

position = po;

stats[0] = st[0];

stats[1] = st[1];

stats[2] = st[2];

}

void Basketball::readFile(Basketball bb[], int &len)

{

// ifstream object declared

ifstream fRead;

string newline;

// Opens the file for reading

fRead.open("basketball.txt");

// Checks if the file unable to open for reading display's error message and stop

if(!fRead)

{

cout<<"\n ERROR: Unable to open the file for reading.";

exit(0);

}// End of if condition

// Loops till end of the file

while(!fRead.eof())

{

fRead>>bb[len].name;

fRead>>bb[len].jerseyNumber;

getline(fRead, newline, '\n');

getline(fRead, bb[len].position);

fRead>>bb[len].stats[0];

fRead>>bb[len].stats[1];

fRead>>bb[len].stats[2];

len++;

}// End of while loop

}

void Basketball::addRecord(Basketball bb[], int &len)

{

string name;

int num;

string pos;

string stats[3];

cout<<"\n Enter name: ";

cin>>name;

cout<<"\n Enter jersey number: ";

cin>>num;

cout<<"\n Enter position: ";

getline(cin, pos);

cout<<"\n Enter stats 1: ";

cin>>stats[0];

cout<<"\n Enter stats 2: ";

cin>>stats[1];

cout<<"\n Enter stats 3: ";

cin>>stats[2];

Basketball temp(name, num, pos, stats);

bb[len] = temp;

len++;

}

void Basketball::topFive(Basketball bb[], int len)

{

int total[len] = {0};

for(int x = 0; x < len; x++)

{

if(bb[x].stats[0] == "FGA")

total[x] += 1;

else if(bb[x].stats[0] == "EFG")

total[x] += 2;

else if(bb[x].stats[0] == "FTA")

total[x] += 3;

else if(bb[x].stats[0] == "FT")

total[x] += 4;

else if(bb[x].stats[0] == "OREB")

total[x] += 5;

else

total[x] += 6;

if(bb[x].stats[1] == "FGA")

total[x] += 1;

else if(bb[x].stats[1] == "EFG")

total[x] += 2;

else if(bb[x].stats[1] == "FTA")

total[x] += 3;

else if(bb[x].stats[1] == "FT")

total[x] += 4;

else if(bb[x].stats[1] == "OREB")

total[x] += 5;

else

total[x] += 6;

if(bb[x].stats[2] == "FGA")

total[x] += 1;

else if(bb[x].stats[2] == "EFG")

total[x] += 2;

else if(bb[x].stats[2] == "FTA")

total[x] += 3;

else if(bb[x].stats[2] == "FT")

total[x] += 4;

else if(bb[x].stats[2] == "OREB")

total[x] += 5;

else

total[x] += 6;

}

}

void Basketball::searchPlayer(Basketball bb[], int len)

{

int found = -1;

string na;

cout<<"\n Enter player name to search: ";

cin>>na;

for(int x = 0; x < len; x++)

{

if(bb[x].name.compare(na) == 0)

{

found = x;

break;

}

}

if(found == -1)

cout<<"\n Record not found.";

else

cout<<"\n Name: "<<bb[found].name<<"\n Jersey Number: "<<bb[found].jerseyNumber

<<"\n Position: "<<bb[found].position<<"\n Stats 1: "<<bb[found].stats[0]

<<"\n Stats 2: "<<bb[found].stats[1]<<"\n Stats 3: "<<bb[found].stats[2];

}

void Basketball::sortPlayer(Basketball bb[], int len)

{

// Loops till length of the array

for(int c = 0; c < len; c++)

{

// Loops till length of the array minus outer loop variable value minus one

// Length minus out loop variable because after each iteration one record is sored

// minus one because numbers are compared in pair

for(int d = 0; d < len - c - 1; d++)

{

// Checks if the number stored at d index position is greater than

// number stored at next index position

if(bb[d].name.compare(bb[d + 1].name) < 0)

{

// Swapping process

Basketball temp = bb[d];

bb[d] = bb[d + 1];

bb[d + 1] = temp;

}// End of if condition

}// End of inner for loop

}// End of outer for loop

}

void Basketball::displayAll(Basketball bb[], int len)

{

// Loops till length of the array

for(int c = 0; c < len; c++)

cout<<"\n Name: "<<bb[c].name<<"\n Jersey Number: "<<bb[c].jerseyNumber

<<"\n Position: "<<bb[c].position<<"\n Stats 1: "<<bb[c].stats[0]

<<"\n Stats 2: "<<bb[c].stats[1]<<"\n Stats 3: "<<bb[c].stats[2];

}

void Basketball::writeFile(Basketball bb[], int len)

{

// ofstream object declared

ofstream fWrite;

// Opens the file for writing

fWrite.open("basketballStats.txt");

// Checks if the file unable to open for writing display's error message and stop

if(!fWrite)

{

cout<<"\n ERROR: Unable to open the file for writing.";

exit(0);

}// End of if condition

// Loops till end of the records

for(int x = 0; x < len; x++)

{

fWrite<<bb[len].name<<endl;

fWrite<<bb[len].jerseyNumber<<endl;

fWrite<<bb[len].position<<endl;

fWrite<<bb[len].stats[0]<<endl;

fWrite<<bb[len].stats[1]<<endl;

fWrite<<bb[len].stats[2]<<endl;

}// End of while loop

}

// Function to display menu, accept user choice and returns user choice

int menu()

{

// To store user choice

int ch;

// Displays menu

cout<<"\n\n

cout<<"\n 1. Open Records.";

cout<<"\n 2. Add record.";

cout<<"\n 3. Identify top 5 players.";

cout<<"\n 4. Search by player name or other stats.";

cout<<"\n 5. Sort by player name or other stats.";

cout<<"\n 6. Display all.";

cout<<"\n 7. Write to file.";

cout<<"\n 8. Exit.";

// Accepts user choice

cout<<"\n Enter your option: ";

cin>>ch;

// Returns user choice

return ch;

}// End of function

int main()

{

Basketball bb[MAX];

int len = 0;

int readStatus = 0;

do

{

switch(menu())

{

case 1:

bb[0].readFile(bb, len);

readStatus = 1;

break;

case 2:

bb[0].addRecord(bb, len);

readStatus = 1;

break;

case 3:

if(readStatus == 1 && len >= 5)

bb[0].topFive(bb, len);

else

cout<<"\n Not enough record to display Top Five.";

break;

case 4:

if(readStatus == 1)

bb[0].searchPlayer(bb, len);

else

cout<<"\n Not enough record to search player.";

break;

case 5:

if(readStatus == 1)

bb[0].sortPlayer(bb, len);

else

cout<<"\n Not enough record to sort players.";

break;

case 6:

if(readStatus == 1)

bb[0].displayAll(bb, len);

else

cout<<"\n Not enough record to display.";

break;

case 7:

if(readStatus == 1)

bb[0].writeFile(bb, len);

else

cout<<"\n Not enough record to write.";

break;

case 8:

exit(0);

break;

default:

cout<<"\n Invalid choice!!";

}

}while(1);

return 0;

}

Sample Output:


****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 6

Not enough record to display.

****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 1


****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 6

Name: Pyari
Jersey Number: 111
Position: Power forward
Stats 1: FGA
Stats 2: EFG
Stats 3: FTA
Name: Pramod
Jersey Number: 527
Position: Shooting Guard
Stats 1: OREB
Stats 2: FT
Stats 3: FTA
Name: Amiya
Jersey Number: 121
Position: Center
Stats 1: FGA
Stats 2: FT
Stats 3: FTA
Name: Anil
Jersey Number: 231
Position: Small Forward
Stats 1: DREB
Stats 2: OREB
Stats 3: FTA
Name: Sasi
Jersey Number: 122
Position: Shooting Guard
Stats 1: FGA
Stats 2: FT
Stats 3: EFG
Name: Sunil
Jersey Number: 321
Position: Small Forward
Stats 1: EFG
Stats 2: OREB
Stats 3: DREB
Name: Ram
Jersey Number: 221
Position: Point Guard
Stats 1: EFG
Stats 2: FT
Stats 3: FTA

****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 4

Enter player name to search: Pyari

Name: Pyari
Jersey Number: 111
Position: Power forward
Stats 1: FGA
Stats 2: EFG
Stats 3: FTA

****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 5


****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 6

Name: Sunil
Jersey Number: 321
Position: Small Forward
Stats 1: EFG
Stats 2: OREB
Stats 3: DREB
Name: Sasi
Jersey Number: 122
Position: Shooting Guard
Stats 1: FGA
Stats 2: FT
Stats 3: EFG
Name: Ram
Jersey Number: 221
Position: Point Guard
Stats 1: EFG
Stats 2: FT
Stats 3: FTA
Name: Pyari
Jersey Number: 111
Position: Power forward
Stats 1: FGA
Stats 2: EFG
Stats 3: FTA
Name: Pramod
Jersey Number: 527
Position: Shooting Guard
Stats 1: OREB
Stats 2: FT
Stats 3: FTA
Name: Anil
Jersey Number: 231
Position: Small Forward
Stats 1: DREB
Stats 2: OREB
Stats 3: FTA
Name: Amiya
Jersey Number: 121
Position: Center
Stats 1: FGA
Stats 2: FT
Stats 3: FTA

****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 7


****************** MENU ******************
1. Open Records.
2. Add record.
3. Identify top 5 players.
4. Search by player name or other stats.
5. Sort by player name or other stats.
6. Display all.
7. Write to file.
8. Exit.
Enter your option: 8

basketball.txt file contents

Pyari
111
Power forward
FGA
EFG
FTA
Pramod
527
Shooting Guard
OREB
FT
FTA
Amiya
121
Center
FGA
FT
FTA
Anil
231
Small Forward
DREB
OREB
FTA
Sasi
122
Shooting Guard
FGA
FT
EFG
Sunil
321
Small Forward
EFG
OREB
DREB
Ram
221
Point Guard
EFG
FT
FTA

OPTION 1 -

int total[len] = {0}; ****Says there is a problem with "len" here, needs to be a constant

Add a comment
Know the answer?
Add Answer to:
C++ Language Overview: Design an APP for a basketball team with a unique name. There should be at least 10 players. The member variables required include team member’s names, jersey number, position p...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to update this C++ code according to these instructions. The team name should be...

    I need to update this C++ code according to these instructions. The team name should be "Scooterbacks". I appreciate any help! Here is my code: #include <iostream> #include <string> #include <fstream> using namespace std; void menu(); int loadFile(string file,string names[],int jNo[],string pos[],int scores[]); string lowestScorer(string names[],int scores[],int size); string highestScorer(string names[],int scores[],int size); void searchByName(string names[],int jNo[],string pos[],int scores[],int size); int totalPoints(int scores[],int size); void sortByName(string names[],int jNo[],string pos[],int scores[],int size); void displayToScreen(string names[],int jNo[],string pos[],int scores[],int size); void writeToFile(string...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • C++ Design a class bankAccount that defines a bank account as an ADT and implements the...

    C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT