Example #1
0
// print statistics summary report ========================================================== 
void printSummary( char code[], int gameStats[][NUMCOLS], double hours[], int numGames ) 
{ 
   int g; 
   int arraySec[NUMSEC][NUMCOLS], extra[MAXGAMES]; 
   int numSecGames, numExtra; 
   int minRuns, maxRuns; 
   double aveRuns; 
   
   printf( "       2015 AU Softall Summary\n" ); 
   printf( "                 #games Min Mean Max\n" ); 
   
   // all games runs 
   // max/mean/min AU runs scored: all, with # of games
    
   printf( "Runs scored-all    %2d  %2d  %4.1f  %2d\n", numGames,intColMin(gameStats,numGames,AU_COL), 
         intColMean(gameStats,numGames,AU_COL),intColMax(gameStats,numGames,AU_COL) );
         
    // max/mean/min runs allowed: all 
    
   printf( "Runs allowed-all       %2d  %4.1f  %2d\n", intColMin(gameStats,numGames,OPP_COL),
       intColMean(gameStats,numGames,OPP_COL),intColMax(gameStats,numGames,OPP_COL) ); 
       
  // SEC games runs 
  // get the Auburn runs for the SEC game 
  
  numSecGames = getSecGames( code, gameStats, numGames, arraySec ); 
  
  // max/mean/min AU runs scored: SEC, with # of games 
  
  printf( "Runs scored-SEC    %2d  %2d  %4.1f  %2d\n", numSecGames,intColMin(arraySec,numSecGames,AU_COL), 
      intColMean(arraySec,numSecGames,AU_COL), intColMax(arraySec,numSecGames,AU_COL) );
      
 // max/mean/min runs allowed: SEC 
 printf( "Runs allowed-SEC       %2d  %4.1f  %2d\n", intColMin(arraySec,numSecGames,OPP_COL), 
      intColMean(arraySec,numSecGames,OPP_COL),intColMax(arraySec,numSecGames,OPP_COL) );
      
// game(s) with extra innings; regular game 7 innings 
numExtra = extraInnings( gameStats, numGames, extra ); 
printf( "\nGames with extra innings:\n"); 
if (numExtra > 0 ) 
{ 
   for ( g=0; g<numExtra; g++ ) 
   { 
      printf( " %d", extra[g] );
   } 
   // end for g 
   printf( "\n" );
 } // if numExtra 
 else 
 {
    printf( "none\n" ); 
} // end else 
// longest game for all and SEC 
printf( "\nLongest game played: %.2f hours\n", doubleMax( hours, numGames ) );
Example #2
0
Symbolhandle    rangen(Symbolhandle list)
{
	Symbolhandle    result = (Symbolhandle) 0, symhN, symhParam1, symhParam2;
	long            sampleSize, lengthParam1, lengthParam2;
	long            op, verbose = 1;
	long            nargs = NARGS(list), margs;
	char           *what1, *what2;
	char           *badarg = "argument %ld (%s) to %s()";
	char           *badParam =
	  "ERROR: argument %ld to %s() (%s) not REAL scalar or vector";
	char           *hasMissing =
	  "ERROR: argument %ld to %s() (%s) has 1 or more MISSING values";
	char           *badLength =
	  "ERROR: length of vector argument %ld to %s() (%s) differs from sample size";
	WHERE("rangen");
	
	/* generate a list of random numbers */
	if (strcmp(FUNCNAME, "rnorm") == 0)
	{
		op = IRNORM;
	}
	else if (strcmp(FUNCNAME, "rpoi") == 0)
	{
		op = IRPOI;
		what1 = "mean";
	}
	else if (strcmp(FUNCNAME, "rbin") == 0)
	{
		op = IRBINOM;
		what1 = "n";
		what2 = "p";
	}
	else
	{
		op = IRUNI;
	}
	margs = (op == IRBINOM) ? 3 : ((op == IRPOI) ? 2 : 1);
	
	OUTSTR[0] = '\0';
	
	if (nargs != margs)
	{
		badNargs(FUNCNAME, margs);
		goto errorExit;
	}
	
	symhN = COMPVALUE(list,0);

	if (!isInteger(symhN, POSITIVEVALUE))
	{
		char    outstr[30];
		
		sprintf(outstr, badarg, 1L, "sample size", FUNCNAME);
		notPositiveInteger(outstr);
		goto errorExit;
	} /*if (!isInteger(symhN, POSITIVEVALUE))*/

	sampleSize = (long) DATAVALUE(symhN,0);

	if (margs > 1)
	{
		symhParam1 = COMPVALUE(list, 1);
		if (!argOK(symhParam1, 0, 2))
		{
			goto errorExit;
		}
		lengthParam1 = symbolSize(symhParam1);
		if (TYPE(symhParam1) != REAL || !isVector(symhParam1))
		{
			sprintf(OUTSTR, badParam, 2L, what1, FUNCNAME);
		}
		else if (anyMissing(symhParam1))
		{
			sprintf(OUTSTR, hasMissing, 2L, what1, FUNCNAME);
		}
		else if (lengthParam1 > 1 && lengthParam1 != sampleSize)
		{
			sprintf(OUTSTR, badLength, 2L, what1, FUNCNAME);
		}
		else if (margs > 2)
		{
			symhParam2 = COMPVALUE(list, 2);
			if (!argOK(symhParam2, 0, 3))
			{
				goto errorExit;
			}

			lengthParam2 = symbolSize(symhParam2);
			if (TYPE(symhParam2) != REAL || !isVector(symhParam2))
			{
				sprintf(OUTSTR, badParam, 3L, what2, FUNCNAME);
			}
			else if (anyMissing(symhParam2))
			{
				sprintf(OUTSTR, hasMissing, 3L, what2, FUNCNAME);
			}
			else if (lengthParam2 > 1 && lengthParam2 != sampleSize)
			{
				sprintf(OUTSTR, badLength, 3L, what2, FUNCNAME);
			}
		}

		if (*OUTSTR)
		{
			goto errorExit;
		}
		
		if (op == IRPOI)
		{
			/*rpoi(lambda)*/
			if (doubleMin(DATAPTR(symhParam1), lengthParam1) < 0.0)
			{
				sprintf(OUTSTR,
						"ERROR: argument 2 (%s) to %s() has negative element",
						what1, FUNCNAME);
			}
		}
		else if (op == IRBINOM)
		{
			/*rbinom(samplesize,n,p)*/
			long        i;
			double     *n = DATAPTR(symhParam1);

			for (i = 0; i < lengthParam1; i++)
			{
				if (n[i] < 1 || n[i] != floor(n[i]))
				{
					sprintf(OUTSTR,
							"ERROR: not all elements of argument 2 (%s) to %s() are positive integers",
							what1, FUNCNAME);
					goto errorExit;
				}
			} /*for (i = 0; i < lengthParam1; i++)*/

			if (doubleMin(DATAPTR(symhParam2), lengthParam2) < 0.0 ||
					 doubleMax(DATAPTR(symhParam2), lengthParam2) > 1.0)
			{
				sprintf(OUTSTR,
						"ERROR: argument 3 (%s) to %s() has value < 0 or > 1",
						what2, FUNCNAME);
			}
		} /*else if (op == IRBINOM)*/

		if (*OUTSTR)
		{
			goto errorExit;
		}
	} /*if (margs > 1)*/

	if (Rands1 == 0 && Rands2 == 0)
	{
		randomSeed(verbose);
	} /*if (Rands1 == 0 && Rands2 == 0)*/

	result = RInstall(SCRATCH, sampleSize);
	if (result != (Symbolhandle) 0)
	{
		switch (op)
		{
		  case IRUNI:
			vuni(sampleSize, DATAPTR(result));
			break;
		  case IRNORM:
			vnorm(sampleSize, DATAPTR(result));
			break;
		  case IRPOI:
			vpoi(sampleSize, DATAPTR(symhParam1), lengthParam1,
				 DATAPTR(result));
			break;
		  case IRBINOM:
			vbinom(sampleSize, DATAPTR(symhParam1), lengthParam1,
				   DATAPTR(symhParam2), lengthParam2, DATAPTR(result));
			break;
		} /*switch (op)*/
	} /*if (result != (Symbolhandle) 0)*/

	return (result);

  errorExit:
	putErrorOUTSTR();

	return (0);
	
} /*rangen()*/
Example #3
0
static void testcode (void)
{
	int result1;
	int correct_answer1;
	int *result2;

	int c = 56;

	printf ("ICS 51, Lab 1 \nName:      %s\nStudentID: %s\n\n", 
	  yourName, yourStudentID);

  /* Once you are done implementing the functions, activate one or more of
     the following test sequences.
     Procedure to activate a single test sequence:
         replace 
              #define TESTPART1_1 0
         with
              #define TESTPART1_1 1
  */

	#define TESTPART1_1 1
	#define TESTPART1_2 1
	#define TESTPART1_3 1

	#define TESTPART2_1 1
	#define TESTPART2_2 1
	#define TESTPART2_3 1
	#define TESTPART2_4 1

	printf( "\nTesting part I \n" );
	#if TESTPART1_1
		result1 = swapBits(0xAAAAAAAA);
		correct_answer1 = 0x55555555;
		printf( "Input = 0x%08X, Output = 0x%08X - %s\n", 0xAAAAAAAA, result1, result1==correct_answer1 ? "CORRECT": "INCORRECT" );
	#endif

	#if TESTPART1_2
		result1 = swapBits(43);
		correct_answer1 = 23;
		printf( "Input = 0x%08X, Output = 0x%08X - %s\n", 43, result1, result1==correct_answer1 ? "CORRECT": "INCORRECT" );
	#endif

	#if TESTPART1_3
		result1 = swapBits(0x12345678);
		correct_answer1 = 0x2138A9B4;
		printf( "Input = 0x%08X, Output = 0x%08X - %s\n", 0x12345678, result1, result1==correct_answer1 ? "CORRECT": "INCORRECT" );
    #endif


	printf( "\nTesting part II \n" );
	#if TESTPART2_1
		result2 = (int*) malloc(sizeof(int));
		doubleMax(1,2,3,result2);
		printf( "Input = %d, %d, %d, Output = %d\n", 1, 2, 3, *result2 );
		free(result2);
	#endif

	#if TESTPART2_2
		result2 = (int*) malloc(sizeof(int));
		doubleMax(4,2,7,result2);
		printf( "Input = %d, %d, %d, Output = %d\n", 4, 2, 7, *result2 );
		free(result2);
	#endif

	#if TESTPART2_3
		result2 = (int*) malloc(sizeof(int));
		doubleMax(3,2,1,result2);
		printf( "Input = %d, %d, %d, Output = %d\n", 3, 2, 1, *result2 );
		free(result2);
	#endif

	#if TESTPART2_4
		result2 = (int*) malloc(sizeof(int));
		doubleMax(-50,2,-100,result2);
		printf( "Input = %d, %d, %d, Output = %d\n", -50, 2, -100, *result2 );
		free(result2);
	#endif

	printf( "\n\n" );
}