Question

soccerApp.cpp is used to test your code and contains the main function. No changes to this...

soccerApp.cpp is used to test your code and contains the main function. No changes to this file are necessary.

Inside of the soccerPlayer.cpp file, implement the three member functions that are specified in

soccerPlayer.hpp. The member function definition for print is already provided.

soccerPlayer.cpp:

#include "soccerPlayer.hpp"

void TopTwoPlayer::print() const {

cout << left << setw(8) << "Name: " << setw(18) << name << setw(10) << "Country:" <<

setw(18) << country << setw(14) << "appearances:" << right << setw(3) << appearances <<

setw(4) << " " << left << setw(8) << "games:" << right << setw(3) << games << endl;

}

// Place your member function definitions here:

// 1: The constructor. Remember that you don't know how long the c-string arguments are.

// Use strncpy and null terminate.

// 2: Function definition for moreAppearances.

// 3: Function definition for moreGames.

soccerPlayer.hpp:

// Header file for lab 4.

#ifndef PLAYER_HPP

#define PLAYER_HPP

#include <iostream>

#include <iomanip>

#include <cstring>

using namespace std;

const int STR_SIZE = 100;

class TopTwoPlayer { // Soccer players with the most finishes in the top 2 teams.

char name[STR_SIZE];

char country[STR_SIZE];

int appearances; // How many times they played in a game.

int games; // The number of games where the player was on the team.

public:

void print() const; // Already implemented in soccerPlayer.cpp.

// Implement the following functions in soccerPlayer.cpp

TopTwoPlayer(const char nameArg[], const char countryArg[], int appearancesArg, int gamesArg);

bool moreAppearances(const TopTwoPlayer & otherPlayer) const;

bool moreGames(const TopTwoPlayer & otherPlayer) const;

};

#endif

soccerApp.cpp:

#include "soccerPlayer.hpp"

using namespace std;

int main() {

        TopTwoPlayer player1("Birgit Prinz", "Germany", 18, 18); // Testing your constructor with arguments.

        TopTwoPlayer player2("Christie Rampone", "United States", 9, 19);

cout << "\nTwo of the \"top two\" players: " << endl;

        player1.print();

        player2.print();

cout << endl;

        if(player1.moreAppearances(player2)) { // Testing your moreAppearances code.

                cout << "Great job on moreAppearances code!" << endl;

        } else {

                cout << "Hmm, moreAppearances code is not quite right." << endl;

        }

        if(player2.moreGames(player1)) { // Testing your moreGames code.

                cout << "Great job on moreGames code!" << endl;

        } else {

                cout << "Hmm, your moreGames code is not quite right." << endl;

        }

        return 0;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Please like and comment

soccerPlayer.cpp

TopTwoPlayer::TopTwoPlayer(const char nameArg[], const char countryArg[], int appearancesArg, int gamesArg)
{
   strncpy(name, nameArg, strlen(nameArg) + 1);
   strncpy(country, countryArg, strlen(countryArg) + 1);
   appearances = appearancesArg;
   games = gamesArg;
}
// 2: Function definition for moreAppearances.

bool TopTwoPlayer::moreAppearances(const TopTwoPlayer & otherPlayer) const
{

   return appearances >= otherPlayer.appearances;
}
// 3: Function definition for moreGames.

bool TopTwoPlayer::moreGames(const TopTwoPlayer & otherPlayer) const
{
   return games >= otherPlayer.games;
}

output

GNC\windows system32\cmd.exe Two of the top two players: Name: Birgit Prinz lame: Christie Rampone Country:United States ap

Add a comment
Know the answer?
Add Answer to:
soccerApp.cpp is used to test your code and contains the main function. No changes to this...
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
  • Can somebody help me with this coding the program allow 2 players play tic Tac Toe....

    Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...

  • You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function...

    You are given a Q1.h file with overloaded function prototypes for isOrdered. Implement this overloaded function into a file named Q1.cpp. Q1.cpp should only include your function implementation, the necessary #include directives if needed, and should not contain anything else such as the main function or global variable declarations. Test your code using a separate main.cpp file where you implement a sufficient number of test cases. You should use Q1.h as a header file and Q1main.cpp as a main function...

  • For the LinkedList class, create a getter and setter for the private member 'name', constructing your...

    For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...

  • Code in C++: Please help me fix the error in function: void write_account(); //function to write...

    Code in C++: Please help me fix the error in function: void write_account(); //function to write record in binary file (NOTE: I able to store data to a txt file but however the data get error when I try to add on data the second time) void display_all(); //function to display all account details (NOTE: This function is to display all the info that save account.txt which is ID, Name, and Type) void modify_account(int); //function to modify record of file...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • I cannot get the C++ code below to compile correctly. Any assistance would be greatly appreciated!...

    I cannot get the C++ code below to compile correctly. Any assistance would be greatly appreciated! ***main.cpp driver file*** #include #include #include "vector.h" using namespace std; int main() {     vectorInfo v1(3, -1);     vectorInfo v2(2, 3);     cout << "v1 : ";     v1.print();     cout << "v2 : ";     v2.print();     cout << "v1 magnitude : " << v1.magnitude() << endl;     cout << "v1 direction : " << v1.direction() << " radians" << endl;     cout...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • I want to change this code and need help. I want the code to not use...

    I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...

  • 2 The following code has some errors. Please point out and correct them (there might be...

    2 The following code has some errors. Please point out and correct them (there might be more than 1 errors). Note: the use of const data member increment and member function print. // This code has some errors. #include using namespace std; class Increment { public: Increment( int c = 0, int i = 0); void addIncrement() const { count -= increment }; void print() const; private: int count; const int increment; }; Increment::Increment(int c, int i) { cout =...

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
Active Questions
ADVERTISEMENT