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

Please Follow below \'C\' Programming programs set guidelines and write program

ID: 3831781 • Letter: P

Question

Please Follow below 'C' Programming programs set guidelines and write program set below as documented in the detailed instructions below. Thank you so much

****All programs must be written using the VC++ 2015 compiler****

*****PLEASE DOUBLE CHECK TO MAKE SURE PROGRAM COMPILES AND DOES NOT SUFFER RUNTIME ERROR*******

A) Required Items/Software:

Visual C++ 2015 (Visual Studio 2015 Professional or Visual Studio Express 2015)

Capture the output from at least two different test cases (actual output) and either submit a text file or a screen shot of the output in a .doc file.

Textbook: PROGRAMMING IN C, 4th Edition Stephen G Kochan.

Program Documentation Guidelines

• All coding submitted must follow the coding standards found in the textbook and the modifications as specified below. The PROGRAMMING IN C, 4th Edition Stephen G Kochan follows standard C programming coding guidelines and practices good habits learned in beginning programming.

• Every C program should have a leading comment block that identifies the author, course, program number, and any references used.

All programs/projects must have leading comment header that looks similar to below:

// Author: James Bond

// Course: COSC 1420

// Program 2

// References:

• If code is borrowed from other sources- cite it in comments (references). In programming one does not always have to "reinvent the wheel" each time you program. One should however, understand the code and give credit where it is found.

• In a Visual C++ console program, if the output window closes quickly add the following statement as the last statement in the main() function:

cin.get(); //Hold the output window

• When creating your project in VC++ make sure you select an empty project. Otherwise, the IDE will add additional code that will likely not let your program compile.

• Do not include the following directive:

#include "stdafx.h"

This will cause the program to not compile when grading. See previous bullet. • In Visual C++, to use scanf()/printf() properly add the following directive before the #include statement (top of the program, first line):

#define _CRT_SECURE_NO_WARNINGS //add this line #include

• Enter file name from the keyboard:

FILE *fp; char file[MAX];

printf("Enter the name of the file to be opened: ");

scanf("%s", file);

if ((fp = fopen(file, "r")) == NULL) {

fprintf(stderr,"Can't open %s file. ", file); exit(1); }

PROGRAM QUESTION

In the past two decades, professional baseball has been revolutionized by using statistics to analyze player and team performance. The driving force behind this movement was Bill James, whose most famous innovation is the Pythagorean Winning Percentage, which predicts the winning percentage of a team based on how many runs they score and how many they allow:

expectedWinPercentage = runsScored2 / (runsScored2 + runsAllowed2)


You are to write a C program when executed, should prompt the user for the number of runs scored and runs allowed for a team, then calculate the expected winning percentage using James' formula. It should display this percentage, along with the projected record for the team over a 162-game season. Wins and losses should be rounded to the nearest integer. One user-defined function must be used. Output should look similar to below.

Sample Run:
Enter the number of runs scored:

649 Enter the number of runs allowed: 577

The expected winning percentage is 0.5585257183774681

Over a full season, that projects to 90-72


Name the program: BBWinPercentageXX.c, where XX are your initials.

Explanation / Answer

#include<iostream>

#include <string>

#include <math.h>

using namespace std;

#define TOTAL_MATCHES 162

typedef long double BIG_FLOAT;

int RoundToNearest(BIG_FLOAT win_per)

{

return floor( win_per + 0.5);

}

long double ExpectedWinPercentage(int runsScored, int runsAllowed)

{

BIG_FLOAT sum = runsScored + runsAllowed;

return ((BIG_FLOAT)runsScored)/(BIG_FLOAT)(sum);

}

void main()

{

int runsScored=0;

int runsAllowed=0;

cout<<"Enter the number of runs scored:";

cin>>runsScored;

cout<<"Enter the number of runs allowed:";

cin>>runsAllowed;

BIG_FLOAT win_per = ExpectedWinPercentage(runsScored, runsAllowed);

cout<<" The expected winning percentage is "<<win_per;

int total_wins = RoundToNearest(win_per*TOTAL_MATCHES);

int total_loss = TOTAL_MATCHES- total_wins;

cout<<"Over a full season that projects to "<<total_wins<<"-"<<total_loss;

cin.get();

}