bool PremierExemple::qt_invoke( int _id, QUObject* _o )
{
    switch ( _id - staticMetaObject()->slotOffset() ) {
    case 0: Addition(); break;
    case 1: Soustraction(); break;
    case 2: Multiplication(); break;
    case 3: DivisionEntiere(); break;
    case 4: Effacer(); break;
    case 5: Terminer(); break;
    case 6: languageChange(); break;
    default:
	return QDialog::qt_invoke( _id, _o );
    }
    return TRUE;
}
Пример #2
0
/************************************************************************
* polynomial multiplication: C(x) = A(x) * B(x)
* parameter:
*     apoly: A(x)
*     bpoly: B(x)
*     cpoly: C(x)
************************************************************************/
void CPolynomial::Multiplication(CPoly& apoly,CPoly& bpoly,CPoly& cpoly)
{
    //A(x) * B(x)
    int ai=0;
    while(ai<apoly.Size())
    {
        CTerm term=apoly.At(ai);

        //D(x) = term * B(x)
        CPoly dpoly(bpoly);
        dpoly.Sprod(term);

        //make addition: C(x) = D(x) + E(x)
        CPoly epoly(cpoly);
        cpoly.Clear();
        Addition(dpoly,epoly,cpoly);

        //next
        ai++;
    }
}
Пример #3
0
void CallFunction(FunctionCall fc)
{
	int function = GetFunction(fc->function);
	
	switch (function)
	{
		case VAR : NewVariable(fc); break;
		case NMX : NewMatrix(fc); break;
		case ADD : Addition(fc); break;
		case SUB : Substraction(fc); break;
		case MUL : Multiplication(fc); break;
		case MSC : Scalar_Mult(fc); break;
		case EXP : Exponentiation(fc); break;
		case TRA : Transpose(fc); break;
		case DET : Determinant(fc); break;
		case DLU : Decomposition(fc); break;
		case SOL : Solve(fc); break;
		case INV : Inversion(fc); break;
		case RNK : Rank(fc); break;
		case DSP : Display(fc); break;
		case NOF : // default
		default :
		{
			if (GetFunction(fc->name)==SPT) SpeedTest(fc);
			else if (IndexVariable(fc->function)!=-1) NewVariable(fc);
			else if (IndexMatrix(fc->function)!=-1) NewMatrix(fc);
			else
			{
				printf("\t%s : Function Not Implemented\n", fc->function);
				fni++;
			}
			break;
		}
	}
	
	if (function!=NOF && function !=VAR) fni = 0;
}
Пример #4
0
Constante* Eval::getValue() const {
    Expression* exp = dynamic_cast<Expression*>(c);
    QStack<Constante*> p;
    if (exp != NULL){
        int i = 0;
        QString s = exp->getExp();
        Constante * result = 0;
        while(i<s.length()){
            //on passe les espaces;
            if(s[i] == ' '){
                if(result != 0){
                    p.push(result);
                    result = 0;
                }
            }
            else if(s[i] >= '0' && s[i] <= '9'){
                if(result == 0)result = Addition(Rationnel(0),Rationnel(0),mModeConstante, mModeComplexes).getValue();
                result->addChiffre(s[i].toAscii() - '0');
            }
            else if(s[i] == '$'){
                if(result == 0) throw EvalException("$ mal placé");
                result->setDollarEntre();
            }
            else if(s[i] == '/'){
                if(result != 0){
                    result->setSlashEntre();
                }
                else{
                    if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour /");
                    Constante *op2 = p.pop(),  *op1 = p.pop();
                    try{
                        result = Division(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                    }
                    catch(DivException e){
                        throw EvalException("division par zéro");
                    }

                    delete op1;
                    delete op2;
                    p.push(result);
                    result = 0;
                }
            }
            else if(s[i] == ',' || s[i] == '.'){
                if(result == 0) throw EvalException(", ou . mal placé");
                result->setVirguleEntree();
            }
            else if(s[i] == '+'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour +");
                Constante *op1 = p.pop(),  *op2 = p.pop();
                result = Addition(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else if(s[i] == '-'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour -");
                Constante *op2 = p.pop(),  *op1 = p.pop();
                result = Soustraction(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else if(s[i] == '*'){
                if(result!=0){
                    p.push(result);
                    result = 0;
                }
                if(p.size() < 2) throw EvalException("Pas assez d'opérandes pour *");
                Constante *op2 = p.pop(),  *op1 = p.pop();
                result = Multiplication(*op1,*op2,mModeConstante,mModeComplexes).getValue();
                delete op1;
                delete op2;
                p.push(result);
                result = 0;
            }
            else{
                throw EvalException("Caractère inconnu");
            }
            i++;
        }
        if(result!=0)p.push(result);
        if(p.size() > 1) throw EvalException("Il manque un opérateur.");
        if(p.size() < 1) throw EvalException("Pile d'évaluation vide.");
        return p.at(0);
    }
    else throw TypeConstanteException("Ceci n'est pas une expression");
}
Пример #5
0
void main()	// main function
{
	int menu, result[100], total=0, count=0;
	char con;
	struct tm time;
		_getsystime(&time);
	int hr, min, sec;

	hr = time.tm_hour;
	min = time.tm_min;
	sec = time.tm_sec;

	int i=0;
	do
	{
		// Menu
		system("CLS");
		printf("_-_-_-_Menu_-_-_-_\n"
			   "[1] Multiplication\n"
			   "[2] Division\n"
			   "[3] Addition\n"
			   "[4] Subtraction\n"
			   "[5] Quit\n\n");

		printf("Choose a selection > ");
		scanf("%d",&menu);

		switch(menu)	// switch statement
		{
		case 1:
			{
				result[i] = Multiplication();	// function call Multiplication();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 2:
			{
				result[i] = Division();	// function call Division();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 3:
			{
				result[i] = Addition();	// function call Addition();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 4:
			{
				result[i] = Subtraction();	// function call Subtraction();
				output(result[i]);	// function call output();
				count++;	// the times of test
				break;
			}
		case 5:
			{
				Quit(total,count,hr,min,sec);	// function call Quit();
				break;
			}
		default:
			{
				printf("Invalid Input! Please re-enter\n");
				main();	// re-run the main function
			}
			i++;
		}
		total = total + result[i];	// sum all the tests' marks
		// ask for user want to continue the test or not
		printf("Do you want to continue? (Y/N) ");
		fflush(stdin);
		scanf("%c",&con);
		toupper(con);
		while(con!='Y' && con!='N' && con!='y' && con!='n')
			{
				printf("Invalid Input! Please re-enter (Y/N)> ");
				fflush(stdin);
				scanf("%c",&con);
				toupper(con);
			}
	}while(con == 'Y' || con=='y');
	Quit(total,count,hr,min,sec);	// Print out the total result & Quit the program
}
Пример #6
0
int main()
{
    // Part One:


    // FIXME: Declare variables
    // Declare two variables: an integer named "age", and a string named "name" with corresponding values (your name and age)
    int age = 19;
    char name[] = "Stan";

    // FIXME: Print
    // Print the following sentence in the console "You are NAME and you are AGE years old !". Don't forget to add a newline at the end
    printf("You are %s and you are %d years old !\n", name, age);

    // FiXME: Concatenation
    // Create a new string variable called "hello" which value is "Hello ". Add "name" at the end of "hello" (Concatenation) then print it
    char hello[] = "Hello ";
    strcat(hello, name);
    printf("%s\n", hello);

    // FIXME: Array
    // create a new string array called "shoppingList", with three elements of your choice. Create an int variable containing the number of
    // elements in "shoppingList" (using a function of the array/using the array)
    char *shoppingList[3] = {"milk", "a Chevy Camaro", "a life"};
    const int nbOfElements = numberOfElements(shoppingList);

    // FIXME: For-loop - Integer
    // Create a simple for-loop for an integer "i" going from 1 to 10 that print the value of "i"
    for (int i = 0; i < 10; i++)
        printf("%d ", i);
    printf("\n");

    // FIXME: For-loop - shoppingList
    // Create a for loop that iterate through "shoppingList" and prints each element with "You have to buy (elemt)".
    for (int j = 0; j <nbOfElements; j++)
        printf("You have to buy %s\n", shoppingList[j]);


    // FIXME: Foreach-loop
    // Do the same with a foreach-loop.
    // The C programming language doesn't have a foreach, but you can look for macros if you are
    // curious.



    // FIXME: If-statement
    // Modify the first for-loop (with i from 1 to 10) such that it prints "(value of i) is even" when "i" is divisible
    // by 2 (You may want to learn more about "modulo" (%)). Else, print "(value of i) is odd".
    for (int i = 0; i < 10; i++)
    {
        if (i % 2)
            printf("%d is odd\n", i);
        else
            printf("%d is even\n", i);
    }



    // FIXME: Sum Up
    // Create a string variable called "element" with the value of your choice. Then create a for-loop/foreach-loop that checks if "shoppingList"
    // contains "element". If yes, print "You have to buy (value of element) !", and stop the loop (search how to stop a loop).
    // If not, print "Nope, you don't need (value of "element")".
    char element[] = "a life";
    for (int k = 0; k < nbOfElements; k++)
    {
        if (strcmp(element, shoppingList[k]) == 0)
        {
            printf("You have to buy %s !\n", shoppingList[k]);
            break;
        }
        else
        {
            printf("Nope, you don't need %s !\n", shoppingList[k]);
        }
    }



    // Part Two:


    // FIXME: Functions - Ascii
    // Create a function that returns nothing and which doesn't takes any parameter. It should just be named "TriForce"
    // and print the TriForce symbol (one triangle over two other ones, can be found on internet) with "TRIFORCE"
    // Don't forget to call the function !
    TriForce(); //Calling the functions in main()


    // FIXME: Functions - One parameter
    // Create a function that takes a string as parameter and returns "Hello (value of string) !"
    // http://stackoverflow.com/questions/1745726/how-to-store-printf-into-a-variable
    printf("%s", Hello("Stan"));

    // FIXME: Functions - Multiple parameters
    // Create a function that takes two integers as parameters and returns the addition of these two.
    // You can do the same with multiplication, subtraction and division.
    printf("%d\n", Addition(5, 12));
    printf("%d\n", Subtraction(5, 12));
    printf("%d\n", Multiplication(5, 12));
    printf("%d\n", Division(5, 12)); // returns 0 because "a" and "b" are Integers
    printf("%d\n", Division(10, 2));


    // FIXME: User entry
    // Create a string variable that takes what the user enter in the console as value. Then print "You entered (value of string)"
    char userInput[100]; // 100 will be the max length of the input
    printf("Enter a word:");
    scanf("%s", userInput);
    printf("You entered %s\n", userInput);


    // FIXME: While loop
    // Create a while loop that takes a number and divides it by 2 until it is less than 3
    int number = 52;
    while (number > 3)
    {
        number /= 2; //or number = number / 2;
        printf("%d ", number);
    }
    printf("\n");



    // FIXME: do-While loop
    // Do the same with a do-while loop
    int number2 = 84;
    do
    {
        number2 = number2 / 2;
        printf("%d ", number2);
    } while (number2 > 3);
    printf("\n");



    // FIXME: Random generator
    // Create a function that returns a random number
    srand((unsigned)time(NULL)); // time used for seeding
    printf("%d\n", rdm());


    // FIXME: Random generator with bounds
    // Create another function that returns a random number between two bounds given as parameters.
    printf("%d\n", rdmBounds(10, 20));



    // FIXME: Multi-dimensionnal array
    // Create a two dimensionnal int array of 3 columns and 3 rows. Use 2 for-loops to add a random number
    // between 1 and 9 in each of the 9 rooms.
    // You may use one of the two previously created function.
    // Then print them such that they appear like this (with [x1, x9] being the 9 random integers):
    // {x1, x2, x3, }
    // {x4, x5, x6, }
    // {x7, x8, x9, }
    int multiArray[3][3];
    for (int l = 0; l < numberOfElements(multiArray); l++)
        for (int m = 0; m < numberOfElements(multiArray[l]); m++)
            multiArray[l][m] = rdmBounds(1, 9);

    for (int n = 0; n < numberOfElements(multiArray); n++)
    {
        printf("{");

        for (int o = 0; o < numberOfElements(multiArray[n]); o++)
            printf("%d, ", multiArray[n][o]);

        printf("}\n");
    }

    // FIXME: Switch
    // Create a Switch that takes an integer "a" and return a sentence regarding the value of a
    // (Create 3 statements for 3 specific values and a default one)

    int a = 2;

    switch(a)
    {
    case 0:
        printf("a is 0\n");
        break;

    case 2:
        printf("a is 2\n");
        break;

    case 37:
        printf("Who cares about a anyway ?");
        break;

    default:
        printf("I don't know what \"a\" is... :'(\n");
        break;
    }

    // FIXME: logic Gates
    // Create 7 functions for each logic gates (And (0), Or (1), No (2), Nand (3), Nor (4), Xnor (5), Xor (6)).
    // Each function takes two booleans as parameters and returns the result of the logic gate.
    // (or You can do it with a switch and only one function)

    logic_gates(1, 0, 1);
    logic_gates(1, 1, 1);
    logic_gates(1, 2, 1);

    // FIXME - Reverse
    // Create a function that reverse a string

    reverse("Hello world");
    return 0;
}
Пример #7
0
void menu(int m1, int n1, int m2, int n2, int m3, int n3)
{
    printf("\n1.Read an Array.\n2.Print an Array.\n3.Addition of 2 Arrays.\n4.Substraction of 2 Arrays.\n5.Multiplication of 2 Arrays.\n6.Multiplication of an Array by a Number.\n7.Transpose of a Matrix.\n8.Determinant of a Matrix.\n9.Exit.\n");
    scanf("%d",&f);
    switch (f) {
        case 1:
            read(x, &m1, &n1, y, &m2, &n2, z, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
            
        case 2:
            printa(x, m1, n1, y, m2, n2, z, m3, n3);
            printf("\n1.Menu.\n2.Exit.\n");
            scanf("%d",&f);
            switch (f) {
                case 1:
                    menu(m1, n1, m2, n2, m3, n3);
                    break;
                case 2:
                    break;
                
                default:
                    break;
            }
            
            break;
            
        case 3:
            Addition(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
            
        case 4:
            substraction(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
            
        case 5:
            multiplication_array(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
        
        case 6:
            multiplaction_number(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
        
        case 7:
            transpose(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
            
        case 8:
            determinant(x, m1, n1, y, m2, n2, z, m3, n3, &m1, &n1, &m2, &n2, &m3, &n3);
            menu(m1, n1, m2, n2, m3, n3);
            break;
            
        case 9:
            break;
            
        default:
            break;
    }
}