In what concerns the "exercises during classes" component of the evaluation, the exercises that you can submit for this class are:
Deadline for submission: March 3rd (submit to PII's Mooshak)
You are encouraged to talk to the professors and your colleagues if you encounter difficulties.
However, any more direct help that you receive should be acknowledged in the comments of the code you submit.
After the deadline the problems will still be available on Mooshak, but the submissions will not count towards your grade.
Each practical class is worth 18% of your final component for exercices during class. Since there will be 6 classes with submissions, you can achieve maximum grade even without doing fully doing all classes.
For a problem to count you must pass all tests (that is, to have an accepted). Even if you solve all problems, the maximum on one class is 100%.
To obtain 100% it will always be enough to solve the main exercises.
With the exercises in this class you will develop the following skills:
If you feel stuck, go back and revise the lecture 01: C Fundamentals
1) My first C program
#include <stdio.h> int main(void) { printf("Hello cruel world, can I go back to Python?\n"); return 0; }
If you have a command line with gcc and assuming you created a file called hello.c with the code above, you can simply do the following:
If you did everything correctly, you should be able to see the following output:
Hello cruel world, can I go back to Python?
2) My first Mooshak submissions
On this course we will use Mooshak to automatically evaluate your Python code (see Mooshak's help).
To access the system you can use your login (with the word "up")
and password that was sent to your institutional email (message sent on the 18th of February with the title "[PII] Mooshak password - login")
(if you have trouble accessing it, send a message on discord to @PedroRibeiro)
In this problem the goal is to make your first submissions in Mooshak, all for the [PII001] Hello there. The problem statement will also be available inside Mooshak. Always start by carefully reading the problem statement given!
This problem is not hard at all using a a basis the code from the last exercise, right?
3) Reading my first input
#include <stdio.h> int main(void) { int n; // create variable to store an integer printf("Number? "); // print message asking for a number scanf("%d", &n); // read an integer to variable n printf("The number is %d\n", n); // print the value of variable n return 0; }
#include <stdio.h> int main(void) { int x, y; // two integer variables scanf("%d %d", &x, &y); // read two integers printf("(%d,%d)\n", x, y); // print integers as a pair return 0; }
Here are a couple more notes about Mooshak on this course:
4) My first expressions
#include <stdio.h> int main(void) { int a = 42; int b = 9; int sum = a + b; printf("%d + %d = %d\n", a, b, sum); int sub = a - b; printf("%d - %d = %d\n", a, b, sub); int mul = a * b; printf("%d * %d = %d\n", a, b, mul); int div = a / b; // a and b are integers, so the division is "truncated" printf("%d / %d = %d\n", a, b, div); int mod = a % b; // division remainder printf("%d %% %d = %d\n", a, b, mod); float fa = a; float fb = b; float fdiv = fa / fb; // a and b are floats, division is not "truncated" printf("%f / %f = %f\n", fa, fb, fdiv); // by default with 6 decimal places // we can print with any number of (rounded) decimal places float n = 1.9876; printf("n = %.0f (0)\n", n); printf("n = %.1f (1)\n", n); printf("n = %.2f (2)\n", n); printf("n = %.3f (3)\n", n); printf("n = %.4f (4)\n", n); return 0; }
With the knowledge you obtained from the previous code, you know everything needed the next 3 main problems
Use the hints if you need extra help (they are hidden in case you do not want spoilers)
Read the statements, code and submit Accepted solutions to all of the following problems. Don't forget to test first on your computer!
- Create an integer variable (e.g. int d) and read to it using scanf
- the number of hours is just... d * 60; and the number of minutes and seconds?
- store the results in three different values and print them
- Create a float variable t and an int variable n
- Read the input and store it on the variables
- Compute the result as t / n and print it with printf("%.2f", result_variable)
- If the number is n then the units (rightmost digit) is simply... n % 10
- The second rightmost digit (tens) is (n / 10) % 10. Can you see why?
- Can you do the other 2 digits by yourself?
PII's Mooshak classes will usually include at least one extra exercise that you can use of you want to keep testing your knowledge of the material. For this class we propose two other problems that complement the main ones.
- In this problem you need to take into account the minutes, but if m is an integer value, then m/60 will truncate the result (and will always be zero)
- If you want this m/60 to be a float, then m needs to be a float or you should use m/60.0
- to round to the integer part you can print using %.0f
- Can you do one problem by yourself? 😁
IP Mooshak classes will usually include one challenge exercise, which can be much harder the previous ones and might even need knowledge that was not given explicitly on the course.
Since this is the first challenge, it is almost of the same difficulty of the previous exercises (but one small aspect was not directly give in the clases and you will need to find it by your own).
Happy coding! 😊