Programmering grundkurs and Programmering C
for D1 and others, including the distance learning course
Thursday, August 22, 2013
Valid as exam for:
DT1029 Datateknik A, Programmering grundkurs, provkod 0100
DT1030 Datateknik A, Tillämpad datavetenskap, provkod 0410
DT1006 Datateknik A, Programmering C, distans, provkod 0100
DT1016 Datateknik A, Programmering grundkurs, provkod 0100
DT1007 Datateknik A, Tillämpad datavetenskap, provkod 0410
(English version. There is also a Swedish version of this exam.)
Aids: | No aids. |
Score requirements: |
Maximum score is 40.
To pass (the grade 3 or G) 20 points are needed. |
Results and solutions: | Notified by email or on the course home page, http://basen.oru.se/kurser/c/2012-2013-p2/, no later than Thursday, September 12, 2013. |
Return of exams: | After the results have been announced, exams can be retrieved from the university's central exam retrieval office. |
Responsible teacher and on-call: | Thomas Padron-McCarthy, telephone 070-73 47 013. |
Priority | Category | Operator | Associativity |
---|---|---|---|
Highest | Unary postfix operators | (), [], ->, ., ++, -- | left |
Unary prefix operators | !, ++, --, +, -, *, &, sizeof, (type) | right | |
Multiplication etc | *, /, % | left | |
Addition etc | +, - | left | |
Comparisons | <, <=, >=, > | left | |
Equality comparisons | ==, != | left | |
Logical AND | && | left | |
Logical OR | || | left | |
Lowest | Assignment | =, +=, -=, *=, /=, %= | right |
int rand(void); void srand(unsigned int seed); void *malloc(size_t size); void *realloc(void *ptr, size_t size); void free(void *ptr); void exit(int status); void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
FILE *fopen(const char *path, const char *mode); int fclose(FILE *stream); int getc(FILE *stream); int getchar(void); int ungetc(int c, FILE *stream); char *fgets(char *s, int size, FILE *stream); char *gets(char *s); int putc(int c, FILE *stream); int printf(const char *format, ...); int fprintf(FILE *stream, const char *format, ...); int sprintf(char *str, const char *format, ...); int snprintf(char *str, size_t size, const char *format, ...); int scanf(const char *format, ...); int fscanf(FILE *stream, const char *format, ...); int sscanf(const char *str, const char *format, ...); size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t strlen(const char *s); char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t n); int strcmp(const char *s1, const char *s2); int strncmp(const char *s1, const char *s2, size_t n); char *strcat(char *dest, const char *src); char *strncat(char *dest, const char *src, size_t n); char *strstr(const char *haystack, const char *needle); void *memmove(void *dest, const void *src, size_t n);
int isalnum(int c); int isalpha(int c); int isblank(int c); int isdigit(int c); int islower(int c); int isprint(int c); int ispunct(int c); int isspace(int c); int isupper(int c);
a) 4 * 3 − 2 + 1
b) 4 − 3*2 + 1
#include <stdio.h> int g(int x, int y) { int i, a, b, c; a = 17; b = 2; c = 38; for (i = x; i < y; i++) printf("*"); return x + y; } int main(void) { int a; int b, c; for (a = 1; a < 3; ++a) { b = a + 1; c = g(a, b); printf("a = %d, b = %d, c = %d\n", a, b, c); } return 0; }
For this and all other tasks on the exam:
Typically, error handling is a large part of a program. For instance, what should happen if the user writes Donald when she really should enter a number? Here, however, no error handling is needed, unless explicitly required in the task. |
For this and all other tasks on the exam:
One can ignore details that are only needed when developing console application in Visual Studio, such as weird character codes for ÅÄÖ, and that the window with program disappears when the program ends. |
struct Triangle { double a, b, c; };
a, b and c are the lengths of the sides of the triangle. The sides can be stored in any order, so there is for example no guarantee that the triangle's longest side is anyone specific of a, b or c. All lengths must be greater than zero.
void show_triangle(struct Triangle t)
or like this:
void show_triangle(struct Triangle *tp)
struct Triangle read_triangle(void)
or like this:
void read_triangle(struct Triangle* tp)
Write the functions min and max.
For this and all other tasks on the exam:
If you need to use something from a previous task or sub-task, such as a data type or a function that was written in the previous task, you do not have to write the same code again. You may also do the task even if you have not done that previous task. |
For realistic testing we would need more than just one call, but here we only do one. Thus there is only a single test case. Try to make that test case as good as possible!
If the file can not be opened, an error message should be printed, and the program should be terminated.
Do not forget to specify if you chose a text file or a binary file!
If the file can not be opened, an error message should be printed, and the program should be terminated.
#include <stdio.h> int main(void) { double x = 0.2, y = 6.0, z = 1.2; printf("%f\n", x * y); printf("%f\n", z); if (x * y == z) printf("Lika, förstås.\n"); else printf("Va? Inte lika!\n"); return 0; }