From: Lukas Jiriste Date: Thu, 24 Oct 2024 12:47:48 +0000 (+0200) Subject: Add main.cpp and Makefile to ex01 X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=3208c61e9ab3266bbfa39f5d7cfaf41c13f56929;p=42%2FCPP_Module_02 Add main.cpp and Makefile to ex01 --- diff --git a/ex01/Makefile b/ex01/Makefile new file mode 100644 index 0000000..3bd789c --- /dev/null +++ b/ex01/Makefile @@ -0,0 +1,53 @@ +CC := c++ +CFLAGS = -std=c++98 -Wall -Wextra -Werror -Wpedantic + +ifneq ("$(wildcard .debug)","") + CFLAGS += -g +endif + +RM := rm -f + +INCDIR := inc +INCDIR += $(addsuffix /inc, $(SUBPROJECTS)); +ifneq ($(INCLUDE),) + INCLUDE := $(addprefix -I, $(INCDIR)) +endif + +SRCDIR := . + +SOURCES := main.cpp \ + Fixed.cpp \ + +SOURCES := $(addprefix $(SRCDIR)/, $(SOURCES)) + +OBJECTS := $(SOURCES:.cpp=.o) + +NAME := fixed + +all : $(NAME) + +debug : .debug + $(MAKE) all + +nodebug : + $(RM) .debug + $(MAKE) re + +.% : + $(MAKE) fclean + touch $@ + +$(NAME) : $(OBJECTS) + $(CC) $(CFLAGS) -o $@ $^ $(LINKS) + +%.o : %.cpp + $(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE) + +clean : + $(RM) $(OBJECTS) + +fclean : clean + $(RM) $(NAME) + +re : fclean + $(MAKE) all diff --git a/ex01/main.cpp b/ex01/main.cpp new file mode 100644 index 0000000..e07f107 --- /dev/null +++ b/ex01/main.cpp @@ -0,0 +1,21 @@ +#include "Fixed.h" +#include + +int main() +{ + Fixed a; + Fixed const b( 10 ); + Fixed const c( 42.42f ); + Fixed const d( b ); + + a = Fixed( 1234.4321f ); + std::cout << "a is " << a << std::endl; + std::cout << "b is " << b << std::endl; + std::cout << "c is " << c << std::endl; + std::cout << "d is " << d << std::endl; + std::cout << "a is " << a.toInt() << " as integer" << std::endl; + std::cout << "b is " << b.toInt() << " as integer" << std::endl; + std::cout << "c is " << c.toInt() << " as integer" << std::endl; + std::cout << "d is " << d.toInt() << " as integer" << std::endl; + return (0); +}