Praktikum 4 angefangen
This commit is contained in:
parent
aac55ce473
commit
d4c2ce5bc4
Binary file not shown.
|
@ -12,5 +12,79 @@
|
|||
* @brief Lab implementation
|
||||
*/
|
||||
// begin students to add code for task 4.1
|
||||
#define EOL 10
|
||||
#define PARSE_ERROR -1
|
||||
#define READ_ERROR -2
|
||||
#define ASCII_SPACE 32
|
||||
#define ASCII_DIGIT_0 48
|
||||
#define ASCII_DIGIT_9 57
|
||||
#define NO_POS -1
|
||||
#define BUFFERSIZE 10
|
||||
#define EOF -1
|
||||
int getInt(int maxResult) {
|
||||
// end of input
|
||||
//int EOF = -1; // end of file
|
||||
//int EOL = 10; // end of line
|
||||
// abnormal return values
|
||||
//int PARSE_ERROR = -1;
|
||||
//int READ_ERROR = -2;
|
||||
// ASCII Codes
|
||||
//int ASCII_SPACE = 32; // ' '
|
||||
//int ASCII_DIGIT_0 = 48; // '0'
|
||||
//int ASCII_DIGIT_9 = 57; // '9'
|
||||
|
||||
// conversion buffer
|
||||
//int NO_POS = -1;
|
||||
//int BUFFERSIZE = 10;
|
||||
char buffer[BUFFERSIZE] = {0};
|
||||
|
||||
int result = 0;
|
||||
|
||||
// read line: up to EOL or EOF (i.e. error while reading)
|
||||
int bytes = 0;
|
||||
int input;
|
||||
scanf("%d", &input);
|
||||
while ((input != EOL) && (input != EOF)) { // read whole line
|
||||
if (bytes < BUFFERSIZE) { // only buffer first n characters
|
||||
buffer[bytes] = (char)input;
|
||||
bytes++;
|
||||
} else {
|
||||
result = PARSE_ERROR; // exceed buffer size, continue read line
|
||||
}
|
||||
scanf("%d", &input);
|
||||
}
|
||||
if (input == EOF) {
|
||||
result = READ_ERROR;
|
||||
}
|
||||
// check for numbers: skip leading and trailing spaces
|
||||
// (i.e. this includes all control chars below the space ASCII code)
|
||||
int pos = 0;
|
||||
while((pos < bytes) && (buffer[pos] <= ASCII_SPACE)) pos++; // skip SP
|
||||
int posOfFirstDigit = pos;
|
||||
int posOfLastDigit = NO_POS;
|
||||
while ((pos < bytes)
|
||||
&& (buffer[pos] >= ASCII_DIGIT_0)
|
||||
&& (buffer[pos] <= ASCII_DIGIT_9))
|
||||
{
|
||||
posOfLastDigit = pos;
|
||||
pos++;
|
||||
}
|
||||
while((pos < bytes) && (buffer[pos] <= ASCII_SPACE)) pos++; // skip SP
|
||||
// produce return value
|
||||
if (result != 0) {
|
||||
// previously detected read or parse error given
|
||||
} else if ((pos != bytes) || (posOfLastDigit == NO_POS)) {
|
||||
result = PARSE_ERROR;
|
||||
} else { // convert number
|
||||
for(int i = posOfFirstDigit; i <= posOfLastDigit; i++) {
|
||||
result = result * 10 + (buffer[i] - ASCII_DIGIT_0);
|
||||
if (result > maxResult) {
|
||||
result = PARSE_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// end students to add code
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
src/read.o: src/read.c /usr/include/stdc-predef.h
|
Binary file not shown.
|
@ -12,5 +12,24 @@
|
|||
* @brief Lab implementation
|
||||
*/
|
||||
// begin students to add code for task 4.1
|
||||
int Rectangular(int a, int b, int c) {
|
||||
int aS = a*a;
|
||||
int bS = b*b;
|
||||
int cS = c*c;
|
||||
|
||||
int isRightAngled;
|
||||
if ((a == 0) && (b == 0) && (c == 0))
|
||||
isRightAngled = 0;
|
||||
else if ((aS + bS) == cS)
|
||||
isRightAngled = 1;
|
||||
else if ((aS + cS) == bS)
|
||||
isRightAngled = 1;
|
||||
else if ((bS + cS) == aS)
|
||||
isRightAngled = 1;
|
||||
else
|
||||
isRightAngled = 0;
|
||||
|
||||
return isRightAngled;
|
||||
}
|
||||
|
||||
// end students to add code
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
src/rectang.o: src/rectang.c /usr/include/stdc-predef.h
|
Binary file not shown.
Binary file not shown.
|
@ -15,9 +15,11 @@
|
|||
#include <stdlib.h>
|
||||
#include "read.h"
|
||||
#include "rectang.h"
|
||||
|
||||
int getInt(int maxResult);
|
||||
int Rectangular(int a, int b, int c);
|
||||
/// max side length
|
||||
#define MAX_NUMBER 1000
|
||||
#define READ_ERROR -2
|
||||
|
||||
|
||||
/**
|
||||
|
@ -28,6 +30,52 @@ int main(void)
|
|||
{
|
||||
// begin students to add code for task 4.1
|
||||
|
||||
while (1) {
|
||||
printf("\nDreiecksbestimmung (CTRL-C: Abbruch)\n");
|
||||
|
||||
int word = 0;
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
|
||||
do {
|
||||
printf("Seite a: ");
|
||||
word = getInt(MAX_NUMBER);
|
||||
}
|
||||
while ((word < 0) && (word != READ_ERROR));
|
||||
if (word >= 0)
|
||||
a = word;
|
||||
else
|
||||
break;
|
||||
|
||||
do {
|
||||
printf("Seite b: ");
|
||||
word = getInt(MAX_NUMBER);
|
||||
}
|
||||
while ((word < 0) && (word != READ_ERROR));
|
||||
if (word >= 0)
|
||||
b = word;
|
||||
else
|
||||
break;
|
||||
|
||||
do {
|
||||
printf("Seite c: ");
|
||||
word = getInt(MAX_NUMBER);
|
||||
}
|
||||
while ((word < 0) && (word != READ_ERROR));
|
||||
if (word >= 0)
|
||||
c = word;
|
||||
else
|
||||
break;
|
||||
|
||||
if (Rectangular(a, b, c) == 1)
|
||||
printf("-> Dreieck %d-%d-%d ist rechtwinklig", a, b, c);
|
||||
else
|
||||
printf("-> Dreieck %d-%d-%d ist nicht rechtwinklig", a, b, c);
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n\nbye bye\n");
|
||||
|
||||
// end students to add code
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
src/triangle.o: src/triangle.c /usr/include/stdc-predef.h \
|
||||
/usr/include/stdio.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
|
||||
/usr/include/features.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/wordsize.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/long-double.h \
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs.h \
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/typesizes.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/FILE.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/libio.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/_G_config.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h /usr/include/stdlib.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/floatn.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/floatn-common.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h src/read.h \
|
||||
src/rectang.h
|
Binary file not shown.
|
@ -0,0 +1,40 @@
|
|||
tests/tests.o: tests/tests.c /usr/include/stdc-predef.h \
|
||||
/usr/include/stdio.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/libc-header-start.h \
|
||||
/usr/include/features.h /usr/include/x86_64-linux-gnu/sys/cdefs.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/wordsize.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/long-double.h \
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs.h \
|
||||
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/typesizes.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/__FILE.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/FILE.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/libio.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/_G_config.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h \
|
||||
/usr/lib/gcc/x86_64-linux-gnu/7/include/stdarg.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/stdio_lim.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h /usr/include/stdlib.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/floatn.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/floatn-common.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h \
|
||||
/usr/include/CUnit/Basic.h /usr/include/CUnit/CUnit.h \
|
||||
/usr/include/string.h /usr/include/math.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/math-vector.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/libm-simd-decl-stubs.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/flt-eval-method.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/fp-logb.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/fp-fast.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/mathcalls.h \
|
||||
/usr/include/CUnit/CUError.h /usr/include/errno.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/errno.h /usr/include/linux/errno.h \
|
||||
/usr/include/x86_64-linux-gnu/asm/errno.h \
|
||||
/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h \
|
||||
/usr/include/CUnit/TestDB.h /usr/include/setjmp.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/setjmp.h \
|
||||
/usr/include/x86_64-linux-gnu/bits/types/__sigset_t.h \
|
||||
/usr/include/CUnit/TestRun.h \
|
||||
/home/vagrant/snp/testlib/include/test_utils.h
|
Binary file not shown.
Loading…
Reference in New Issue