Skip to content

Commit

Permalink
Merge pull request #4 from malikalhack/fixes
Browse files Browse the repository at this point in the history
Release version 1.1.0
Fixed bugs and warnings
  • Loading branch information
malikalhack2 authored Nov 6, 2022
2 parents b19d92d + 25bd41c commit 0b0d79b
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 78 deletions.
5 changes: 4 additions & 1 deletion Common/inc/common.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/**
* @file common.h
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 02/11/2022
* @date 06/11/2022
*/

#ifndef COMMON_H
#define COMMON_H
/****************************** Included files ********************************/
#include <stdint.h>
/******************************** Definition **********************************/
#define HALF_PARAMETER(param) ((param) & 0x1 ? (param) / 2 + 1 : (param) / 2)

typedef uint16_t coordinate_t;
typedef signed short offset_t;
typedef unsigned short abs_offset_t;
Expand Down
2 changes: 1 addition & 1 deletion Common/inc/coordinate.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file coordinate.h
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 27/10/2022
* @date 02/11/2022
Expand Down
4 changes: 3 additions & 1 deletion Common/inc/test.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* @file test.h
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 30/10/2022
* @date 06/11/2022
*/

#ifndef TEST_H
Expand All @@ -11,6 +12,7 @@
#include <stdbool.h>
#include <stdio.h>
/******************************** Definition **********************************/
#define DISCARD_RETURN(f) ((void)f)
#define TEST_START(name)\
printf("\n\r>>> Test start for %s <<<\n\n", name)
#define TEST_FINISH \
Expand Down
5 changes: 3 additions & 2 deletions Common/src/common.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/**
* @file common.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 02/11/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
#include "common.h"
/***************************** Public functions *******************************/
abs_offset_t abs(offset_t num) {
return (abs_offset_t)(num < 0 ? num *= -1 : num);
return (abs_offset_t)(num < 0 ? -num : num);
}
/******************************************************************************/
2 changes: 1 addition & 1 deletion Common/src/coordinate.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file coordinate.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 27/10/2022
* @date 02/11/2022
Expand Down
5 changes: 3 additions & 2 deletions Common/src/test.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* @file test.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 30/10/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
Expand All @@ -12,7 +13,7 @@ bool DoRepeat(void) {
char answer;
printf("Would you like to repeat the test? ");
fflush(stdout);
scanf(" %c", &answer);
DISCARD_RETURN(scanf(" %c", &answer));
return (((answer == 'y') || (answer == 'Y')) ? true : false);
}
/******************************************************************************/
1 change: 1 addition & 0 deletions Encapsulation/Encapsulation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
<ClCompile Include="src\main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\Common\inc\common.h" />
<ClInclude Include="..\Common\inc\coordinate.h" />
<ClInclude Include="..\Common\inc\test.h" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions Encapsulation/Encapsulation.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@
<ClInclude Include="..\Common\inc\test.h">
<Filter>Include</Filter>
</ClInclude>
<ClInclude Include="..\Common\inc\common.h">
<Filter>Include</Filter>
</ClInclude>
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions Encapsulation/src/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file main.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 27/10/2022
* @date 02/11/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
Expand Down Expand Up @@ -71,17 +71,17 @@ int main(void) {
TEST_START("moving to specified coordinates");
printf("Enter coordinates for point p1:\nx: ");
fflush(stdout);
scanf_s("%hu", &x);
DISCARD_RETURN(scanf(" %hu", &x));
printf("y: ");
fflush(stdout);
scanf_s("%hu", &y);
DISCARD_RETURN(scanf(" %hu", &y));
MoveToCoordinate(&p1, x, y);
printf("\nEnter coordinates for point p2:\nx: ");
fflush(stdout);
scanf_s("%hu", &x);
DISCARD_RETURN(scanf(" %hu", &x));
printf("y: ");
fflush(stdout);
scanf_s("%hu", &y);
DISCARD_RETURN(scanf(" %hu", &y));
MoveToCoordinate(&p2, x, y);
PrintCoordinatesOfBothPoints(&p1, &p2);
TEST_FINISH;
Expand All @@ -92,17 +92,17 @@ int main(void) {
TEST_START("moving to the specified offset");
printf("Enter offset for point p1:\nx: ");
fflush(stdout);
scanf(" %hd", &xof);
DISCARD_RETURN(scanf(" %hd", &xof));
printf("y: ");
fflush(stdout);
scanf(" %hd", &yof);
DISCARD_RETURN(scanf(" %hd", &yof));
MoveFromCurrentPoint(&p1, xof, yof);
printf("\nEnter coordinates for point p2:\nx: ");
fflush(stdout);
scanf(" %hd", &xof);
DISCARD_RETURN(scanf(" %hd", &xof));
printf("y: ");
fflush(stdout);
scanf(" %hd", &yof);
DISCARD_RETURN(scanf(" %hd", &yof));
MoveFromCurrentPoint(&p2, xof, yof);
PrintCoordinatesOfBothPoints(&p1, &p2);
TEST_FINISH;
Expand Down
2 changes: 1 addition & 1 deletion Inheritance/inc/rectangle.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file rectangle.h
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 29/10/2022
* @date 02/11/2022
Expand Down
28 changes: 14 additions & 14 deletions Inheritance/src/main.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file main.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 29/10/2022
* @date 01/11/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
Expand All @@ -28,18 +28,18 @@ int main(void) {
params_t l, w;
printf("\nEnter the width of rectangle r1: ");
fflush(stdout);
scanf("%hu", &w);
DISCARD_RETURN(scanf(" %hu", &w));
printf("Enter the length of rectangle r1: ");
fflush(stdout);
scanf("%hu", &l);
DISCARD_RETURN(scanf(" %hu", &l));
Rectangle_ctor(&r1, w, l);

printf("\nEnter the width of rectangle r2: ");
fflush(stdout);
scanf("%hu", &w);
DISCARD_RETURN(scanf(" %hu", &w));
printf("Enter the length of rectangle r2: ");
fflush(stdout);
scanf("%hu", &l);
DISCARD_RETURN(scanf(" %hu", &l));
Rectangle_ctor(&r2, w, l);
}
printf(
Expand Down Expand Up @@ -91,17 +91,17 @@ int main(void) {
TEST_START("moving to specified coordinates");
printf("Enter coordinates for center point of the rectangle r1:\nx: ");
fflush(stdout);
scanf_s("%hu", &x);
DISCARD_RETURN(scanf(" %hu", &x));
printf("y: ");
fflush(stdout);
scanf_s("%hu", &y);
DISCARD_RETURN(scanf(" %hu", &y));
MoveToCoordinate(SUPER_UPCAST(&r1), x, y);
printf("\nEnter coordinates for center point of the rectangle r2:\nx: ");
fflush(stdout);
scanf_s("%hu", &x);
DISCARD_RETURN(scanf(" %hu", &x));
printf("y: ");
fflush(stdout);
scanf_s("%hu", &y);
DISCARD_RETURN(scanf(" %hu", &y));
MoveToCoordinate(SUPER_UPCAST(&r2), x, y);
PrintCoordinatesOfBothRectangles(&r1, &r2);
TEST_FINISH;
Expand All @@ -112,17 +112,17 @@ int main(void) {
TEST_START("moving to the specified offset");
printf("Enter offset for center point of the rectangle r1:\nx: ");
fflush(stdout);
scanf(" %hd", &xof);
DISCARD_RETURN(scanf(" %hd", &xof));
printf("y: ");
fflush(stdout);
scanf(" %hd", &yof);
DISCARD_RETURN(scanf(" %hd", &yof));
MoveFromCurrentPoint(SUPER_UPCAST(&r1), xof, yof);
printf("\nEnter offset for center point of the rectangle r2:\nx: ");
fflush(stdout);
scanf(" %hd", &xof);
DISCARD_RETURN(scanf(" %hd", &xof));
printf("y: ");
fflush(stdout);
scanf(" %hd", &yof);
DISCARD_RETURN(scanf(" %hd", &yof));
MoveFromCurrentPoint(SUPER_UPCAST(&r2), xof, yof);
PrintCoordinatesOfBothRectangles(&r1, &r2);
TEST_FINISH;
Expand Down
24 changes: 12 additions & 12 deletions Inheritance/src/rectangle.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file rectangle.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 29/10/2022
* @date 02/11/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
Expand Down Expand Up @@ -31,7 +31,7 @@ static void make_move(
coordinate_t const limit
) {
if (*offset) {
coordinate_t lower_limit = *param / 2;
coordinate_t lower_limit = HALF_PARAMETER(*param);
coordinate_t higher_limit = limit - lower_limit;
abs_offset_t abs_offset = abs(*offset);

Expand All @@ -53,7 +53,7 @@ static coordinate_t make_rebase(
coordinate_t const limit
) {
coordinate_t result;
coordinate_t lower_limit = *param / 2;
coordinate_t lower_limit = HALF_PARAMETER(*param);
coordinate_t higher_limit = limit - lower_limit;

if (*new_coordinate < lower_limit) { result = lower_limit; }
Expand Down Expand Up @@ -136,26 +136,26 @@ static void RectangleMoveFromCurrentPoint_(
/*----------------------------------------------------------------------------*/
static void RectangleMoveToTheLowerLeftCorner_(Coordinate * const self) {
Rectangle * const _self = (Rectangle *)self; /* explicit downcast */
_self->super.x = _self->length / 2;
_self->super.y = _self->width / 2;
_self->super.x = HALF_PARAMETER(_self->length);
_self->super.y = HALF_PARAMETER(_self->width);
}
/*----------------------------------------------------------------------------*/
static void RectangleMoveToTheUpperLeftCorner_(Coordinate * const self) {
Rectangle * const _self = (Rectangle *)self; /* explicit downcast */
_self->super.x = _self->length / 2;
_self->super.y = Y_LIMIT - _self->width / 2;
_self->super.x = HALF_PARAMETER(_self->length);
_self->super.y = Y_LIMIT - HALF_PARAMETER(_self->width);
}
/*----------------------------------------------------------------------------*/
static void RectangleMoveToTheLowerRightCorner_(Coordinate * const self) {
Rectangle * const _self = (Rectangle *)self; /* explicit downcast */
_self->super.x = X_LIMIT - _self->length / 2;
_self->super.y = _self->width / 2;
_self->super.x = X_LIMIT - HALF_PARAMETER(_self->length);
_self->super.y = HALF_PARAMETER(_self->width);
}
/*----------------------------------------------------------------------------*/
static void RectangleMoveToTheUpperRightCorner_(Coordinate * const self) {
Rectangle * const _self = (Rectangle *)self; /* explicit downcast */
_self->super.x = X_LIMIT - _self->length / 2;
_self->super.y = Y_LIMIT - _self->width / 2;
_self->super.x = X_LIMIT - HALF_PARAMETER(_self->length);
_self->super.y = Y_LIMIT - HALF_PARAMETER(_self->width);
}
/*----------------------------------------------------------------------------*/
static void RectangleMoveToTheCenter_(Coordinate * const self) {
Expand Down
2 changes: 1 addition & 1 deletion Polymorphism/inc/circle.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @file circle.h
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 01/11/2022
* @date 02/11/2022
Expand Down
16 changes: 8 additions & 8 deletions Polymorphism/src/circle.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* @file circle.c
* @version 1.0.0
* @version 1.1.0
* @authors Anton Chernov
* @date 01/11/2022
* @date 02/11/2022
* @date 06/11/2022
*/

/****************************** Included files ********************************/
Expand All @@ -29,7 +29,7 @@ static void make_move(
coordinate_t const limit
) {
if (*offset) {
coordinate_t lower_limit = *param / 2;
coordinate_t lower_limit = HALF_PARAMETER(*param);
coordinate_t higher_limit = limit - lower_limit;
abs_offset_t abs_offset = abs(*offset);

Expand All @@ -51,7 +51,7 @@ static coordinate_t make_rebase(
coordinate_t const limit
) {
coordinate_t result;
coordinate_t lower_limit = *param / 2;
coordinate_t lower_limit = HALF_PARAMETER(*param);
coordinate_t higher_limit = limit - lower_limit;

if (*new_coordinate < lower_limit) { result = lower_limit; }
Expand Down Expand Up @@ -120,26 +120,26 @@ static void CircleMoveFromCurrentPoint_(
/*----------------------------------------------------------------------------*/
static void CircleMoveToTheLowerLeftCorner_(Coordinate * const self) {
Circle * const _self = (Circle *)self; /* explicit downcast */
radius_t temp = _self->radius / 2;
radius_t temp = HALF_PARAMETER(_self->radius);
_self->super.x = temp;
_self->super.y = temp;
}
/*----------------------------------------------------------------------------*/
static void CircleMoveToTheUpperLeftCorner_(Coordinate * const self) {
Circle * const _self = (Circle *)self; /* explicit downcast */
_self->super.x = _self->radius / 2;
_self->super.x = HALF_PARAMETER(_self->radius);
_self->super.y = Y_LIMIT - _self->super.x;
}
/*----------------------------------------------------------------------------*/
static void CircleMoveToTheLowerRightCorner_(Coordinate * const self) {
Circle * const _self = (Circle *)self; /* explicit downcast */
_self->super.y = _self->radius / 2;
_self->super.y = HALF_PARAMETER(_self->radius);
_self->super.x = X_LIMIT - _self->super.y;
}
/*----------------------------------------------------------------------------*/
static void CircleMoveToTheUpperRightCorner_(Coordinate * const self) {
Circle * const _self = (Circle *)self; /* explicit downcast */
radius_t temp = _self->radius / 2;
radius_t temp = HALF_PARAMETER(_self->radius);
_self->super.x = X_LIMIT - temp;
_self->super.y = Y_LIMIT - temp;
}
Expand Down
Loading

0 comments on commit 0b0d79b

Please sign in to comment.