Rewrite the C program below to a C program include include
Rewrite the C program below to a C++ program.
---------------------------------------------------------------------------------
#include<string.h>
#include<stdio.h>
#include<math.h>
#define size 9
int main()
{
char name[10][size]; /*Player Name*/
int hits[size],atbat[size]; /*Number of Hits and at Bat*/
float avg[size]; /*Batting Average of Player*/
int i,j=0;
printf(\"\ BATTING AVERAGE CALCULATION OF EACH PLAYER\ \");
printf(\"\ Please enter data of player\ \");
/*Reading the Player Name, the Number of Hits and at Bats */
for(i=0;i
{
j=i;
printf(\"\ Player %d-->\",j+1);
printf(\"\ Name:\");
scanf(\"%s\",name[i]);
printf(\"Hits:\");
scanf(\"%d\",&hits[i]);
printf(\"AtBat:\");
scanf(\"%d\",&atbat[i]);
}
/*Calculating the Batting Average */
for(i=0;i
{
avg[i]= ((float)hits[i]/(float)atbat[i]);
}
printf(\"\ SUMMARY OF EACH PLAYER\ \");
printf(\"NAME\\tHITS\\tATBATS\\tBATTING AVG\ \");
/*
* Printing the Name, the Number of Hits, the Number of times
* at bats, and the batting average of the each Player
*/
for(i=0;i
{
printf(\"%s\\t%d\\t%d\\t%f\",name[i],hits[i],atbat[i],avg[i]);
printf(\"\ \");
}
return(0);
}
Solution
solution
#include<string.h>
 #include<stdio.h>
 #include<math.h>
 #define size 9
 
 int main()
 {
 char name[10][size]; /*Player Name*/
 int hits[size],atbat[size]; /*Number of Hits and at Bat*/
 float avg[size]; /*Batting Average of Player*/
 int i,j=0;
 printf(\"\ BATTING AVERAGE CALCULATION OF EACH PLAYER\ \");
 printf(\"\ Please enter data of player\ \");
 
 /*Reading the Player Name, the Number of Hits and at Bats */
 for(i=0;i<size;i++)
 {
 j=i;
 printf(\"\ Player %d-->\",j+1);
 printf(\"\ Name:\");
 scanf(\"%s\",name[i]);
 printf(\"Hits:\");
 scanf(\"%d\",&hits[i]);
 printf(\"AtBat:\");
 scanf(\"%d\",&atbat[i]);
 }
 
 /*Calculating the Batting Average */
 for(i=0;i<size;i++)
 {
 avg[i]= (hits[i]/atbat[i]);
 }
 printf(\"\ SUMMARY OF EACH PLAYER\ \");
 printf(\"NAME\\t\\t\\tHITS\\tATBATS\\tBATTING AVG\ \");
 
 /*
 * Printing the Name, the Number of Hits, the Number of times
 * at bats, and the batting average of the each Player
 */
 for(i=0;i<size;i++)
 {
 printf(\"%s\\t\\t\\t%d\\t%d\\t%0.2f\",name[i],hits[i],atbat[i],avg[i]);
  printf(\"\ \");
 }
 return(0);
 }
output
 BATTING AVERAGE CALCULATION OF EACH PLAYER
Please enter data of player
Player 1-->
 Name:john
 Hits:45
 AtBat:2
Player 2-->
 Name:68
 Hits:12
 AtBat:2
Player 3-->
 Name:ramu
 Hits:654
 AtBat:2
Player 4-->
 Name:adam
 Hits:65
 AtBat:2
Player 5-->
 Name:anand
 Hits:2
 AtBat:3
Player 6-->
 Name:anil
 Hits:56
 AtBat:23
Player 7-->
 Name:amul
 Hits:256
 AtBat:3
Player 8-->
 Name:ashok
 Hits:25
 AtBat:2
Player 9-->
 Name:aravind
 Hits:21
 AtBat:1
SUMMARY OF EACH PLAYER
 NAME HITS ATBATS BATTING AVG
 john 45 2 22.00
 68 12 2 6.00
 ramu 654 2 327.00
 adam 65 2 32.00
 anand 2 3 0.00
 anil 56 23 2.00
 amul 256 3 85.00
 ashok 25 2 12.00
 aravind 21 1 21.00
--------------------------------




