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

7) Write a function that will return in a structure the following characteristic

ID: 3758329 • Letter: 7

Question

    
 7)  Write a function that will return in a structure the following characteristics of a given string:            1) string length (use strlen),                 2) number of upper case characters         3) number of lower case characters,                 4) number of digits 
         5) number of blank spaces 
    
         6) number of non-alphanumeric characters. 
   8)  Write a program to compute various offensive statistics on baseball.   The following information 
       will be available on each player: 
           Number of Walks (BB), Strike Outs (SO), Hit by Pitch (HP), Sac Flys (SF), Singles,  
           Doubles (2B), Triples (3B), and Home Runs (HR) as well as Number of At Bats (AB).       Based on this information, develop a set of functions within your program that will compute the following:            Total Bases, Batting Average, Home Run Ratio, Strike Out Ratio, On Base Percentage, and Slugging Average.       You do not need to be a baseball fan to do this ... All the information you need in       terms of the formulas and explanations can be found at:             http://www.baseball-almanac.com/stats.shtml       Note:  Number of hits is:  singles + doubles + triples + home runs        If you want to check your work, see compiled stats of the 2014 Boston Red Sox at:  http://www.baseball-reference.com/teams/BOS/2014.shtml 

Explanation / Answer

7.

#include <stdio.h>
#include <string.h>
#include<ctype.h>
struct info
{
long length;
int upper_case;
int lower_case;
int digits;
int non_alphanumeric;
};
void string_info (struct info s_info[], char string []);

int main()
{
struct info s_info [1];

char string [40];

printf("Please enter a string: ");
scanf("%s", & string);

string_info (s_info, string);

return(0);
}
void string_info (struct info s_info[], char string [])
{
int i;
s_info.length = strlen(string);
for (i = 0; i < strlen(string); ++i)
{
s_info.upper_case += (isupper(string[i])) ? 1 : 0;
s_info[i].lower_case+ =( islower(string[i])) ?1:0 ;
s_info[i].digits += (isdigit(string[i]))?1:0;
s_info[i].non_alphanumeric+=(isalnum(string[i]))? 1:0;
}
printf(" The length of the string is %li: ", s_info[i].length);
printf(" The number of upper case letters in the string is %i: ", s_info[i].upper_case);
printf(" The number of lower case letters in the string is %i: ", s_info[i].lower_case);
printf(" The number of digits in the string is: %i ", s_info[i].digits);
printf(" The number of alphanumeric in the string is: %i ", s_info[i].non_alphanumeric);
printf(" The number of non-alphanumeric is :%d",s_info[i].length-s_info[i].non_alphanumeric);
}

8.

struct player

{
char first_name [10];
char last_name [10];
int at_bats;
int singles;
int doubles;
int triples;
int home_runs;
int total_bases;
float batting_avg;
float home_run_ratio;
float slugging_avg;

struct player *next;
};

void myBaseBallStats (struct player *plyr1);
void print_list (struct player *plyr1);

int main()
{

char answer[80];
int more_data = 1;
char value;

struct player *current_ptr,
*head_ptr;

head_ptr = (struct player *) malloc (sizeof(struct player));
current_ptr = head_ptr;

while (more_data)
{
printf("Please enter the players first name: ");
scanf("%s", & current_ptr ->first_name);

printf("Please enter the players last name: ");
scanf("%s", & current_ptr ->last_name);

printf(" How many at bats did the player have: ");
scanf("%i", & current_ptr ->at_bats);

printf(" How many singles did the player have: ");
scanf("%i", & current_ptr ->singles);

printf(" How many doubles did the player have: ");
scanf("%i", & current_ptr ->doubles);

printf(" How many triples did the player have: ");
scanf("%i", & current_ptr ->triples);

printf(" How many home runs did the player have: ");
scanf("%i", & current_ptr ->home_runs);

printf(" Would you like to add another employee? (y/n): ");
scanf("%s", answer);

if ((value = toupper(answer[0])) != 'Y')
{
current_ptr->next = (struct player *) NULL;
more_data = 0;
}
else
{
current_ptr->next = (struct player *) malloc (sizeof(struct player));
current_ptr = current_ptr->next;
}
}

myBaseBallStats(head_ptr);

print_list(head_ptr);

printf(" End of program ");

return (0);
}

void myBaseBallStats (struct player *plyr1)
{

struct player *tmp;
int i = 0;
int num_hits;
for (tmp = plyr1; tmp ; tmp = tmp->next)
{
i++;

num_hits = (tmp ->singles + tmp ->doubles + tmp ->triples + tmp ->home_runs);

tmp ->total_bases = (tmp ->singles + (2 * tmp ->doubles) + (3 * tmp ->triples) + (4 * tmp ->home_runs));

tmp ->batting_avg = (num_hits / tmp ->at_bats);

tmp ->home_run_ratio = (tmp ->home_runs / tmp ->at_bats);

tmp ->slugging_avg = ((tmp ->singles + (2 * tmp ->doubles) + (3 * tmp ->triples) + (4 * tmp ->home_runs)) / tmp ->at_bats);

}

}
void print_list (struct player *plyr1)
{
printf( the number of hits is :%d",num_hits);

printf( the number of total bases is :%d",total_bases);

printf( the batting average is :%d",batting_avg);

printf( the home run ratio is :%d",home_run_ratio);

printf( the slugging average is :%d",slugging_avg);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote