Nas suas obras mais importantes, as Meditações metafísicas e o Discurso do método, o francês René Descartes deixa claro sua preferência pelo subjetivismo. O subjetivismo cartesiano pode ser sintetizado na seguinte expressão:
A geometria analítica conecta a álgebra e a geometria tradicional. É também apelidada de geometria das coordenadas, com eixos x e y formando um plano. Diferente do que aconteceu com a geometria euclidiana, elaborada desde a Antiguidade; a geometria analítica surgiu a partir das teorias de Descartes e de outro pensador. É considerada moderna, portanto. Assinale o nome do outro teórico que iniciou os estudos sobre a geometria analítica:
Descartes foi um filósofo formidável. Apesar de ter uma saúde frágil, produziu vários livros e escreveu sobre variados assuntos. Assinale a opção correta, que identifica o método desenvolvido por ele:
Exercise L5.E4
Develop a program to input a matrix with any dimension and output the transpose of that matrix. You should stop accepting the rows when -1 is entered as the input. Use a 2D (two-dimensional) list to store the matrix. You should handle the exceptions such as checking the invalid rows with an inconsistent number of elements.
Note: Print “Invalid Matrix” as the error message for invalid rows with an inconsistent number of elements. Print “Error” for any other exceptions you are handling.
Please submit the flowchart diagram that illustrates the algorithm of your program here.
Exercise L5.E3
Suppose there are 4 students each having marks of 3 subjects. Develop a program to read the marks from the keyboard and calculate and display the total marks and average mark (rounded off to one decimal point) of each student. Use a 2D (two-dimensional) list to store the marks.
Please submit the flowchart diagram that illustrates the algorithm of your program here.
Exercise L5.E2
Develop a program to read the names of two sports that you and your friends love to play and watch. Then generate all sentences where the subject is in ["I", "We"], the verb is in ["play", "watch"] and the object is in the two sports. Use lists to store the words and generate the sentences by iterating through the lists using deeply nested loops.
Please submit the flowchart diagram that illustrates the algorithm of your program here.
Consider the following lock and unlock functions from class that puts threads to sleep instead of spin-waiting. Identify the bug(s) in the code. Assume TestAndSet runs atomically.
void lock(lock_t *m) {
while (TestAndSet(&m->guard, 1) == 1)
; // acquire guard lock by spinning
if (m->flag == 0){
m->flag = 1; // lock is acquired
m->guard = 0;} else {
queue_add(m->q, gettid());
m->guard = 0; park(); } } void unlock(lock_t *m) { while (TestAndSet(&m->guard, 1) == 1) ; // acquire guard lock by spinning if (queue_empty(m->q)) m->flag = 0; // let go of lock; no one wants it elseunpark(queue_remove(m->q)); // hold lock (for next thread!)
m->guard = 0;
}
Suppose three (3) threads each increment a shared variable 5 times that is initialized to 0 (so, the expected result then is 15). After all threads have finished, the main prints the value of the shared variable. Without locks (or any other way of enforcing mutual exclusion), which of the following will/could be printed by the main?
What will be printed by the following code snippet that creates two (2) threads to execute the function mythread and joins them to ensure they both finish?
void *mythread(void *arg) {
int result = 0;
result = result + 100;
printf("result %d\n", result);
}
thread_t p1, p2;
thread_create(&p1, mythread, NULL);
thread_create(&p2, mythread, NULL);
thread_join(p1);
thread_join(p2);
What will be the result of a thread executing the following C code snippet?
lock_t mutex;
.
.
.
lock(&mutex);
while(1){
myFunc();
}
unlock(&mutex);