Commit ad0c0510 authored by Michael's avatar Michael

michael.davityan:exercise_05_24v3

parent f2088732
progname=exercise_05_24
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1 test2 test3 test4 test5
debug/$(progname): debug/$(progname).o
$(CC) $(CFLAGS) $< -o $@
debug/%.o: debug/%.s
$(CC) -c $(CFLAGS) $< -o $@
debug/%.s: debug/%.ii
$(CC) -S $(CFLAGS) $< -o $@
debug/%.ii: %.cpp | debug
$(CC) -E $(CFLAGS) $< -o $@
debug:
mkdir -p debug
clean:
rm -r debug Tests/*.out
test%: debug/$(progname)
@./debug/$(progname) < Tests/$@.in > Tests/$@.out 2>&1 || echo "$@ is executing..."
@diff Tests/$@.out Tests/$@.expected && echo PASSED || echo FAILED
.PRECIOUS: debug/%.ii debug/%.s
.SECONDARY: debug/%.ii debug/%.s
*
***
*****
*******
*********
***********
*************
***************
*************
***********
*********
*******
*****
***
*
Error 1: wrong number(must be odd number from 1->19).
Error 1: wrong number(must be odd number from 1->19).
Error 1: wrong number(must be odd number from 1->19).
#include <iostream>
#include <unistd.h>
#include <cmath>
int
main()
{
int lineCount;
if (::isatty(STDIN_FILENO)) {
std::cout << "insert line count(must be odd number from 1->19): ";
}
std::cin >> lineCount;
if (lineCount % 2 == 0 || lineCount < 1 || lineCount > 19) {
std::cerr << "Error 1: wrong number(must be odd number from 1->19).\n";
return 1;
}
const int LINE_LIMIT = (lineCount - 1) / 2;
for (int row = LINE_LIMIT; row >= -LINE_LIMIT; --row) {
for (int column = -LINE_LIMIT; column <= (LINE_LIMIT - std::abs(row)) + 1; ++column) {
std::cout << (column <= std::abs(row) - LINE_LIMIT ? " " : "*");
}
std::cout << std::endl;
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment