Advertisement
alansam

C++ Question

Aug 23rd, 2022 (edited)
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.40 KB | None | 0 0
  1. #ifdef ORIGINAL /* see below for updated version */
  2. // i am learn this simple code but he tell me id returned 1 exit status
  3.  
  4. #include<iostream>
  5. #include<cstdlib>
  6.  
  7. namespace month_name
  8. {
  9.  void jan();
  10.  void feb();
  11.  void print();
  12.  //...
  13. }
  14. namespace month_number
  15. {
  16.  enum month_year{
  17.  jannuary =1 , febuary , mar
  18.  };
  19.  month_year month;
  20. }
  21.  
  22. void month_name::jan()
  23.     {int cnt=1;
  24.     for(size_t i=1; i<31; i++)
  25.           {cnt++;
  26.            std::cout << i << "\t";
  27.         if(cnt == 7)
  28.         {std::cout << std::endl;}
  29.         else if (cnt == 14)
  30.         {std::cout << std::endl;}
  31.         else if(cnt == 21)
  32.         {std::cout << std::endl;}
  33.         else if(cnt == 28)
  34.         {std::cout << std::endl;}}}
  35.  
  36. void month_name::feb()
  37.     {int cnt=1;
  38.     for(size_t i=1; i<30; i++)
  39.            {cnt++;
  40.            std::cout << i << "\t";
  41.         if(cnt == 7)
  42.            {std::cout << std::endl;}
  43.            else if (cnt == 14)
  44.         {std::cout << std::endl;}
  45.         else if(cnt == 21)
  46.         {std::cout << std::endl;}
  47.          else if(cnt == 28)
  48.         {std::cout << std::endl;}}}
  49. void month_name::print()
  50.            {switch(month_number::month)
  51.         {case month_number::jannuary:
  52.  month_name::jan();
  53.  break;
  54.  case month_number::febuary:
  55.  month_name::feb();
  56.  break;
  57.  default:
  58.  std::cerr << "not enough" << std::endl;}
  59.  
  60. #else
  61.  
  62. // i am learn this simple code but he tell me id returned 1 exit status
  63. // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  64. // cleaned up and working:
  65.  
  66. #include <iostream>
  67. #include <iomanip>
  68. #include <cstdlib>
  69.  
  70. namespace month_name {
  71.   void jan();
  72.   void feb();
  73.   void print();
  74.   //...
  75. }
  76.  
  77. namespace month_number {
  78.   enum month_year {
  79.     january = 1, febuary, march,
  80.   };
  81.   month_year month;
  82. }
  83.  
  84. void month_name::jan() {
  85.   int cnt = 0; // 1;
  86.   for (size_t i = 1; i < 32; i++) {
  87.     cnt++;
  88.     // std::cout << i << "\t";
  89.     std::cout << std::setw(5) << i; // << "\t";
  90.     if (cnt == 7) {
  91.       std::cout << '\n'; // std::endl;
  92.     }
  93.     else if (cnt == 14) {
  94.       std::cout << '\n'; // std::endl;
  95.     }
  96.     else if (cnt == 21) {
  97.       std::cout << '\n'; // std::endl;
  98.     }
  99.     else if (cnt == 28) {
  100.       std::cout << '\n'; // std::endl;
  101.     }
  102.   }
  103. }
  104.  
  105. void month_name::feb() {
  106.   int cnt = 0; // 1;
  107.   for (size_t i = 1; i < 30; i++) {
  108.     cnt++;
  109.     // std::cout << i << "\t";
  110.     std::cout << std::setw(5) << i; // << "\t";
  111.     if (cnt == 7) {
  112.       std::cout << std::endl;
  113.     }
  114.     else if (cnt == 14) {
  115.       std::cout << std::endl;
  116.     }
  117.     else if (cnt == 21) {
  118.       std::cout << std::endl;
  119.     }
  120.     else if (cnt == 28) {
  121.       std::cout << std::endl;
  122.     }
  123.   }
  124. }
  125.  
  126. void month_name::print() {
  127.   switch (month_number::month) {
  128.   case month_number::january:
  129.     month_name::jan();
  130.     break;
  131.  
  132.   case month_number::febuary:
  133.     month_name::feb();
  134.     break;
  135.  
  136.   default:
  137.     // std::cerr << "not enough" << std::endl;
  138.     std::cout << "not enough" << std::endl;
  139.     break;
  140.   }
  141. }
  142.  
  143. int main(int argc, char const * argv[]) {
  144.  
  145.   month_number::month = month_number::month_year::january;
  146.   month_name::print();
  147.   std::cout << '\n' << '\n';
  148.  
  149.   month_number::month = month_number::month_year::febuary;
  150.   month_name::print();
  151.   std::cout << '\n' << '\n';
  152.  
  153.   month_number::month = month_number::month_year::march;
  154.   month_name::print();
  155.   std::cout << '\n' << '\n';
  156.  
  157.   return 0;
  158. }
  159.  
  160. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement