Пример #1
0
int main(int argc, char ** argv) {
  char * secID;
  time_t t;

  unsigned int pagesize=getpagesize();
  setbuf(stdout,0);
  retBuffer=(unsigned char *)(((long)retBufferArea + pagesize-1) & ~(pagesize-1));
  if(mprotect(retBuffer, 1024, PROT_READ|PROT_EXEC|PROT_WRITE)) {
    printf("mprotect failed\n");
    return(1);
  }
  if (argc==1) srand((unsigned) time(&t));
  else {
    unsigned int seed=atoi(argv[1]);
    srand(seed);
  }
  getGrades(aGrades,ASIZE);
  getGrades(bGrades,BSIZE);
  getAvg(aGrades,ASIZE);
  getAvg(bGrades,BSIZE);

  printf("Choose section A or B: ");
  secID=getUserLine();
  printf("\n");
  
  if (secID[0]=='A') {
    printGrades(aGrades,ASIZE,100);
  } else if (secID[0]=='B') {
    printGrades(bGrades,BSIZE,200);
  } else {
    printf("Unable to determine which section you wanted.\n");
  }
  // free(retBufferArea);
  exit(0);
}
Пример #2
0
int main()
{
    bool bPass = false;
    int low = 0, high = 0;    //length of dynamic array

    std::cout << "Grade Program\n\n";

    while ( bPass != true )
    {
        std::cout << "Please enter the high grade for the class (int): ";
        getValidInput(high);
        if ( high < 0 )
        {
            std::cout << "This is below the low grade.  ";
        }
        else
        {
            bPass = true;
        }
    }


    int *arrGrades = new int[abs(high - low)+1];   //declare dynamic array

    for ( int i = 0 ; i <= high ; i++ )
    {
        arrGrades[i] = 0;
    }

    getGrades(high, arrGrades);

    for ( int i = 0 ; i <= abs(high - low) ; i++ )
    {
        std::cout << arrGrades[i] << " grade(s) of " << i << std::endl;
    }

    delete [] arrGrades;     //clear memory

    return 0;
}