Starting Computing Homework 8

$24.99 $18.99

All 3 components (Cloud9 workspace, Moodle Coderunner attempts, and zip file) must be completed and submitted by Saturday, April 6, at 6 pm for your homework to receive points. 1. Objectives Vector operations Create vectors of an object type Define classes and create objects that use other objects as data members Develop some methods that…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:

Description

5/5 – (2 votes)

All 3 components (Cloud9 workspace, Moodle Coderunner attempts, and zip file) must be completed and submitted by Saturday, April 6, at 6 pm for your homework to receive points.

1. Objectives

  • Vector operations

  • Create vectors of an object type

  • Define classes and create objects that use other objects as data members

  • Develop some methods that will be useful in your Project 3 codes!

2. Submission Requirements

All three steps must be fully completed by the submission deadline for your homework to be graded.

  1. Create Hmwk8 directory on your Cloud 9 workspace:Your recitation TA will review your code by going to your Cloud9 workspace.TAs will check the last version that was saved before the submission deadline.

    • Create a directory calledHmwk8 and place all your file(s) for this assignment in this directory.

    • Make sure tosave the final version of your code (File > Save). Verify that this version displays correctly by going to File > File Version History.

    • The file(s) should have all of your functions, test cases for the functions in main() function(s), and adhere to the style guide. Please read the submission file instructions under Week 4.You must include a test case for each one of your member functions for your classes.

  1. Submit to the Moodle Coderunner:Head over to Moodle to the link Homework 8 Coderunner. You will find one programming quiz question for each problem in the assignment. Submit your solution for the first problem and press the Check button. You will see a report on how your solution passed the tests, and the resulting score for the first problem. You can modify your code and re-submit (pressCheckagain) as many times as you need to, up until the assignment due date. Continue with the rest of the problems.

  1. Submit a .zip file to Moodle:After you have completed all questions from the Moodle assignment, zip all 8 files you compiled in Cloud9, and submit the zip file through theHomework 8 (File Submission)​​link on Moodle.

3. Rubric

Aside from the points received from the Homework 8 Coderunner quiz problems, your TA will look at your solution files (zipped together) as submitted through the Homework 8 (File Submission)link on Moodle and assign points for the following:

Style and Comments(5 points):

  • The style guideis posted on Moodle under Week 6.

  • Your code should be well-commented. Please review the standard for well-commented code, presented in more detail in previous homework write-ups.

  • Please also include a comment at the top of your solution with the following format:

    • CS1300 Spring 2019

    • Author: my name

    • Recitation: 123 – Favorite TA

    • Cloud9 Workspace Editor Link: https://ide.c9.io/…

    • Project 2 – Problem # …

Global variables(use will result in a 5 point deduction):

  • To keep things simple, straightforward, and easy to debug and test,you may not use global variables in this homework.

Algorithm(5 points):

function. Please review the standard for including your algorithm for each function, presented in more detail in previous homework write-ups.

Test Cases(20 points):

  1. Code compiles and runs(10 points):

All the files you submit on Moodle under the zip file submission should compile and be free of bugs. It is important that your programs can be compiled and run on Cloud9 with no errors. The class files and the functions included in these programs should match those submitted to the CodeRunner on Moodle.

  1. Test cases(20 points):

For this week’s homework, every problem is asking you to define a class and/or some of its member functions, or functions to make use of your classes. In addition to the class files (.h and .cpp), you will need to create a driver/tester program, with a main() function, where you must have test cases for each function or member function. Your test cases should follow the guidelines, Writing Test Cases, posted on Moodle under Week 3.

Please make sure that your submission files follow the the submission file instructions under Week 6.

4. Problem Set

Problem 1 – vector fun!

Write a functionshuffle that takes as input parameter arguments two vectors of integer values and returns a vector of integer values that combines the two input vectors by alternating between values from each of the two vectors.

  • If one vector is shorter than the other (including size 0), then alternate as long as you can, starting with the longer vector, and then append the remaining elements from the longer vector.

  • If both vectors are empty (size 0), then the return value should be an empty vector.

  • If both input vectors are the same size, then the first element of the returned vector should come from the first input argument.

Examples:

Function call

Output

vector<int> v1{1,3,5,9};

2143658910

vector<int> v2{2,4,6,8,10};

vector<int>

v3 = shuffle(v1,v2);

for (int i=0; i < v3.size(); i++) {

cout << v3[i] << “ ”;

}

vector<int> v4{1,3};

153-7

vector<int> v5{5,-7};

vector<int> v6 = shuffle(v4,v5);

for (int i=0; i < v6.size(); i++) {

cout << v6[i] << “ ”;

}

vector<int> v7;

(empty vector)

vector<int> v8;

vector<int> v9 = shuffle(v7,v8);

for (int i=0; i < v9.size(); i++) {

cout << v9[i] << “ ”;

}

The zip submission should have one file for this problem:shuffleDriver.cpp, with your shuffle()function and amain()function to test yourshuffle()function.

For the Problem 1 Coderunner, pasteyour shuffle function only. Do not include your main()function from shuffleDriver.cpp that you used for testing your function.

Problem 2 – the Player class

CreatePlayer.h andPlayer.cpp to implement thePlayer class as described below. You will also need to create aplayerDriver.cpp file to test yourPlayer class implementation. The Playerclass has the following attributes:

Data members (private):

string:name

The player’s name

double:points

The player’s points

Member functions (public):

Default constructor

Setname=“”andpointsto value 0.

Parameterized constructor

Takes a string and double initializingnameand

points, in this order

getName()

Returns the player’snameas a string

getPoints()

Returns the player’spointsas a double

setName(string)

Sets the player’sname(and returns nothing)

setPoints(double)

Sets the player’spoints(and returns nothing)

The zip submission should have three files for this problem:Player.h,Player.cpp, and a driver calledplayerDriver.cpp to test your member functions. For Coderunner, in the Answer Box, paste your Player class and its implementation(contents of Player.h and Player.cpp). Donotinclude yourmain()function from​​playerDriver.cpp that you used for testing.

In yourmain() function inplayerDriver.cpp, the test cases should include the creation of class objects with both the default and parameterized constructors. You must also test each of the getter and setter member functions by creating and manipulating class objects and displaying output to verify that things are working properly. For reference, follow the cashRegister example from lecture 22 materials, and theWorked Example 9-1from the textbook (Implementing a Bank Account Class– step 6: Test your class).

Examples:

Function call

Output

Player stella;

(empty string)

cout << stella.getName() << endl;

0

cout << stella.getPoints() << endl;

Stella

stella.setName(“Stella”);

13.1

stella.setPoints(13.1);

cout << stella.getName() << endl; cout << stella.getPoints() << endl;

Player hector(“Hector”, 6.2);

Hector

cout << hector.getName() << endl;

6.2

cout << hector.getPoints() <<

endl;

Problem 3 – the Team class

CreateTeam.h andTeam.cpp to implement theTeam class as described below. You will also need to create ateamDriver.cpp file to test yourTeam class implementation. The Teamclass has the following attributes:

Data members (private):

string:teamName

The team’s name

vector<Player>:players

The players on this team

Member functions (public):

Default constructor

SetteamName=“”and an empty vector of Players.

Parameterized constructor

Takes a string to initializeteamName, and set an empty

vector of Players.

setTeamName(string)

Takes a string to setteamName(and returns nothing)

readRoster(string)

Reads from the input file name (a string) a list of player

namesand theirpointsvalues, separated by a

comma, and appends the players (in order) to the

playersvector for this team

getPlayerName(int i)

Returns thename(string) of the player at positioni

within theplayersvector

getPlayerPoints(int i)

Returns thepoints(double) of the player at positioni

within the ​players​vector

getNumPlayers()

Returns the number of players on this team (as an

integer)

getTeamName()

Returns the name of this team (as a string)

readRoster:Players should be pushed to the players vector in order from the beginning of the file to the end.

  • There willnotbe any blank lines in the input files.

  • Your code should be able to handle the case where multiple roster files are read for a single team.

  • Note that on Moodle, we have postedroster1.txt androster2.txt, which are two test files you may use (and/or modify) for testing your functions.

getPlayerName/getPlayerPoints:ThegetPlayerName andgetPlayerPoints member functions take an integer input argument that represents the index of a Player object within theplayers vector, whose name or points we want to query. If either of these member functions receive an input argumenti that is outside of the bounds of theplayers vector, then:

  • getPlayerNameshould return “ERROR”, and

  • getPlayerPointsshould return -1

The zip submission should have five files for this problem:Player.h,Player.cpp,Team.h, Team.cpp, and a driver calledteamDriver.cpp to test your member functions. For Coderunner, in the Answer Box, paste your PlayerandTeam classesand their implementations(contents of Player.h and Player.cpp, and Team.h and Team.cpp).Donot include yourmain()function from​​teamDriver.cpp that you used for testing.

In yourmain() function inteamDriver.cpp, the test cases should include the creation of class objects with both the default and parameterized constructors. You must also test each of the getter and setter member functions by creating and manipulating class objects and displaying output to verify that things are working properly. For reference, follow the cashRegister example from lecture 22 materials, and theWorked Example 9-1from the textbook (Implementing a Bank Account Class– step 6: Test your class).

Examples:

Function call

Output

// Using

roster1.txt from Moodle

Seg Faultline

Team team1(“Seg Faultline”);

5

cout << team1.getTeamName() << endl;

O’Flaherty 5.5

team1.readRoster(“roster1.txt”);

Ioana Fleming 6.1

int

n1 =

team1.getNumPlayers();

Behera 8

cout << n1 << endl;

Ku 4.9

for (int

i = 0; i < n1; i++) {

Sankaralingam 1.7

cout

<< team1.getPlayerName(i) << “ ”;

}

cout

<< team1.getPlayerPoints(i) << endl;

// Using

roster1.txt and roster2.txt

Thats so Ravenclaw

//

from

Moodle

10

Team team2;

O’Flaherty 5.5

team2.setTeamName(“Thats so Ravenclaw”);

Ioana Fleming 6.1

cout << team2.getTeamName() << endl;

Behera 8

team2.readRoster(“roster1.txt”);

Ku 4.9

team2.readRoster(“roster2.txt”);

Sankaralingam 1.7

int

n2 =

team2.getNumPlayers();

Reddy 9.1

cout << n2 << endl;

Palavalli 2.8

for (int

i = 0; i < n2; i++) {

Naidu 5.6

cout

<< team2.getPlayerName(i) << “ ”;

Tetsumichi (Telly)

cout

<< team2.getPlayerPoints(i) << endl;

Umada 4.4

}

Ladd 8

// Using

roster1.txt from Moodle

Oh no!

Team team3(“Oh no!”);

5

cout << team3.getTeamName() << endl;

ERROR -1

team3.readRoster(“roster1.txt”);

Sankaralingam 1.7

int

n3 =

team3.getNumPlayers();

ERROR -1

cout << n3 << endl;

cout << team3.getPlayerName(-1) << “ ”;

cout << team3.getPlayerPoints(-1) << endl;

cout << team3.getPlayerName(4) << “ ”;

cout << team3.getPlayerPoints(4) << endl;

cout << team3.getPlayerName(5) << “ ”; cout << team3.getPlayerPoints(5) << endl;

Problem 4 – thegame()function

Write a function,game, to take as input parameters twoTeam objects (filled withPlayer vectors) and return the name (as a string) of the winning team. The function should:

  • Be namedgame

  • Taketwoarguments, both of typeTeam

  • Return thenameof the winning team, as a string

    • To determine the winning team, add up the points associated with each team’s first 4 players. The team with more points is the winner.

    • If one or both of the teams do not have 4 or more players, your function should return “forfeit”

    • If the teams have the same total points, your function should return “draw”

    • The output of “forfeit” takes higher priority than “draw” in the sense that if a team doesn’t have enough players, a game cannot be played, so there could be no draw (for example, if both teams have no players, this would constitute a “forfeit”, not a draw).

Example 1: In this example, the team Seg Faultline wins because the total points of their first 4 players is 24.5 points, whereas Team Maim only has 21.9 points.

Function call

Output

// Using roster1.txt and roster2.txt

The winner is: Seg

// from Moodle

Faultline

Team team1(“Seg Faultline”);

team1.readRoster(“roster1.txt”);

Team team2(“Team Maim”);

team2.readRoster(“roster2.txt”);

string winner = game(team1, team2);

cout << “The winner is: ” << winner << endl;

result should be “forfeit” because one (or more) teams do not have enough players.

Function call

Output

// Using roster2.txt from Moodle

The winner is:

Team team3(“Hurt Shoebox”);

forfeit

team3.readRoster(“roster00.txt”);

Team team2(“Team Maim”);

team2.readRoster(“roster2.txt”);

string winner = game(team3, team2);

cout << “The winner is: ” << winner << endl;

Example 3: In this example, the teams have identical rosters. So, the result should be “draw” because the points totals are the same.

Function call

Output

// Using roster1.txt from Moodle

The winner is: draw

Team team4(“Thats so Ravenclaw”);

team4.readRoster(“roster1.txt”);

Team team5(“Planes on a Snake”);

team5.readRoster(“roster1.txt”);

string winner = game(team4, team5);

cout << “The winner is: ” << winner << endl;

The zip submission should have five files for this problem:Player.h,Player.cpp,Team.h, Team.cpp, and a driver calledgameDriver.cpp, with yourgame() function and amain() function to test yourgame()function.

For Coderunner, paste yourTeam andPlayer classes and their implementations, and yourgame function. (Submit what you did for Problems 2 and 3,and add your game function.)Do not include yourmain() function from gameDriver.cpp that you used for testing your function.

5. Homework 8 checklist

  1. Submit one zip file to Homework 8 (File Submission). The zip file should be named,<firstName>_<lastName>_hmwk8.zip., and have following 8 files:

    1. shuffle.cpp

    1. Player.h

    1. Player.cpp

    1. playerDriver.cpp

    1. Team.h

    1. Team.cpp

    1. teamDriver.cpp

    1. gameDriver.cpp

      1. Homework 8 point summary

* If your attendance is not recorded, you will lose points.

Make sure your attendance is recorded on Moodlebefore you leave recitation.

Starting Computing Homework 8
$24.99 $18.99