--- loncom/homework/caparesponse/caparesponse.c 2004/03/12 23:46:06 1.13 +++ loncom/homework/caparesponse/caparesponse.c 2004/11/16 23:37:40 1.14 @@ -1,6 +1,6 @@ /* The LearningOnline Network with CAPA * CAPA wrapper code - * $Id: caparesponse.c,v 1.13 2004/03/12 23:46:06 albertel Exp $ + * $Id: caparesponse.c,v 1.14 2004/11/16 23:37:40 albertel Exp $ * * Copyright Michigan State University Board of Trustees * @@ -124,3 +124,58 @@ int caparesponse_capa_check_answer(char return result; } + +int caparesponse_get_real_response (char* unit_str, char* answer, + double* scaled) { + //double caparesponse_get_real_response (char* unit_str, char* answer) { + int input_len,all_alphabet,idx,outcome,result; + double n_part,scale=1.0,given,target; + char input[ANSWER_STRING_LENG],filename[FILE_NAME_LENGTH]; + Unit_t *ans_unit; + long seed1,seed2; + FILE *fp; + sprintf(filename,"/home/httpd/html/res/adm/includes/capa.units"); + if ((fp=fopen(filename,"r"))==NULL) { + /* printf("Error: can't open %s\n",filename);*/ + return (-1); + } + u_getunit(fp); + fclose(fp); + + if (unit_str != NULL && unit_str[0]!='\0') { + ans_unit = u_parse_unit(unit_str); + } else { + ans_unit=NULL; + } + input_len = strlen(answer); + all_alphabet = 1; + for(idx=0;idx 1 ) { /* with both num and unit parts or only unit part */ + if( ans_unit != NULL ) { + result = check_correct_unit(unit_str,ans_unit,&scale); + } else { + /* what to do when no unit is specified but student entered a unit? */ + result = UNIT_NOTNEEDED; + } + } else { + if( ans_unit != NULL ) { + result = NO_UNIT; + } + } + if( (result != NO_UNIT) && (!check_for_unit_fail(result)) && ( result != UNIT_NOTNEEDED) ) { + given = n_part * scale; + *scaled=given; + /* convert the given answer into proper scale for units */ + } /* end if unit check */ + } else { /* user entered a +lphabet, but no number */ + result = WANTED_NUMERIC; + } + return result; +}