Assignment for C Programming - Recursion and Sorting
Task2/sample_length_3.txt
*** %%% %## %$$ ##% $$%
Task2/sample_length_5.txt
***%% ***## ***$$ %***% %%*** %%%%% %%%## %%%$$ %%##% %%$$% %##%% %#### %##$$ %$$%% %$$## %$$$$ ##*** ##%%% ##%## ##%$$ ####% ##$$% $$*** $$%%% $$%## $$%$$ $$##% $$$$%
Task2/task2.cpp
#include <cstdio> #include <iostream> #include <string> using namespace std; #define EMPTY '-' struct Tile { int size; char pattern; }; void init_floor(string& floor, int size) { int i; floor.clear(); //clear the content of string floor.assign(size, EMPTY); //fill string with "size" copies of EMPTY '-' } void put_tile(string& floor, int loc, Tile* tilePtr) { int i; for (i = 0; i < tilePtr->size; i++){ floor[loc+i] = tilePtr->pattern; } } void remove_tile(string& floor, int loc, Tile* tilePtr) { int i; for (i = 0; i < tilePtr->size; i++){ floor[loc+i] = EMPTY; } } void tile_floor(string& floor, int loc, Tile tileArray[], int numTiles) { //Only nee dto write this function } int main() { Tile tileSet[4] = { {3, '*'}, {1, '%'}, {2, '#'}, {2, '$'}}; string floor; //This example test a floor length of 3 // You should test additional values to ensure correctness init_floor(floor, 3); tile_floor(floor, 0, tileSet, 4); return 0; }