Ejemplo n.º 1
0
int main()
{
	int t;
	FRACTION f1,f2;
	scanf("%d",&t);
	printf("n0\tn1\t+\t-\t*\t/");
	putchar('\n');
	for(int i=0;i<t;++i)
	{
		f1=getFractionFromStream(stdin);
		f2=getFractionFromStream(stdin);
		writeFractionToStream(stdout,f1);
		putchar('\t');
		writeFractionToStream(stdout,f2);
		putchar('\t');
		writeFractionToStream(stdout,addFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,subFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,mulFraction(f1,f2));
		putchar('\t');
		writeFractionToStream(stdout,divFraction(f1,f2));
		putchar('\n');
	}
	return 0;
}
Ejemplo n.º 2
0
/**
 * Return symbolic or numerical representation of n>0
 */
const string positiveSymbolicNumber(double n)
{
    string s;
    faustassert(n>0);

    // Try to find a symbolic representation

    for (int i=1; i<10; i++) {
        for(int j=1; j<10; j++) {
            if (isSymbolicPower(i*n/j,s)) {
                return addFraction(j,i,s);
            }
        }
    }

    // No symbolic representation,
    // Then numerical representation x.10^k

    char tmp[64];
    string entree = " * 10^{";
    char sortie = '}';
    string::size_type ps;

    snprintf(tmp, 63, "%.15g", n); // Warning: over 15 decimals, results are wrong !!
    s = tmp;
    ps = s.find('e');

    if (ps != string::npos) {
        s.replace(ps, 1, "");
        s.insert(ps, entree);
        s += sortie;
    }

    return s;
}
Ejemplo n.º 3
0
int main()
{
    int a;
    fraction_t fraction1,fraction2;
    printf("一つ目の分数の分子、分母を入力してください。\n");
    scanf("%d %d",&fraction1.numerator,&fraction1.denominator);
    printf("二つ目の分数の分子、分母を入力してください。\n");
    scanf("%d %d",&fraction2.numerator,&fraction2.denominator);

    printf("足し算      %2d/%d\n",addFraction(fraction1,fraction2));
    printf("引き算(1-2) %2d/%d\n",subtractFraction(fraction1,fraction2));
    printf("引き算(2-1) %2d/%d\n",subtractFraction(fraction2,fraction1));
    printf("掛け算      %2d/%d\n",multiplyFraction(fraction1,fraction2));
    printf("割り算(1/2) %2d/%d\n",divideFraction(fraction1,fraction2));
    printf("割り算(2/1) %2d/%d\n",divideFraction(fraction2,fraction1));


    return 0;
}
TextFormatButtons::TextFormatButtons(QTextEdit * textEdit, Buttons buttons, QWidget * parent)
: QWidget(parent),
connectedTextEdit(textEdit),
d_buttons(buttons)
{
	QHBoxLayout * layout = new QHBoxLayout(this);
	layout->setMargin(0);
	layout->setSpacing(0);

	QFont font = this->font();
	font.setPointSize(14);

	if (buttons == Legend){
		buttonCurve = new QPushButton( QPixmap(lineSymbol_xpm), QString());
		buttonCurve->setMaximumWidth(40);
		buttonCurve->setMinimumHeight(35);
		buttonCurve->setFont(font);
		layout->addWidget(buttonCurve);
		connect( buttonCurve, SIGNAL(clicked()), this, SLOT(addCurve()) );
	}

	buttonSubscript = new QPushButton(QPixmap(index_xpm), QString());
	buttonSubscript->setMaximumWidth(40);
	buttonSubscript->setMinimumHeight(35);
	buttonSubscript->setFont(font);
	layout->addWidget(buttonSubscript);
	connect( buttonSubscript, SIGNAL(clicked()), this, SLOT(addSubscript()) );

	buttonSuperscript = new QPushButton(QPixmap(exp_xpm), QString());
	buttonSuperscript->setMaximumWidth(40);
	buttonSuperscript->setMinimumHeight(35);
	buttonSuperscript->setFont(font);
	layout->addWidget(buttonSuperscript);
	connect( buttonSuperscript, SIGNAL(clicked()), this, SLOT(addSuperscript()));

	if (buttons != Equation){
		buttonLowerGreek = new QPushButton(QString(QChar(0x3B1)));
		buttonLowerGreek->setFont(font);
		buttonLowerGreek->setMaximumWidth(40);
		layout->addWidget(buttonLowerGreek);
		connect( buttonLowerGreek, SIGNAL(clicked()), this, SLOT(showLowerGreek()));

		buttonUpperGreek = new QPushButton(QString(QChar(0x393)));
		buttonUpperGreek->setFont(font);
		buttonUpperGreek->setMaximumWidth(40);
		layout->addWidget(buttonUpperGreek);
		connect( buttonUpperGreek, SIGNAL(clicked()), this, SLOT(showUpperGreek()));

		buttonMathSymbols = new QPushButton(QString(QChar(0x222B)));
		buttonMathSymbols->setFont(font);
		buttonMathSymbols->setMaximumWidth(40);
		layout->addWidget(buttonMathSymbols);
		connect( buttonMathSymbols, SIGNAL(clicked()), this, SLOT(showMathSymbols()));

		buttonArrowSymbols = new QPushButton(QString(QChar(0x2192)));
		buttonArrowSymbols->setFont(font);
		buttonArrowSymbols->setMaximumWidth(40);
		layout->addWidget(buttonArrowSymbols);
		connect( buttonArrowSymbols, SIGNAL(clicked()), this, SLOT(showArrowSymbols()));
	}

	if (buttons != Plot3D && buttons != Equation){
		font = this->font();
		font.setBold(true);
		font.setPointSize(14);

		buttonBold = new QPushButton(tr("B","Button bold"));
		buttonBold->setFont(font);
		buttonBold->setMaximumWidth(40);
		layout->addWidget(buttonBold);
		connect( buttonBold, SIGNAL(clicked()), this, SLOT(addBold()));

		font = this->font();
		font.setItalic(true);
		font.setPointSize(14);

		buttonItalics = new QPushButton(tr("It","Button italics"));
		buttonItalics->setFont(font);
		buttonItalics->setMaximumWidth(40);
		layout->addWidget(buttonItalics);
		connect( buttonItalics, SIGNAL(clicked()), this, SLOT(addItalics()));

		font = this->font();
		font.setUnderline(true);
		font.setPointSize(14);

		buttonUnderline = new QPushButton(tr("U","Button underline"));
		buttonUnderline->setFont(font);
		buttonUnderline->setMaximumWidth(40);
		layout->addWidget(buttonUnderline);
   		layout->addStretch();
		connect( buttonUnderline, SIGNAL(clicked()), this, SLOT(addUnderline()));
	}

	if (buttons == Equation){
		buttonFraction = new QPushButton(QPixmap(fraction_xpm), QString());
		buttonFraction->setMaximumWidth(40);
		buttonFraction->setMinimumHeight(35);
		buttonFraction->setFont(font);
		layout->addWidget(buttonFraction);
		connect(buttonFraction, SIGNAL(clicked()), this, SLOT(addFraction()));

		buttonSquareRoot = new QPushButton(QPixmap(square_root_xpm), QString());
		buttonSquareRoot->setMaximumWidth(40);
		buttonSquareRoot->setMinimumHeight(35);
		buttonSquareRoot->setFont(font);
		layout->addWidget(buttonSquareRoot);
		connect(buttonSquareRoot, SIGNAL(clicked()), this, SLOT(addSquareRoot()));
		layout->addStretch();
	}
}
Ejemplo n.º 5
0
int main(void)
{
    //ex 1,2
    printf("Jussi\n\n");

    //ex 3
    printf("%6d, %4d\n", 86, 1040);
    printf("%12.5e\n", 30.253);
    printf("%.4f\n", 83.162);
    printf("%-6.2g\n\n", .0000009979);

    //ex 4
    printf("%d, %d, %d, %d\n\n", 5%2, -5%2, 5%-2, 5%-2);

    int i = 7;
    float f = 5.5;
    char c = 'w';
    printf("%lf\n", (double)(i+f));
    printf("%d\n", (int)(i+c));
    printf("%d\n", (int)(i+c-'0'));
    printf("%lf\n\n", (double)((i+c)-(2*f/5)));

    printf("%i\n\n", ((int)f)%2);

    i = 1;
    printf("i = %d \n", i);
    printf("i = %d \n", ++i);
    printf("i = %d \n", i);

    float x = 1.1;
    double d=2.2;
    printf("integer: %d \n", sizeof(i));
    printf("float: %d \n", sizeof(x));
    printf("double: %d \n", sizeof(d));
    printf("character: %d \n", sizeof(c));

    //ex 5
    d = (char)d;
    i = 8;
    int j = 5;
    x = (double)x;
    x = 0.005;
    double y = -0.01;
    c = 'c';
    d = 'd';

    abs(i - 2 * j); //absolute value
    fabs(x+y); //floating point abs
    isprint(c); //check if char is printable
    isdigit(c); //check if character is decimal digit
    toupper(d); //lowercase --> uppercase
    ceil(x); //round up
    ceil(x+y); //--
    floor(x); //round down
    floor(x+y); //--
    islower(c); //check if char is lowercase
    isupper(j); // -- uppercase
    exp(x); //e^x
    log(x); //trivial
    log(exp(x)); //x
    sqrt(x*x+y*y); //square root
    isalnum(10*j); //check if char is alphanumeric
    isalpha(10*j); // -- alphabetic
    isascii(10*j); // -- a 7-bit US-ASCII char code
    toascii(10*j); // converto to --
    fmod(x,y); //remainder of division
    tolower(65); //uppercase --> lowercase
    strlen("hello\0"); //string lenght
    strstr("hello\0", 'e'); //locate substring

    //ex 6
    printf("\n%d, %d\n\n", itseis(-4), itseis(8));

    //ex 7
    printf("GCD: %d\n\n", maxdiv(1235,345));

    //ex 8
    printf("SYT: %d\n\n", syt(1235,345));

    //ex 9
    int onnaa = addFraction(1,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 10
    onnaa = subFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 11
    onnaa = mulFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    //ex 12
    onnaa = divFraction(3,2,1,2);
    printf("%d\n\n",onnaa);

    return 0;
}
Ejemplo n.º 6
0
void menu() {
	int option;
	int frOption;
	frPtr lOp = 0;
	frPtr rOp = 0;
	
	do {
		printf("\n");
		printf("\nMENU : Fraction -- Tyler Hill"\
			"\n1. Creating/Updating"\
			"\n2. Adding"\
			"\n3. Subtracting"\
			"\n4. Multiplying"\
			"\n5. Dividing"\
			"\n6. Displaying"\
			"\n7. Quit");
		printf("\nEnter the option: ");
		scanf("%d", &option);

		switch (option) {
		case 1:
				do {
					printf("\nMENU : Creating/Updating"\
						"\n1. Left Operand"\
						"\n2. Right Operand"\
						"\n3. Both Operands"\
						"\n4. Displaying Current Operands"\
						"\n5. Return");
					printf("\nEnter the option: ");
					scanf("%d", &frOption);
					switch(frOption) {
						case 1:
							printf("\nLeft Operand: ");
							lOp = reduceFraction(createFraction());
							break;
						case 2:
							printf("\nRight Operand: ");
							rOp = reduceFraction(createFraction());
							break;
						case 3:
							printf("\nLeft Operand: ");
							lOp = reduceFraction(createFraction());
							printf("\nRight Operand: ");
							rOp = reduceFraction(createFraction());
							break;
						case 4:
							printf("\n");
							printf("\nLeft Operand:");
							displayFraction(lOp);
							printf("\n");
							printf("\nRight Operand:");
							displayFraction(rOp);
							break;
						case 5:
							break;
					}
				} while (frOption != 5);
			break;
		case 2:
			if(lOp != 0 && rOp != 0) {	
				displayFraction(addFraction(lOp,rOp));
			} else {
				printf("\nNot Allowed Yet - No Proper Data!");
			}
			break;
		case 3:
			if(lOp != 0 && rOp != 0) {	
				displayFraction(subtractFraction(lOp,rOp));
			} else {
				printf("\nNot Allowed Yet - No Proper Data!");
			}
			break;
		case 4:
			if(lOp != 0 && rOp != 0) {	
				displayFraction(multiplyFraction(lOp,rOp));
			} else {
				printf("\nNot Allowed Yet - No Proper Data!");
			}
			break;
		case 5:
			if(lOp != 0 && rOp != 0) {	
				displayFraction(divideFraction(lOp,rOp));
			} else {
				printf("\nNot Allowed Yet - No Proper Data!");
			}
			break;
		case 6:
			printf("\n");
			printf("\nLeft Operand:");
			displayFraction(lOp);
			printf("\n");
			printf("\nRight Operand:");
			displayFraction(rOp);
			break;
		case 7:
			break;
		default:
			printf("\nYou should not be in this class!\n");
		}
	} while (option != 7);
}
Ejemplo n.º 7
0
void TextFormatButtons::init(Buttons buttons)
{
  QHBoxLayout *layout = (QHBoxLayout*)this->layout();
  QLayoutItem *child;
  while ((child = layout->takeAt(0)) != 0){
    if (child->widget())
      delete child->widget();
  }

  QFont font = QFont();
  int btnSize = 32;
#ifdef Q_OS_MAC
  btnSize = 38;
#endif
  if (buttons == Legend || buttons == TexLegend){
    QPushButton *buttonCurve = new QPushButton( QPixmap(":/lineSymbol.png"), QString());
    buttonCurve->setFixedWidth(btnSize);
    buttonCurve->setFixedHeight(btnSize);
    buttonCurve->setFont(font);
    layout->addWidget(buttonCurve);
    connect( buttonCurve, SIGNAL(clicked()), this, SLOT(addCurve()) );
  }

  QPushButton *buttonSubscript = new QPushButton(QPixmap(":/index.png"), QString());
  buttonSubscript->setFixedWidth(btnSize);
  buttonSubscript->setFixedHeight(btnSize);
  buttonSubscript->setFont(font);
  layout->addWidget(buttonSubscript);
  connect( buttonSubscript, SIGNAL(clicked()), this, SLOT(addSubscript()) );

  QPushButton *buttonSuperscript = new QPushButton(QPixmap(":/exp.png"), QString());
  buttonSuperscript->setFixedWidth(btnSize);
  buttonSuperscript->setFixedHeight(btnSize);
  buttonSuperscript->setFont(font);
  layout->addWidget(buttonSuperscript);
  connect( buttonSuperscript, SIGNAL(clicked()), this, SLOT(addSuperscript()));

  if (buttons == Equation || buttons == TexLegend){
    QPushButton *buttonFraction = new QPushButton(QPixmap(":/fraction.png"), QString());
    buttonFraction->setFixedWidth(btnSize);
    buttonFraction->setFixedHeight(btnSize);
    buttonFraction->setFont(font);
    layout->addWidget(buttonFraction);
    connect(buttonFraction, SIGNAL(clicked()), this, SLOT(addFraction()));

    QPushButton *buttonSquareRoot = new QPushButton(QPixmap(":/square_root.png"), QString());
    buttonSquareRoot->setFixedWidth(btnSize);
    buttonSquareRoot->setFixedHeight(btnSize);
    buttonSquareRoot->setFont(font);
    layout->addWidget(buttonSquareRoot);
    connect(buttonSquareRoot, SIGNAL(clicked()), this, SLOT(addSquareRoot()));
  }

  QPushButton *buttonLowerGreek = new QPushButton(QString(QChar(0x3B1)));
  buttonLowerGreek->setFont(font);
  buttonLowerGreek->setFixedWidth(btnSize);
  buttonLowerGreek->setFixedHeight(btnSize);
  layout->addWidget(buttonLowerGreek);
  connect( buttonLowerGreek, SIGNAL(clicked()), this, SLOT(showLowerGreek()));

  QPushButton *buttonUpperGreek = new QPushButton(QString(QChar(0x393)));
  buttonUpperGreek->setFont(font);
  buttonUpperGreek->setFixedWidth(btnSize);
  buttonUpperGreek->setFixedHeight(btnSize);
  layout->addWidget(buttonUpperGreek);
  connect( buttonUpperGreek, SIGNAL(clicked()), this, SLOT(showUpperGreek()));

  QPushButton *buttonArrowSymbols = new QPushButton(QString(QChar(0x2192)));
  buttonArrowSymbols->setFont(font);
  buttonArrowSymbols->setFixedWidth(btnSize);
  buttonArrowSymbols->setFixedHeight(btnSize);
  layout->addWidget(buttonArrowSymbols);
  connect( buttonArrowSymbols, SIGNAL(clicked()), this, SLOT(showArrowSymbols()));

  QPushButton *buttonMathSymbols = new QPushButton(QString(QChar(0x222B)));
  buttonMathSymbols->setFont(font);
  buttonMathSymbols->setFixedWidth(btnSize);
  buttonMathSymbols->setFixedHeight(btnSize);
  layout->addWidget(buttonMathSymbols);
  connect( buttonMathSymbols, SIGNAL(clicked()), this, SLOT(showMathSymbols()));

  if (buttons != Plot3D && buttons != Equation && buttons != TexLegend){
    font = this->font();
    font.setBold(true);

    QPushButton *buttonBold = new QPushButton(tr("B","Button bold"));
    buttonBold->setFont(font);
    buttonBold->setFixedWidth(btnSize);
    buttonBold->setFixedHeight(btnSize);
    layout->addWidget(buttonBold);
    connect( buttonBold, SIGNAL(clicked()), this, SLOT(addBold()));

    font = this->font();
    font.setItalic(true);

    QPushButton *buttonItalics = new QPushButton(tr("It","Button italics"));
    buttonItalics->setFont(font);
    buttonItalics->setFixedWidth(btnSize);
    buttonItalics->setFixedHeight(btnSize);
    layout->addWidget(buttonItalics);
    connect( buttonItalics, SIGNAL(clicked()), this, SLOT(addItalics()));

    font = this->font();
    font.setUnderline(true);

    QPushButton *buttonUnderline = new QPushButton(tr("U","Button underline"));
    buttonUnderline->setFont(font);
    buttonUnderline->setFixedWidth(btnSize);
    buttonUnderline->setFixedHeight(btnSize);
    layout->addWidget(buttonUnderline);
    layout->addStretch();
    connect( buttonUnderline, SIGNAL(clicked()), this, SLOT(addUnderline()));
  } else
    layout->addStretch();
}