Question

In: Computer Science

C++ Chapter 4/5 Lab Assignment Using concepts from chapters 1 – 5 only. Grading will be...

C++ Chapter 4/5 Lab Assignment Using concepts from chapters 1 – 5 only. Grading will be based on chapter 4 concepts more. Design a menu driven program that can keep track of five player’s scores. Your program must have the following documentation: A. Your name B. The program name C. Program Description D. The date the exe file was created E. The code: a. Use a menu approach do the following: i. to Add a player information ii. to Search for any player based on their name. iii. to Display all the information at any time (Hint : Use value and reference parameters as necessary).. b. Organize the main program to call input and output functions. Use static variables to keep track of player’s information. c. Input the names of five players and their highest scores on three games they ever played. Do Not Hard-Code the players’ names and their scores. d. Create an average function to compute the average highest score of each player i.e. ( john: g1 100 g2 200 g3 300. Average highest score will be 200.00).

Solutions

Expert Solution

Source code:

#include <iostream>

using namespace std;

/*
* class to store player details
*/
class Player{
string name; //name of the player
int scores[3]; //highest scores of 3 matches
  
public:
Player(){} //default constructor
//constructor to initialize details
Player(string name, int s0, int s1, int s2){
this->name = name;
scores[0] = s0;
scores[1] = s1;
scores[2] = s2;
}
  
//to get name
string getName(){
return name;
}
  
//to get score of match i
int getScore(int i){
return scores[i];
}
};

void getPlayerDetails(Player players[], int* total_players);
void searchAPlayer(Player players[], int total_players);
void displayDetailsOfAllPlayers(Player players[], int total_players);
void displayAverageScores(Player players[], int total_players);
double findAverageScore(Player players[], int indx);

int main(){
//player object to store details of 5 players
Player players[5];
int total_players = 0; //total players
char ch;
  
//loop until user exits
do{
//main menu display
cout << "1. Enter the details of a player" << endl
<< "2. Search for a player" << endl
<< "3. Display the details of all players" << endl
<< "4. Display average highest scores of all players" << endl
<< "0. Exit" << endl
<< "Your choice: ";
cin >> ch;
  
switch(ch){
case '1':
//choice to add player details
getPlayerDetails(players, &total_players);
break;
case '2':
//choice to search for a player
searchAPlayer(players, total_players);
break;
case '3':
//choice to display details of all players
displayDetailsOfAllPlayers(players, total_players);
break;
case '4':
//choice to display average scores
displayAverageScores(players, total_players);
break;
case '0':
//choice to exit
break;
default:
//invalid choice
cout << "Invalid choice" << endl << endl;
break;
}
}while(ch != '0');
return 0;
}

/*
* get details of a player
*/
void getPlayerDetails(Player players[], int* total_players){
string name;
int s0, s1, s2;
  
cout << "Enter name of the player: ";
cin >> name;
cout << "Enter the score 1 : ";
cin >> s0;
cout << "Enter the score 2 : ";
cin >> s1;
cout << "Enter the score 3 : ";
cin >> s2;
cout << endl;
  
players[*total_players] = Player(name, s0, s1, s2);
*total_players = *total_players + 1;
}

/*
* search for a player
*/
void searchAPlayer(Player players[], int total_players){
string name;
cout << "Enter name of the player to search: ";
cin >> name;
for(int i = 0; i < total_players; i++){
if(players[i].getName().compare(name) == 0){
cout << "The details of player are:" << endl;
cout << "\tScore 1: " << players[i].getScore(0) << endl;
cout << "\tScore 2: " << players[i].getScore(1) << endl;
cout << "\tScore 3: " << players[i].getScore(2) << endl << endl;
return;
}
}
  
cout << "Player details not found." << endl << endl;
}

/*
* display details of all players
*/
void displayDetailsOfAllPlayers(Player players[], int total_players){
for(int i = 0; i < total_players; i++){
cout << "Player " << i + 1 << " name : " << players[i].getName() << endl;
cout << "\tscore 1 : " << players[i].getScore(0) << endl;
cout << "\tscore 2 : " << players[i].getScore(1) << endl;
cout << "\tscore 3 : " << players[i].getScore(2) << endl;
}
  
cout << endl;
}

/*
* display average scores
*/
void displayAverageScores(Player players[], int total_players){
for(int i = 0; i < total_players; i++){
cout << "Player name : " << players[i].getName() << endl;
cout << "Average score: " << findAverageScore(players, i) << endl << endl;
}
cout << endl;
}

/*
* find average score of a player
*/
double findAverageScore(Player players[], int indx){
double total_score = 0.0;
for(int i = 0; i < 3; i++){
total_score += players[indx].getScore(i);
}
  
return total_score / 3;
}

Code screenshot:

Output:


Related Solutions

Organisational behaviour- For this assignment you will pick a chapter from the chapters we will cover...
Organisational behaviour- For this assignment you will pick a chapter from the chapters we will cover in class and discuss what your main learning from the reading/class discussion was and how this learning has impacted your way of thinking in your personal and/or professional life. What has changed? How might this affect your future practice? What are the implications for the workplace? Is there a question or a concern that has arisen for you as a result of this content?
C++ Programming Chapter 7 Assignment: Assignment #4 – Student Ranking : In this assignment you are...
C++ Programming Chapter 7 Assignment: Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display...
Using SQL Developer ONLY! Lab 5 1. Create a lab report file (MS Word compatible) and...
Using SQL Developer ONLY! Lab 5 1. Create a lab report file (MS Word compatible) and name it as “IT4153_Lab 5_ Your D2L ID”. a. Create two tables: Employee: empID (PK), empFname, empLname, deptID(FK) and Department: deptID(PK), deptName, chairID chairID is empID from Employee table b. Insert at least 3 rows in the Department table and at least 6 rows in the Employee table. c. Create trigger on update of chairID that enforces the following business rules • One employee...
CSCI 1470 Lab 5 Assignment #3 Topic: Selection (switch statement)) Reading: Chapter 4 Point Value: 15...
CSCI 1470 Lab 5 Assignment #3 Topic: Selection (switch statement)) Reading: Chapter 4 Point Value: 15 points *Note: Include the following set of comments at the top of your source code for all assignments. //Your Name //Brief description of the purpose of the program (Example: Displays student information.) Assignment: (Save this file as Lab5-3-YourLastName.cpp) A mobile phone service provider has three different subscription packages for its customers: Package A: For $39.99 per month 450 minutes are provided. Additional minutes are...
C++ ONLY -- LAB ASSIGNMENT DIFFICULT We have to turn in two files - List.h and...
C++ ONLY -- LAB ASSIGNMENT DIFFICULT We have to turn in two files - List.h and Lab5.cpp What should the code for those two files look like? INSTRUCTIONS AS FOLLOWS: What Should This Program Do? Linked List Class Design your own linked list class (List.h) to hold a series of strings. The linked list node should be implemented as a struct. The class should have member functions for appending, inserting, and deleting nodes. You should also have a display function...
Please complete in only C++, using loops Assignment: For this assignment you’ll be designing a program...
Please complete in only C++, using loops Assignment: For this assignment you’ll be designing a program which can take the input of a decimal number and a numerical base, and convert the decimal number to that base. For example, if given the decimal number seven and the base two, your program should output it as 111, which is how seven is represented in binary. Another example, 8,943 in base 10, is 13,236 in base 9. You’ll need to perform these...
This is a tough chapter - not because the concepts are that hard, but only because...
This is a tough chapter - not because the concepts are that hard, but only because there are so many different decisions and the format utilized to make the decision is different for each. My question is, the book goes over a lot of different potential decisions, the common factors involved and the ways to determine the correct decision from an economic standpoint. Are there non-quantitative factors to consider? Like what?
Discussion Module 3: Prenatal Development and Birth. the chapters required for the Assignment  is chapter 3 in...
Discussion Module 3: Prenatal Development and Birth. the chapters required for the Assignment  is chapter 3 in the text book which is Lifespan development 7E. upper saddle text book. 1.Choose one piece of research from the chapters on Prenatal Development and Birth that interests you. In the title of your discussion, include the topic (from the heading in the textbook) and the page number where you found the section. For example, your title might be: How Teratogens Influence Development, pp. 64-66....
Assignment Chapters 5 1. If you invest $1,500 and you expect the following payoffs with correlating...
Assignment Chapters 5 1. If you invest $1,500 and you expect the following payoffs with correlating probability $300.00 .3 $1500.00 .3 $1800.00. .3 $3500.00 .1 Calculate the the Expected value, Standard deviation, and Variance of each. 2. If you invest $1,500 and you expect the following payoffs with correlating probability $600.00 .1 $1500.00 .5 $1800.00. .2 $2500.00 .2 Calculate the the Expected value, Standard deviation, and Variance of each. Which investment would you choose? Which one is riskier?
5. Using only the digits of 1, 4, 5, 8, (a) How many three digit numbers...
5. Using only the digits of 1, 4, 5, 8, (a) How many three digit numbers can be formed? (b) How many odd numbers greater than 10 can be formed? (c) How many even number less than 300 can be formed? Repetition is allowed!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT