Commit fb595546 authored by Michael's avatar Michael

michael.davityan:exercise_07_35v2

parent 6d3c86ad
progname=exercise_07_35
CC=g++
CFLAGS=-Wall -Wextra -Werror -g3
all: test1
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
5
2 3 5 7 9
5
12.5 23.4 67.1 32.25 89.96
6
radar
#include <iostream>
#include <iomanip>
#include <unistd.h>
template <typename T>
void
printArray(const T array[], const size_t sizeOfArray, const size_t firstIdx = 0)
{
std::cout << array[firstIdx];
if (firstIdx == sizeOfArray - 1) {
std::cout << std::endl;
return;
}
if (sizeof(T) > 1) {
std::cout << ", ";
}
return printArray(array, sizeOfArray, firstIdx + 1);
}
template <typename T>
void
numericArrayInitialization(T array[], const size_t sizeOfArray)
{
for (size_t index = 0; index < sizeOfArray; ++index) {
if (::isatty(STDIN_FILENO)) {
std::cout << "element " << index + 1 << ": ";
}
std::cin >> array[index];
}
}
void
charsArrayInitialization(char array[], const size_t sizeOfArray)
{
if (::isatty(STDIN_FILENO)) {
std::cout << "word: ";
}
std::cin >> std::setw(sizeOfArray) >> array;
}
int
main()
{
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert integers array size and elements.\n" << "size: ";
}
size_t integersArraySize;
std::cin >> integersArraySize;
int integersArray[integersArraySize];
numericArrayInitialization(integersArray, integersArraySize);
printArray(integersArray, integersArraySize);
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert floating numbers array size and elements.\n" << "size: ";
}
size_t floatingArraySize;
std::cin >> floatingArraySize;
double floatingArray[floatingArraySize];
numericArrayInitialization(floatingArray, floatingArraySize);
printArray(floatingArray, floatingArraySize);
if (::isatty(STDIN_FILENO)) {
std::cout << "Insert characters array size and elements.\n" << "size: ";
}
size_t charactersArraySize;
std::cin >> charactersArraySize;
char charactersArray[charactersArraySize];
charsArrayInitialization(charactersArray, charactersArraySize);
printArray(charactersArray, charactersArraySize);
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