Guest User

BlueMelon Cuboid

a guest
Aug 6th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. /*
  2. Solution to Cuboid Problem
  3. URL: http://www.reddit.com/r/dailyprogrammer/comments/xq2ao/832012_challenge_85_intermediate_3d_cuboid/
  4. Date: 08/06/2012
  5. Author: BlueMelon
  6. */
  7.  
  8. #include <iostream>
  9.  
  10. using std::cin;
  11. using std::cout;
  12.  
  13. void drawCuboid(int length,int height,int depth){
  14.  
  15.         cout <<"\nLength: " <<length << " Height: " << height << " Depth: " << depth << "\n\n";
  16.        
  17.         /*Draw Top Part*/
  18.         for(int d=0; d<depth; d++){
  19.             //whitespace
  20.             for(int w=0; w < (depth-d); w++) cout << " ";
  21.             // :
  22.             for(int c=0; c < (length - 1); c++) cout << ":";
  23.             // top right edge
  24.             cout << "/";
  25.             // +
  26.             for(int p=0; p < d; p++) cout << "+";
  27.            
  28.             cout << "\n";
  29.         }
  30.  
  31.         /*Draw Middle Part*/
  32.         for(int m=0; m < (height-depth); m++){
  33.             // #
  34.             for(int w=0; w < length; w++) cout << "#";
  35.             // +
  36.             for(int p=0; p < depth; p++) cout << "+";
  37.  
  38.             cout << "\n";
  39.         }
  40.  
  41.         /*Draw Bottom Part*/
  42.         for(int b=0; b <= depth; b++){
  43.             // #
  44.             for(int w=0; w < length; w++) cout << "#";
  45.             // +
  46.             for(int p=0; p < (depth-b); p++) cout << "+";
  47.  
  48.             cout << "\n";
  49.         }
  50.  
  51.  
  52.         return;
  53.        
  54. }
  55. int main(){
  56.    
  57.     int w,h,d = 0;
  58.     cout << "Enter Width,Height,Depth: \n";
  59.     cin >> w >> h >> d;
  60.     cout << "\nHere is your cube, \n\n";
  61.     drawCuboid(w,h,d);
  62.  
  63.  
  64.     cout << "\n\nDone\n\n";
  65.     system("pause");
  66.     return 0;
  67. }
Add Comment
Please, Sign In to add comment