Esempio n. 1
0
int SimulatedFSM::calculate(int floor, int type)
{
  insert_order(floor, type);
  int step = 0;
  if (state.door_open)
    step++;
  while (!at_floor(floor))  {
    LOG(5, "dir=" << (int)state.direction << " floor=" << state.current_floor
	<< "state=" << (int)state.state_id);
    if (state.state_id == MOVING) {
      if (step > 0 && should_stop(state.current_floor)) {
	state.state_id = STOPPED;
	step++;
	continue;
      }
    }
    else {
      state.state_id = MOVING;
    }

    if (state.direction == Direction::UP) {
      if (floors_above()) {
	state.current_floor++;
	step++;
      }
      else if (floors_below()) {
	state.direction = Direction::DOWN;
	state.current_floor--;
	step++;
      }
    }
    else if (state.direction == Direction::DOWN) {
      if (floors_below()) {
	state.current_floor--;
	step++;
      }
      else if (floors_above()) {
	state.direction = Direction::UP;
	state.current_floor++;
	step++;
      }
    }
  }
  return step;
}
Esempio n. 2
0
int CTdManager::limit_order_insert(const char* ins_id, char action_direct, char open_flag, double price, int quantity)
{
	CThostFtdcInputOrderField order_limit;
	memset(&order_limit, 0x00, sizeof(CThostFtdcInputOrderField));
	
	strncpy_s(order_limit.InstrumentID, ins_id, sizeof(order_limit.InstrumentID) - 1);
	order_limit.OrderPriceType = THOST_FTDC_OPT_LimitPrice;
	order_limit.Direction = action_direct;
	order_limit.CombOffsetFlag[0] = open_flag;
	order_limit.CombHedgeFlag[0] = THOST_FTDC_HF_Speculation;
	order_limit.LimitPrice = price;
	order_limit.VolumeTotalOriginal = quantity;
	order_limit.TimeCondition = THOST_FTDC_TC_GFD;
	order_limit.VolumeCondition = THOST_FTDC_VC_AV;
	order_limit.ContingentCondition = THOST_FTDC_CC_Immediately;

	return insert_order(order_limit);
}
Esempio n. 3
0
int main()
{
    int i;
    int a[MAX];

    printf("please input 5 num :");
    for(i = 0; i < MAX; i++)
    {
        scanf("%d",&a[i]);
    }
 
    insert_order(a);

    printf("ordering 5 number is :");
    for(i = 0; i < MAX; i++)
    {
        printf("%d  ",a[i]);
    } 
    printf("\n");

    return 0;
}
Esempio n. 4
0
// [Q2 - 5pts]	Write code to capture customerNo, cost, name, address, and item
// into the new created struct Order pointed by ptr.  Assume name, address, and item
// cannot accept any spaces or return characters.  
int insert_update_order_helper(char c) {

	struct Order *ptr = (struct Order *)malloc(sizeof(struct Order));

	/* -- START CODING HERE -- */
	printf("What is the order id? ");
	scanf("%d", &ptr->orderid);

	printf("What is your customer id? ");
	scanf("%d", &ptr->customerNo);

	printf("What is your name? ");
	scanf("%s", ptr->name);

	printf("What is your address? (No spaces) ");
	scanf("%s", ptr->address);

	printf("What is the item? ");
	scanf("%s", ptr->item);

	printf("What is the cost? ");
	scanf("%f", &ptr->cost);

	ptr->next = NULL;
	/* -- END CODING HERE -- */

	if (c == 'i') {
		return insert_order(ptr);
	}
	else {
		int value = update_order(ptr);

		if (value == -1) { printf("No Record Found."); }

		return update_order(ptr);
	}
}