stefan1919

MidTermPrep

Mar 7th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. // Exercises with solutions
  8. void DisplayRowsEx8() {
  9.     for (int i = 1; i <= 4; i++)
  10.     {
  11.         for (int j = 1; j <= i; j++)
  12.         {
  13.             cout << i * 2 + 1 << " ";
  14.         }
  15.         cout << endl;
  16.     }
  17. }
  18.  
  19. void CorrectInnerLoopEx9() {
  20.     for (int i = 1; i <= 6; i++)
  21.     {
  22.         for (int j = 1; j <= i; j++)
  23.         {
  24.             cout << i << " ";
  25.         }
  26.         cout << endl;
  27.     }
  28. }
  29.  
  30. void RewriteForLoop() {
  31.     int x = -50;
  32.     while (x < 50)
  33.     {
  34.         cout << x << " ";
  35.         x += 4;
  36.     }
  37. }
  38. void HomeworkTask1Pyramid(int size) {
  39.     string outerSpaces = "";
  40.     int counter = 0;
  41.     for (int i = 0; i < size * 2; i += 2)
  42.     {
  43.         outerSpaces.assign(counter, ' ');
  44.         cout << outerSpaces;
  45.         for (int j = size + counter; j >= i + 1; j--)
  46.         {
  47.             cout << j << " ";
  48.         }
  49.         cout << outerSpaces <<endl;
  50.         counter++;
  51.  
  52.     }
  53.  
  54. }
  55. void PrintS(int size) {
  56.     string line = "";
  57.     for (int i = 1; i <= 2 * size + 3; i++)
  58.     {
  59.         if (i == 1)
  60.         {
  61.             line.assign(size, '*');
  62.             cout << " " << line << endl;
  63.         }
  64.         else if(i == 2)
  65.         {
  66.             line.assign(size, ' ');
  67.             cout << '*' << line << '*' << endl;
  68.         }
  69.         else if(i > 2 && i <= 1 + size)
  70.         {
  71.             cout << '*' << endl;
  72.         }
  73.         else if (i == 2 + size)
  74.         {
  75.             line.assign(size, '*');
  76.             cout << " " << line << " " << endl;
  77.         }
  78.         else if(i > 2 + size && i < 2 + 2 * size)
  79.         {
  80.             line.assign(size + 1, ' ');
  81.             cout << line << '*' << endl;
  82.         }
  83.         else if(i == 2 + 2 * size)
  84.         {
  85.             line.assign(size, ' ');
  86.             cout << '*' << line << '*' << endl;
  87.         }
  88.         else if(i > 2 + 2 * size)
  89.         {
  90.             line.assign(size, '*');
  91.             cout << " " << line << " " << endl;
  92.         }
  93.     }
  94. }
  95.  
  96. void CheckTask1() {
  97.     int size;
  98.     cout << "Please, enter the size: ";
  99.     cin >> size;
  100.     PrintS(size);
  101. }
  102.     int main() {
  103.         CheckTask1();
  104.         return 0;
  105.     }
Advertisement
Add Comment
Please, Sign In to add comment