Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cmath>
- using namespace std;
- // Exercises with solutions
- void DisplayRowsEx8() {
- for (int i = 1; i <= 4; i++)
- {
- for (int j = 1; j <= i; j++)
- {
- cout << i * 2 + 1 << " ";
- }
- cout << endl;
- }
- }
- void CorrectInnerLoopEx9() {
- for (int i = 1; i <= 6; i++)
- {
- for (int j = 1; j <= i; j++)
- {
- cout << i << " ";
- }
- cout << endl;
- }
- }
- void RewriteForLoop() {
- int x = -50;
- while (x < 50)
- {
- cout << x << " ";
- x += 4;
- }
- }
- void HomeworkTask1Pyramid(int size) {
- string outerSpaces = "";
- int counter = 0;
- for (int i = 0; i < size * 2; i += 2)
- {
- outerSpaces.assign(counter, ' ');
- cout << outerSpaces;
- for (int j = size + counter; j >= i + 1; j--)
- {
- cout << j << " ";
- }
- cout << outerSpaces <<endl;
- counter++;
- }
- }
- void PrintS(int size) {
- string line = "";
- for (int i = 1; i <= 2 * size + 3; i++)
- {
- if (i == 1)
- {
- line.assign(size, '*');
- cout << " " << line << endl;
- }
- else if(i == 2)
- {
- line.assign(size, ' ');
- cout << '*' << line << '*' << endl;
- }
- else if(i > 2 && i <= 1 + size)
- {
- cout << '*' << endl;
- }
- else if (i == 2 + size)
- {
- line.assign(size, '*');
- cout << " " << line << " " << endl;
- }
- else if(i > 2 + size && i < 2 + 2 * size)
- {
- line.assign(size + 1, ' ');
- cout << line << '*' << endl;
- }
- else if(i == 2 + 2 * size)
- {
- line.assign(size, ' ');
- cout << '*' << line << '*' << endl;
- }
- else if(i > 2 + 2 * size)
- {
- line.assign(size, '*');
- cout << " " << line << " " << endl;
- }
- }
- }
- void CheckTask1() {
- int size;
- cout << "Please, enter the size: ";
- cin >> size;
- PrintS(size);
- }
- int main() {
- CheckTask1();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment