1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
#include <iostream>
#include <ctime>
#include <cstdlib>
#define BLOCK std::cout<<(char)'\xdb';
#define END '\n';
const int YMAX=10,XMAX=10;//GLOBAL - small simple program!
void option_one()
{
for(int y=0;y<YMAX;y++)
{
for(int x=0;x<XMAX;x++)
{
if(y==0||y==XMAX-1)
{
BLOCK;
}
else
{
if(x==0||x==XMAX-1)
{
BLOCK;
}
else
{
std::cout<<" ";
}
}
}
std::cout<<END;
}
}
void option_two()
{
char arry[YMAX][XMAX]=
{
{'\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb'},
{'\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb'}
};
for(int y=0;y<YMAX;y++)
{
for(int x=0;x<XMAX;x++)
{
std::cout<<arry[y][x];
}
std::cout<<END;
}
}
void option_three()//Implemented by OP
{
for(int top=1;top<=10;top++){
BLOCK;
}
std::cout<<END;
for(int height=1;height<=8;height++){
for(int c=1;c<=1;c++){
BLOCK;
}
for(int right_edge=1;right_edge<=8;right_edge++){
std::cout<<' ';
}
BLOCK;
std::cout<<END;
}
for(int bottom=1;bottom<=10;bottom++){
BLOCK;
}
std::cout<<END;
}
void option_four()//For additional competition
{
char str[2][11] = {
{'\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\xdb','\0'},
{'\xdb',' ',' ',' ',' ',' ',' ',' ',' ','\xdb','\0'}
};
std::cout<<str[0]<<END;
for(int i=0;i<YMAX-2;i++)
std::cout<<str[1]<<END;
std::cout<<str[0]<<END;
}
void option_five()//naraku933's
{
std::cout << std::string(XMAX, '*') << END;
for(int i = 0; i < YMAX - 2; ++i)
std::cout << '*' << std::string(XMAX - 2, ' ') << '*' << END;
std::cout << std::string(XMAX, '*') << END;
}
int main()
{
clock_t t;
//Array of pointers to functions with no arguments and no return type:
void (*option[])() = {&option_one,&option_two,&option_three,&option_four,&option_five};
std::string choice="";
std::cout<<"How many cycles should we test: ";
getline(std::cin,choice);
int rounds = atoi(choice.c_str());
float *table[rounds]; //Array of pointers, size = rounds
for(int test=0;test<rounds;test++)
{
table[test] = new float[5]; //5 options: each array pointing to 5 new floats
for(int i=0;i<5;i++) //5 options
{
t = clock();
option[i]();
table[test][i] = t = clock()-t;
std::cout<<"Option "<<i+1<<" took: "<<float(t)/CLOCKS_PER_SEC<<" seconds."<<END;
}
}
std::cout<<"-----"<<END;
float *sums = new float[5]{0,0,0,0,0};
for(int i=0;i<rounds;i++)//Delete embedded pointers
{
for(int j=0;j<5;j++)
{
sums[j]+=table[i][j];
}
delete []table[i];//deleting the 5 heaps per index
}
for(int i=0;i<5;i++)
{
std::cout<<"Option "<<i+1<<" took: "<<(float(sums[i])/CLOCKS_PER_SEC)/rounds<<" seconds, on average, out of "<<rounds<<" tests."<<END;
}
delete []sums;
std::cout<<"\nCustom exit: press Enter to exit";
std::cin.get();
return 0;
}
|