Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please let me know how to write C++ code without using setw function. Have to use the variables and functions that are mention in the
Please let me know how to write C++ code without using setw function.
Have to use the variables and functions that are mention in the instruction.
Need 4 separate files (SoccerTeam.cpp SoccerTeam.h Tournament.cpp Tournament.h). Please check the attachments.
Tester program main.cpp
Correct Output
In this workshop you have to Implement two modules (i.e., classes): Tournament and SoccerTeam The SoccerTeam module Develop this module in two files named soccerTeam.h and soccerTeam.cpp. Create a structure named soccerTeam and the structure should have the following member variables (attributes) and member functions (method): First, define the following constant in the soccerTeam header file: const int MAX_FOUL =4;1/ maximum number of fouls member variables(attributes) The struct soccerTeam should have the following member variables: char m_teamName[41];// a statically allocated Cstring with size 41. Remember, name could be //maximum 40 characters long and 1 byte is for the null byte. int m_noFouls;/umber of fouls, it can be zero or more but cannot be a negative number double m_fines;//it can be equal to and more than zero. int m_golas;//can be zero or more member functions(methods) void setTeam(const SoccerTeam\& team) It will set the team name, fine and fouls of the team. void setName(const char* tname) If the received name pointer is valid and not null it will copy the received name to the data member m_teamName void setFine(double fines, int foul) It will receive the information about fines and no of foul. After checking the validity it will set the values to the appropriate data members. Fine and foul should be grater than and equal to zero. Otherwise, it will set the soccerTeam object to an empty state. void setEmpty(); Sets the soccerTeam object to an Empty State. Do this by setting the m teamName to an empty Cstring, m noFoul and m_fines to a negative number and mgoals to 0 . bool isEmpty( ) const; Returns true if mteamName is not null, m_fines and m_noFouls is grater than 0 . void calfines (); If this function is called it will increases the fine by 20% of the old fine value. It will return the m_noFoul A soccerTeam can be created in two different ways: soccerTeam(); - By default a soccerTeam is set to the empty state (as in setEmpty()) Three argument constructor SoccerTeam(const char* tname, double fines, int foul); After checking the validity it will set the team's name,fine and no of fouls to the appropriate data members or else it will set the team to the empty state. (reuse your setter fucntions) 1. If a soccerTeam object is valid a) prints m_teamName with width 30 , left justified and fill with empty spaces. b) prints m_fines with width 6 and after the decimal point 2 digits. c) prints m_noFoul with width 6 d) prints m_fines with width 6 e) prints m golas with width 10 . If number of goals are greater than zero then it will print "w" besides the number. 2. otherwise prints, "Invalid Team". 3. At the end return the reference of the ostream object. The Tournament module Develop this module in two files named Tournament.h and Tournament.cpp. Place your class definition in Tournament.h and your function definitions in Tournament.cpp. Create a class named Tournament and the class should have the following member variables (attributes) and member functions (method): Private member variables(attributes) The class should have the following private member variables: char* m_name;//points to a dynamically allocated Cstring int m_num;//size of the dynamically allocated array of soccer team. It should be more then zero. SoccerTeam* m_soccer=nullptr;//pointer to the dynamically allocated array of soccerTeam Public member functions(methods) void setTournament (const char* name, int noofteam, const SoccerTeam* soccer); - First, it will check the validity of all the received arguments. Tournament name should be valid and non-empty Cstring. Number of teams should be greater than zero. - It will set m_num to the corresponding argument value. - Then it will dynamically allocate memory for tournament name in the tournament name pointer attribute and then copies the content of the tournament name argument into the newly allocated memory. - It will dynamically allocate an array of soccer team pointed by msoccer member variable. The length of this array will be m_num. - Lastly, add all the teams to the dynamically allocated array of m _soccer. - If any of the arguments are not valid it will set the Tournament to an empty state. void setEmpty(); Sets the Tournamnet object to an Empty State. Do this by setting the m_name and m_soccer to null and m num to 0 . bool isempty() const; Returns true if m_name and m_soccer is not null and m_num is grater than 0 . Tournament\& match (const SoccerTeam* 1s); This function will find out the winner between 2 soccer teams by having matches. It will loop through all the teams. - First it will check which team is having more no of fouls. - If first team is having less fouls then second team then, second team's no of foul will increase by double and fine will be increased by 20% - First team's goal will be increased by 1. - If seconds team's no of foul exceed the MAX_FOUL then this team will become a invalid team. You can do this by setting the number to foul to an invalid value. - At the end it will return the reference of the current object. ostream\& display() const; 1. If Tournament object is valid a) prints "Tournament name: " then tournament name b) prints "list of the teams" after that a newline c) prints "Fines" with width 45 and fill with empty spaces. d) prints "Fouls" with width 10 and fill with empty spaces. e) prints "Goals" with width 10 and fill with empty spaces. e) prints all the soccer teams information. For details see the sample output. 2. otherwise prints, "Invalid Tournament". 3. At the end return the reference of the ostream object. Sample output construction and destruction A Tournament can be created in two different ways: Tournament( ); - By default a Tournament is initiated by setting all the member variable values to default values. You can do this by setting m_name, m_soccer to nullptr and m_num to a value like 0 . Three argument constructor Tournamnet(const char* name, int noofteam, const SoccerTeam* soccer); It works exactly like the setTournamnet() Tournament ( ) ; Deallocate the memory allocated by m_name and msoccer. *****First match between two Teams***** I> T4:Undated list with the winner
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started