Skip to content
Snippets Groups Projects
Commit fd1f905f authored by Husam-Ahmad's avatar Husam-Ahmad
Browse files

perfect

parent 6ac72b42
No related branches found
No related tags found
No related merge requests found
{
"files.associations": {
"iomanip": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"regex": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp"
}
}
\ No newline at end of file
File deleted
......@@ -6,6 +6,11 @@ int config_min = -99;
int config_max = 100;
int config_width = 3;
std::string config_align = "left";
int config_stretch = 0;
bool isstretchprovided = false;
int config_header = 1;
bool isheaderprovided = false;
std::vector<std::vector<std::string>> table; // data from the table
......@@ -51,8 +56,12 @@ void printconfig()
{
std::cout << "config.min=" << config_min << std::endl;
std::cout << "config.max=" << config_max << std::endl;
std::cout << "config.width=" << config_width << std::endl;
std::cout << "config.width=" << config_width + config_stretch << std::endl;
std::cout << "config.align=" << config_align << std::endl;
if (isheaderprovided)
std::cout << "config.header=" << config_header << std::endl;
if (isstretchprovided)
std::cout << "config.stretch=" << config_stretch << std::endl;
std::cout << "\n";
}
......@@ -85,6 +94,8 @@ void dothesum()
}
}
row[i] = std::to_string(sum);
if ((static_cast<int>(row[i].length()) > config_width) && !isstretchprovided)
errorhere("Cell is too short", 103);
}
}
}
......@@ -98,24 +109,76 @@ void printthedamntable()
if (row.size() > maxcols)
maxcols = row.size();
}
std::string border = "+-" + std::string(config_width, '-') + "-";
for (size_t i = 0; i < maxcols; i++)
border += "+-" + std::string(config_width, '-') + "-";
std::string border = "+-" + std::string(config_width + config_stretch, '-') + "-";
if (config_header == 1)
for (size_t i = 0; i < maxcols; i++)
border += "+-" + std::string(config_width + config_stretch, '-') + "-";
else if (config_header == 0)
for (size_t i = 1; i < maxcols; i++)
border += "+-" + std::string(config_width + config_stretch, '-') + "-";
border += "+";
if (config_header == 1)
{
std::cout << border << std::endl;
std::cout << "| " << std::string(config_width + config_stretch, ' ') << " |";
for (size_t i = 0; i < maxcols; i++)
std::cout << " " << std::setw(config_width + config_stretch) << (config_align == "left" ? std::left : std::right) << static_cast<char>('A' + i) << " |";
std::cout << std::endl;
}
std::cout << border << std::endl;
std::cout << "| " << std::string(config_width, '-') << " |";
for (size_t i = 0; i < maxcols; i++)
std::cout << " " << std::setw(config_width) << (config_align == "left" ? std::left : std::right) << static_cast<char>('A' + i) << " |";
std::cout << std::endl << border << std::endl;
for (size_t i = 0; i < table.size(); i++)
if (config_header == 1)
{
for (size_t i = 0; i < table.size(); i++)
{
std::cout << "| " << std::setw(config_width + config_stretch);
std::cout << (config_align == "left" ? std::left : std::right) << i + 1;
std::cout << " |";
for (size_t j = 0; j < maxcols; j++)
{
if (((size_t)(config_width + config_stretch) >= table[i][j].size()) || table[i][j].size() > 10)
{
std::cout << " " << std::setw(config_width + config_stretch) << (config_align == "left" ? std::left : std::right);
std::cout << (j < table[i].size() ? table[i][j] : "");
}
else
{
std::cout << " " << (config_align == "left" ? std::left : std::right);
for (int l = 0; (config_width + config_stretch) > l; l++)
std::cout << "#";
}
std::cout << " |";
}
std::cout << std::endl << border << std::endl;
}
}
if (config_header == 0)
{
std::cout << "| " << std::setw(config_width) << (config_align == "left" ? std::left : std::right) << i + 1 << " |";
for (size_t j = 0; j < maxcols; j++)
std::cout << " " << std::setw(config_width) << (config_align == "left" ? std::left : std::right) << (j < table[i].size() ? table[i][j] : "") << " |";
std::cout << std::endl << border << std::endl;
for (size_t i = 0; i < table.size(); i++)
{
std::cout << "|";
for (size_t j = 0; j < maxcols; j++)
{
if (((size_t)(config_width + config_stretch) >= table[i][j].size()) || table[i][j].size() > 10)
{
std::cout << " " << std::setw(config_width + config_stretch) << (config_align == "left" ? std::left : std::right);
std::cout << (j < table[i].size() ? table[i][j] : "");
}
else
{
std::cout << " " << (config_align == "left" ? std::left : std::right);
for (int l = 0; (config_width + config_stretch) > l; l++)
std::cout << "#";
}
std::cout << " |";
}
std::cout << std::endl << border << std::endl;
}
}
}
// << std::setw(config_width + config_stretch)
config_t configureit(std::string init)
{
config_t config;
......@@ -185,7 +248,6 @@ void draw_line(int columns, int width)
int main()
{
std::string init, svalue, cell;
int longest;
while(std::getline(std::cin, init) && init != "=")
{
......@@ -204,6 +266,16 @@ int main()
}
else if (config.type == "align")
config_align = config.value;
else if (config.type == "stretch")
{
config_stretch = std::stoi(config.value);
isstretchprovided = true;
}
else if (config.type == "header")
{
config_header = std::stoi(config.value);
isheaderprovided = true;
}
}
else
errorhere("Invalid configuration", 102);
......@@ -218,21 +290,20 @@ int main()
while ((end = svalue.find(';', start)) != std::string::npos)
{
cell = svalue.substr(start, end - start);
if (static_cast<int>(cell.length()) > config_width)
errorhere("Cell is too short", 100);
start = 1 + end;
row.push_back(svalue.empty() ? " " : cell);
}
row.push_back(svalue.substr(start)); // to add the last element
if (endswithsemicolon)
row.push_back(" ");
row.push_back(" ");
table.push_back(row);
}
if (isoutofrange())
return 100;
printconfig();
dothesum();
printconfig();
printthedamntable();
// printf("\n\n%d", (int)table[0][2].size());
}
// // -40;-50;-60;-70
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment