int main(){ float num; int member; int yn; char yesno; printf("How much does the meal cost? : "); scanf("%f",&num); if (num>=1000){ printf("Does customer have member card? (y/n)"); scanf(" %c",&yesno); if(yesno == 'y')yn=1; else if(yesno == 'n')yn=0; printf("Sub total (bath): %.2f\n",num); printf("Discount (bath): %.2f\n",num/5); printf("Total (bath): %.2f\n",calculateDiscount(yn,num)); } else{ printf("There is no discount for this promotion\n"); printf("total (bath): %.2f\n",num); } return 0; }
void SimplePhraseTable:: knsmoothing(){ //collect count of count cerr<<"knsmoothing"<<endl; map<string,double> unigram; double unigramTotal=0; vector<double> coc(MAX_DISCOUNT_ORDER-1,0.0); for(auto& outM: *this){ for(auto& item: outM.second){ //item.second.fractype.print(cerr); item.second.fractype.changeLogToReal(); //item.second.fractype.print(cerr); unigram[item.first]+=1-item.second.fractype[0]; unigramTotal+=1-item.second.fractype[0]; for(int i=0;i<MAX_DISCOUNT_ORDER-1;i++) coc[i]+=item.second.fractype[i+1]; } } for(int i=0;i<MAX_DISCOUNT_ORDER-1;i++) cout<<"count of count "<<i+1<<": "<<coc[i]<<endl; //calculate prob for unigram for(auto& item: unigram){ item.second/=unigramTotal; } //calculate discounts vector<double> discount; calculateDiscount(coc,discount); //apply discount, calculate bow for(auto& outM: *this){ double total=0,tdMass=0; for(auto& item: outM.second){ // now, fractype[1]=discount // and fractype[0]=probability this item appearing // fractype[2-3] not defined. item.second.fractype[1]= discountMass(item.second.fractype, discount); item.second.fractype[0]=1-item.second.fractype[0]; total+=item.second.count; tdMass+=item.second.fractype[1]; } double bow=tdMass/total; for(auto& item: outM.second){ // now fractype[2]=backoff weight // fractype[3]=smoothed probability before interpolated item.second.fractype[2]=bow; item.second.fractype[3]= (item.second.count-item.second.fractype[1])/total; item.second.prob=item.second.fractype[3]+bow*unigram[item.first]; item.second.count=0; if(item.second.prob<=0){ //cerr<<outM.first<<" => "<<item.first<<" count: " //<<item.second.count<<", total: "<<total<<endl; item.second.prob=1E-10; } //assert(item.second.prob>0); item.second.fractype.resetToLog(); } } }