Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string>
- #include "Skyscraper.h"
- #include "Tree.h"
- #define NEW_LINE cout << endl;
- using namespace std;
- int main()
- {
- string prompt = "=>";
- string cmdline;
- bool on = true;
- while (on)
- {
- NEW_LINE
- cout << prompt; getline(cin, cmdline);
- if (cmdline == "exit") on = false; // Exit clause
- // Multiple argument commands
- else if (!cmdline.empty())
- {
- // Separate cmdline input into vector containing each arg
- const char* yourStr = cmdline.c_str();
- char str[100];
- strncpy(str, yourStr, sizeof(str));
- char* parts[10] = {0};
- unsigned int index = 0;
- parts[index] = strtok(str," ");
- while(parts[index] != 0)
- {
- ++index;
- parts[index] = strtok(0, " ");
- }
- // Now evaluate command
- if (string(parts[0]) == "hex2dec") // Convert hexadecimal to decimal
- {
- cout << parts[1] << " base 16 = ";
- int converted = strtol(parts[1], NULL, 16);
- cout << converted << " base 10.";
- }
- else if (string(parts[0]) == "dec2hex") // Convert decimal to hexadecimal
- {
- cout << parts[1] << " base 10 = ";
- int converted = strtol(parts[1], NULL, 10);
- cout << hex << uppercase << converted << " base 16.";
- }
- else if (string(parts[0]) == "prompt") // Change the prompt
- {
- prompt = string(parts[1]);
- }
- else if (string(parts[0]) == "draw") // Draw a....
- {
- if (string(parts[1]) == "tree") // Tree must specify height
- {
- int height = strtol(parts[2], NULL, 10);
- Tree arbre(height);
- arbre.drawTree();
- }
- else if (string(parts[1]) == "house") // House with n parameters
- {
- int params = strtol(parts[2], NULL, 10);
- switch (params) // Number of parameters
- {
- case 0: // No params
- {
- Skyscraper house; // Default construct
- house.drawBuilding();
- break;
- }
- case 1: // Only number of floors specified
- {
- int nF = strtol(parts[3], NULL, 10);
- Skyscraper house(nF);
- house.drawBuilding();
- break;
- }
- case 2: // Number floors and floor height specified
- {
- int nF = strtol(parts[3], NULL, 10);
- int fH = strtol(parts[4], NULL, 10);
- Skyscraper house(nF, fH);
- house.drawBuilding();
- break;
- }
- case 3: // Number floors + floor height + floor length
- {
- int nF = strtol(parts[3], NULL, 10);
- int fH = strtol(parts[4], NULL, 10);
- int fL = strtol(parts[5], NULL, 10);
- Skyscraper house(nF, fH, fL);
- house.drawBuilding();
- break;
- }
- }
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement