Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <array>
- #include <vector>
- #include <cstddef>
- #include <cmath> // TODO: C++ needs cmath not math.h
- #include <memory>
- //using namespace std; // TODO: don't do this, it's a bad habit!
- char constexpr SS = '/'; // TODO: it is a constant, make it so
- class TireSlot { // TODO: keep class definition neat
- public:
- std::string Size;
- std::array<float, 3> SizeDblArr {};
- float TireWidth;
- float TireaSpect;
- float TireRim;
- char Src;
- int Amt;
- int AmtS;
- };
- float constexpr WAr[/*29*/] { // TODO: it is a constant, make it so
- // TODO: braces around elements are not needed
- // TODO: make it cleare these are floats
- 125.0f, 135.0f, 145.0f, 155.0f, 165.0f, 175.0f, 185.0f,
- 195.0f, 205.0f, 215.0f, 225.0f, 235.0f, 245.0f, 255.0f,
- 265.0f, 275.0f, 285.0f, 295.0f, 305.0f, 315.0f, 325.0f,
- 335.0f, 345.0f, 355.0f, 365.0f, 375.0f, 385.0f, 395.0f,
- 405.0f,
- };
- size_t constexpr WAR_l(sizeof(WAr) / sizeof(*WAr)); // TODO: let the compiler do it
- float constexpr RAr[/*38*/] { // TODO: it is a constant, make it so
- 10.0f, 10.5f, 11.0f, 11.5f, 12.0f, 12.5f, 13.0f,
- 13.5f, 14.0f, 14.5f, 15.0f, 15.5f, 16.0f, 16.5f,
- 17.0f, 17.5f, 18.0f, 18.5f, 19.0f, 19.5f, 20.0f,
- 20.5f, 21.0f, 21.5f, 22.0f, 22.5f, 23.0f, 23.5f,
- 24.0f, 24.5f, 25.0f, 25.5f, 26.0f, 26.5f, 27.0f,
- 27.5f, 28.0f, 28.5f,
- };
- size_t constexpr RAR_l(sizeof(RAr) / sizeof(*RAr)); // TODO: let the compiler do it
- float constexpr SAr[/*15*/] { // TODO: it is a constant, make it so
- 25.0f, 30.0f, 35.0f, 40.0f, 45.0f,
- 50.0f, 55.0f, 60.0f, 65.0f, 70.0f,
- 75.0f, 80.0f, 85.0f, 90.0f, 95.0f,
- };
- size_t constexpr SAR_l(sizeof(SAr) / sizeof(*SAr)); // TODO: let the compiler do it
- #define AS_DYNAMIC_
- #ifdef AS_DYNAMIC_
- // MARK: Structure DB_container
- struct DB_container {
- std::array<std::array<std::array<TireSlot, /*29*/WAR_l>, /*15*/SAR_l>, /*38*/RAR_l> DB;
- DB_container() {
- std::cout << "DB_container constructor" << std::endl;
- }
- ~DB_container() {
- std::cout << "DB_container destructor" << std::endl;
- }
- #endif
- };
- // MARK: DB Globally allocated
- auto DBC = std::make_shared<DB_container>();
- /*
- * MARK: main()
- */
- int main() {
- // TODO: dispense with magic numbers
- #ifdef AS_DYNAMIC_
- if (!DBC) {
- // TODO: go BOOM!
- throw std::runtime_error("Datastore unavailable.");
- }
- #else
- std::array<std::array<std::array<TireSlot, /*29*/WAR_l>, /*15*/SAR_l>, /*38*/RAR_l> DB;
- #endif
- //DB[29][15][38]; // TODO: not needed
- for (size_t ac = 0; ac < /*29*/WAR_l; ac++) { // TODO: array index can be up to SIZE_MAX which is > short
- for (size_t bc = 0; bc < /*15*/SAR_l; bc++) {
- for (size_t cc = 0; cc < /*38*/RAR_l; cc++) {
- #ifndef AS_DYNAMIC_
- DB[ac][bc][cc].TireRim = RAr[cc];
- DB[ac][bc][cc].TireaSpect = SAr[bc];
- DB[ac][bc][cc].TireWidth = WAr[ac];
- #else
- DBC->DB[ac][bc][cc].TireRim = RAr[cc];
- DBC->DB[ac][bc][cc].TireaSpect = SAr[bc];
- DBC->DB[ac][bc][cc].TireWidth = WAr[ac];
- #endif
- std::string tStr;
- float AC = WAr[ac];
- float BC = SAr[bc];
- float CC = RAr[cc];
- std::string As = std::to_string(AC);
- std::string Bs = std::to_string(BC);
- std::string Cs = std::to_string(CC);
- std::string Ss = "/";
- As += Ss;
- Bs += Ss;
- tStr = As + Bs + Cs;
- #ifndef AS_DYNAMIC_
- DB[ac][bc][cc].Size = tStr;
- DB[ac][bc][cc].Amt = 0;
- DB[ac][bc][cc].AmtS = 0;
- #else
- DBC->DB[ac][bc][cc].Size = tStr;
- DBC->DB[ac][bc][cc].Amt = 0;
- DBC->DB[ac][bc][cc].AmtS = 0;
- #endif
- }
- }
- }
- size_t count = 0;
- for (size_t zx = 0; zx < /*29*/WAR_l; zx++) { // TODO: array index can be up to SIZE_MAX which is > int
- for (size_t zy = 0; zy < /*15*/SAR_l; zy++) {
- for (size_t zz = 0; zz < /*38*/RAR_l; zz++) {
- // TODO: pretty print
- std::cout << "Entry:" << std::setfill(' ') << std::setw(10) << ++count << '\n'
- << "[" << std::setfill(' ') << std::setw(3) << zx
- << "][" << std::setfill(' ') << std::setw(3) << zy
- << "][" << std::setfill(' ') << std::setw(3) << zz
- << "]\n";
- #ifndef AS_DYNAMIC_
- std::cout << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DB[zx][zy][zz].TireWidth
- << SS
- << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DB[zx][zy][zz].TireaSpect
- << SS
- << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DB[zx][zy][zz].TireRim
- << " ["
- << DB[zx][zy][zz].Amt
- << SS
- << DB[zx][zy][zz].AmtS
- << "]"
- << '\n'
- << std::endl; // TODO: keep std::endl to a minimum, it calls a buffer flush.
- #else
- std::cout << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DBC->DB[zx][zy][zz].TireWidth
- << SS
- << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DBC->DB[zx][zy][zz].TireaSpect
- << SS
- << std::fixed << std::setw(5) << std::setprecision(1) << std::setfill('0')
- << DBC->DB[zx][zy][zz].TireRim
- << " ["
- << DBC->DB[zx][zy][zz].Amt
- << SS
- << DBC->DB[zx][zy][zz].AmtS
- << "]"
- << '\n'
- << std::endl; // TODO: keep std::endl to a minimum, it calls a buffer flush.
- #endif
- };
- };
- };
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement