Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third as

ID: 3587699 • Letter: C

Question

CSCI 24000- Fall 2017 Assignment #3-Class-v Players Due: 10/9/2017 This third assignment will allow you to explore (by comparing and contrasting through construction and implementation) two different object-oncnted programmanlanguages (C++ and Javal You will be creating tme scparate programs-onc written in C++ and on written in Java For this assignment, we are going to explore how we can use objects to build more expressive and cleaner programs. In honor of football season we are going to be creating Players for our IUPUI football team Undefeated since 1969). We will need to create and stoee these Players in memory and allow the user to view an entire "roster" of Players. We will make the following assumpcions No two Players will have the same name (eg.,Test Testerson. "2 Test Teserson). No two Players can have the same number (eg.. #, Jane Testrson·#2 Jame Testerson). Each Player MUST have at-least a first name, last name, and jersey Bumber * *In the basic submission there will only be, at maximum, eleven(11) Players on our icam Your goal is to create a peogram that will allow for creation and viewing of Players from our Team. Development Process: For this assignment, all development must take place on the master branch in a private GitHub repository. You must add me and all four (4) TAs as collaborators to your repository, It is stronglhy recommended that you commit and push often! We will be chocking to make sure that you are actively pushing changes to your repository-failure to do so will result in a deduction of points We will also be checking that you are providing "useful" comments with your commits-failure to do so will result in a deduction of ports. You are also required to include the Honor Ple ge and Digital Signature each one of your files (any file that you have writtien "code" in-you nood to include the Honor Pledge and Digital Signature). You are required to implement the following items as part of this assignment: .Your C++program mast contain three files (2.qpp and 1 h file). These files should be mamed as such: Driver.cpp, Player.cpp, Player.h .Your Java program must contain the following two files: Driverjava and Player.java * Array on the Heap Your Driver class must store any and all created Players in This Amay must make use of dynamic memory allocation. to manage our memory accordingly-nommory o You can use Valgrind to check our program for memory leaks- any leaks in memory will result in a deduction of points. When you start the program, you should provide the user with a menu choice to do one of the * . Add New Player 2 View Players 3. Exit Program Upon completion of Options #1 or #2 the menu should once again be displayed to the user . thus allowing them to make another selection. This process should continue to loop unil the user selections Option 3. Once'lf eleven (11) Players have been entered the program should print the roster and terminate * Below is example output of what your prog this exactly when executed-your format must match 1 of 3

Explanation / Answer

in C++

#include <stdio.h>

#include <math.h>

#define MAXgames 13

#define dataFile "offense9.txt"

//functions

int openANDread(int player[], int games[], int rush[], int pass[]);

void dispTitlesAndColumns();

void dispDashes();

int displayStats(int player[], int games[], int rush[], int pass[], int count, int totalYds[], double ydsPGame[]);

int maxRush(int player[], int rush[], int n);

int maxPass(int player[], int pass[], int n);

int maxGames(int games[], int n);

int positionMax(int x[], int n);

int dispTotals(int games[], int rush[], int pass[], int num);

int main()

{

//arrays initialized

int player[MAXgames];

int games[MAXgames];

int rush[MAXgames];

int pass[MAXgames];

int totalYds[MAXgames];

double ydsPGame[MAXgames];

int count;

//all functions used

  

openANDread(player, games, rush, pass);

dispTitlesAndColumns();

dispDashes();

displayStats(player, games, rush, pass, count, totalYds, ydsPGame);

dispTotals(games, rush, pass, count);

dispDashes();

maxRush(player, rush, count);

maxPass(player, pass, count);

}

int openANDread(int player[], int games[], int rush[], int pass[])

{//read datafile into arrays and return count

int count = 0;

int i = 0;

FILE *infile;

infile = fopen(dataFile, "r");

if (infile == NULL)

printf("Error Opening File. Program Terminated");

else

{

while (fscanf( infile, "%d %d %d %d", &player[i], &games[i], &rush[i], &pass[i]) != EOF)

{

i +=1;

count += 1;

}

}

fclose(infile);

return count;

}

void dispTitlesAndColumns()

{//simply print headings

printf(" 2008 Auburn Football "

" Auburn Overall Individual Statistics "

" (All Games as of Nov 01, 2008) "

"Player Games Yards Yards Total Yards/ "

" No. Played Rushing Passing Yards Game ");

}

void dispDashes()

{//dashes

printf("------ ------ ------- ------- ----- ----- ");

}

int displayStats(int player[], int games[], int rush[], int pass[], int count, int totalYds[], double ydsPGame[])

{//getting and displaing the arrays totalYds and ydsPGame

int i = 0;

while( i < count, i++)

{

printf("hello");

totalYds[i] = rush[i] + pass[i];

ydsPGame[i] = (pass[i] + rush [i])/games[i];

printf(" %d %d %d %d %d %f", player[i], games[i], rush[i], pass[i], totalYds[i], ydsPGame[i]);

}

}

int maxRush(int player[], int rush[], int n)

{

printf("Most Rushing Yards: %d by Player #%d", rush[positionMax(rush, n)], player[positionMax(rush, n)]);

}

int maxPass(int player[], int pass[], int n)

{

printf("Most Rushing Yards: %d by Player #%d", pass[positionMax(pass, n)], player[positionMax(pass, n)]);

}

int maxGames(int games[], int n)

{

int k;

int maxGame = -99999999;

for (k=1; k < n; k++)

{

if (games[k] > maxGame)

maxGame = games[k];

}

return maxGame;

}

int positionMax(int x[], int n)

{

int k;

int max = -99999999;

int maxPos = 0;

for (k=1; k < n; k++)

{

if (x[k] > max)

max = x[k];

k = maxPos;

}

}

int dispTotals(int games[], int rush[], int pass[], int num)

{

int maxGame = 0;

int totalRush = 0;

int totalPass = 0;

int totalYds = 0;

int totalYdsPGame;

int i;

maxGame = maxGames(games, num);

while(i < num, i++)

{

totalRush += rush[i];

totalPass += pass[i];

}

totalYds = totalRush + totalPass;

totalYdsPGame = totalYds / maxGame;

printf("Total %d %d %d %d %d", maxGame, totalRush, totalPass, totalYds, totalYdsPGame);

}

in JAVA

package football;

import javax.swing.JFrame;

/**
Displays a pie chart.
*/
public class Main
{
public static void main(String[] args)
{
JFrame frame = new JFrame();

final int FRAME_WIDTH = 1000;
final int FRAME_HEIGHT = 1000;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("Football");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Component component = new Component();
frame.add(component);

frame.setVisible(true);
}
}