Exemple #1
0
long CalcOptions::onInitDialog()
{
	::CopyMemory(&normalFmt, &_normalFmt, sizeof(CHARFORMAT));
	::CopyMemory(&resultFmt, &_resultFmt, sizeof(CHARFORMAT));
	::CopyMemory(&errorFmt, &_errorFmt, sizeof(CHARFORMAT));

	// fill angle mode combo box
	::SendDlgItemMessage(_hDlg, IDC_ANGLE_MODE, CB_ADDSTRING, 0, (LPARAM)"Degrees");
	::SendDlgItemMessage(_hDlg, IDC_ANGLE_MODE, CB_ADDSTRING, 0, (LPARAM)"Radians");
	::SendDlgItemMessage(_hDlg, IDC_ANGLE_MODE, CB_ADDSTRING, 0, (LPARAM)"Gradians");

	// fill mem view format combo box
	::SendDlgItemMessage(_hDlg, IDC_MEMVIEW_FORMAT, CB_ADDSTRING, 0, (LPARAM)"Decimal");
	::SendDlgItemMessage(_hDlg, IDC_MEMVIEW_FORMAT, CB_ADDSTRING, 0, (LPARAM)"Hex");
	::SendDlgItemMessage(_hDlg, IDC_MEMVIEW_FORMAT, CB_ADDSTRING, 0, (LPARAM)"Octal");
	::SendDlgItemMessage(_hDlg, IDC_MEMVIEW_FORMAT, CB_ADDSTRING, 0, (LPARAM)"Binary");

	if(getAlwaysOnTop()) ::CheckDlgButton(_hDlg, IDC_ALWAYS_ON_TOP, BST_CHECKED);
	if(getMemVisible()) ::CheckDlgButton(_hDlg, IDC_MEM_VISIBLE, BST_CHECKED);
	if(getCopyResult()) ::CheckDlgButton(_hDlg, IDC_COPY_RESULT, BST_CHECKED);
	::SendDlgItemMessage(_hDlg, IDC_ANGLE_MODE, CB_SETCURSEL, (WPARAM)getAngleMode(), 0L);
	::SendDlgItemMessage(_hDlg, IDC_MEMVIEW_FORMAT, CB_SETCURSEL, (WPARAM)getMemViewFmt(), 0L);
	if(getOutputDec()) ::CheckDlgButton(_hDlg, IDC_OUTPUT_DEC, BST_CHECKED);
	if(getOutputHex()) ::CheckDlgButton(_hDlg, IDC_OUTPUT_HEX, BST_CHECKED);
	if(getOutputOct()) ::CheckDlgButton(_hDlg, IDC_OUTPUT_OCT, BST_CHECKED);
	if(getOutputBin()) ::CheckDlgButton(_hDlg, IDC_OUTPUT_BIN, BST_CHECKED);

	::SetDlgItemInt(_hDlg, IDC_NUM_DIGITS, getNumDigits(), TRUE);
	return TRUE;
}
Exemple #2
0
    int countDigitOne(int n) {
        int result = 0;
        int firstDigit = getFirstDigit(n);
        int numDigits = getNumDigits(n);
        if (numDigits == 1) {
            if (firstDigit >= 1)
                result = 1;
        }
        else if (numDigits > 1) {
            int remainder = n - firstDigit*pow(10, numDigits-1);

            for (int k = 1; k < numDigits; k++)
                result += numOneInNDigitNumbers(k);
            
            if (firstDigit > 1) {
                int sum = 0;
                for (int k = 1; k < numDigits; k++)
                    sum += numOneInNDigitNumbers(k);
                result += pow(10, numDigits-1)+(firstDigit-1)*sum;
            }
            else
                result += remainder+1;

            result += countDigitOne(remainder);
        }
        return result;
    }
Exemple #3
0
/**********************************************************************************************************************
 * Function    : intToString											      *
 * Inputs      : int integer. Receives the integer to be converted to string.					      *
 * Outputs     : N/A												      *
 * Return      : char *. Reference to the string obtained after the conversion.					      *
 * Description : This is the function required by the exercise (see excersie description).			      *
 *               												      *
 **********************************************************************************************************************/
char *intToString(int integer) {

  bool negative = false;
  unsigned short i,
    num_len = 0;
  char *outstring = NULL;
  
  /* Exctract the sign of the integer         */
  negative = getSign(&integer);

  /* Calculate the required length            */
  num_len = getNumDigits(&integer) + 1;
  if(negative)
    num_len++;

  /* Allocate memory space for the string     */
  outstring = (char *)malloc(num_len*sizeof(char));
  if(!outstring) {
    printf("Error! Unable to allocate memory for \"outstring\".\n");
    return NULL;
  }

  i = 0;
  /* Prefix negative sign when required       */
  if(negative) {
    *(outstring + i++) = '-';
  }
  /* Fore each digit, get the digit character */
  while(i < num_len - 1) {
    *(outstring + i) = (char)getDigit(&integer, num_len - 2 - i);
    i++;
  }
  /* Add string terminator */
  *(outstring + i) = '\0';

  /* Return the result */
  return outstring;
}