Add Lesson 2

This commit is contained in:
Stanislav Mykhailenko 2024-06-24 18:19:29 +03:00
parent 17e1f943be
commit a9b7ecf20c
GPG key ID: 1E95E66A9C9D6A36
10 changed files with 430 additions and 0 deletions

1
Lesson_2/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
*.pro

74
Lesson_2/Task_1/.gitignore vendored Normal file
View file

@ -0,0 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

48
Lesson_2/Task_1/main.cpp Normal file
View file

@ -0,0 +1,48 @@
#include <iostream>
using namespace std;
int main()
{
int accounts[10];
for (int account = 0; account < 10; ++account)
accounts[account] = 0;
while (true) {
int action = 0;
cout << "Enter action (1 - add money, 2 - remove money, 3 - display all balances): ";
cin >> action;
if (action == 1 || action == 2) {
int number = 0;
int money = 0;
cout << "Enter account number: ";
cin >> number;
if (number >= 0 && number < 10) {
cout << "Enter the amount of money: ";
cin >> money;
if (money > 0) {
if (action == 1) {
accounts[number] += money;
cout << "Money added." << endl;
} else if (accounts[number] >= money) {
accounts[number] -= money;
cout << "Money removed." << endl;
} else
cout << "Not enough money." << endl;
} else
cout << "The amount must be positive." << endl;
} else
cout << "Invalid account number." << endl;
} else if (action == 3) {
for (int account = 0; account < 10; ++account)
cout << "Account " << account << ": " << accounts[account] << endl;
} else
cout << "Invalid action." << endl;
}
return 0;
}

74
Lesson_2/Task_2/.gitignore vendored Normal file
View file

@ -0,0 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

29
Lesson_2/Task_2/main.cpp Normal file
View file

@ -0,0 +1,29 @@
#include <iostream>
using namespace std;
int main()
{
int numbers[20];
int maximum = 0;
for (int number = 0; number < 20; ++number) {
cout << "Enter value: ";
cin >> numbers[number];
if (maximum < numbers[number])
maximum = numbers[number];
if (numbers[number] == 0)
break;
}
for (int number = 0; number < 20; ++number) {
if (numbers[number] == 0)
break;
int spaces = (maximum - numbers[number]) / 2;
for (int space = 0; space < spaces; ++space)
cout << " ";
for (int asterisk = 0; asterisk < numbers[number]; ++asterisk)
cout << "*";
cout << endl;
}
return 0;
}

74
Lesson_2/Task_3/.gitignore vendored Normal file
View file

@ -0,0 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

27
Lesson_2/Task_3/main.cpp Normal file
View file

@ -0,0 +1,27 @@
#include <iostream>
using namespace std;
int main()
{
int numbers[5];
int max = 0;
for (int number = 0; number < 5; ++number) {
cout << "Enter amount in " << number + 1 << " row: ";
cin >> numbers[number];
if (numbers[number] > max)
max = numbers[number];
}
for (int iteration = 0; iteration < max; ++iteration) {
for (int number = 0; number < 5; ++number) {
if (iteration < numbers[number])
cout << "*";
else
cout << " ";
}
cout << endl;
}
return 0;
}

74
Lesson_2/Task_4/.gitignore vendored Normal file
View file

@ -0,0 +1,74 @@
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
CMakeLists.txt.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe

22
Lesson_2/Task_4/main.cpp Normal file
View file

@ -0,0 +1,22 @@
#include <iostream>
using namespace std;
int main()
{
char str[256];
cout << "Enter some string: ";
cin.getline(str, 256);
int words = 1;
for (int character = 0; character < 256; ++character) {
if (str[character] == ' ')
++words;
else if (str[character] == 0)
break;
}
cout << "Number of words: " << words << endl;
return 0;
}

View file

@ -17,3 +17,10 @@ Checked means the task is Done.
- [x] Task 5 - [x] Task 5
- [x] Task 6 - [x] Task 6
- [x] Task 7 - [x] Task 7
### Lesson 2
- [ ] Task 1
- [ ] Task 2
- [ ] Task 3
- [ ] Task 4