150 lines
2.6 KiB
C++
150 lines
2.6 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
const unsigned int MAX_SENTENTECE_SIZE = 100U;
|
|
|
|
int Task_1();
|
|
int Task_2();
|
|
int Task_3();
|
|
int Task_4();
|
|
int Task_5();
|
|
|
|
int main()
|
|
{
|
|
int result = 0;
|
|
|
|
result = Task_1();
|
|
if (result != 0)
|
|
{
|
|
return result;
|
|
}
|
|
result = Task_2();
|
|
if (result != 0)
|
|
{
|
|
return result;
|
|
}
|
|
result = Task_3();
|
|
if (result != 0)
|
|
{
|
|
return result;
|
|
}
|
|
result = Task_4();
|
|
if (result != 0)
|
|
{
|
|
return result;
|
|
}
|
|
result = Task_5();
|
|
if (result != 0)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void PrintArray(int* pArr, const size_t count, std::string s)
|
|
{
|
|
std::cout << s;
|
|
for (size_t i = 0U; i < count; i++)
|
|
{
|
|
std::cout << "Array[" << i << "] = " << pArr[i] << std::endl;
|
|
}
|
|
}
|
|
|
|
void PrintArray(int** pArr, const size_t count)
|
|
{
|
|
for (size_t i = 0U; i < count; i++)
|
|
{
|
|
for (size_t j = 0U; j < count; j++)
|
|
{
|
|
std::cout << "\t" << pArr[i][j];
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
}
|
|
|
|
void FillArrayByTwoPowers(int* pArr, const size_t count)
|
|
{
|
|
pArr[0U] = 1;
|
|
for (size_t i = 1U; i < count; i++)
|
|
{
|
|
pArr[i] = pArr[i - 1U] << 1;
|
|
}
|
|
}
|
|
|
|
void FillRandArray(int** ppArr, const size_t count)
|
|
{
|
|
for (size_t i = 0U; i < count; i++)
|
|
{
|
|
for (size_t j = 0U; j < count; j++)
|
|
{
|
|
ppArr[i][j] = rand();
|
|
}
|
|
}
|
|
}
|
|
|
|
int FillFileBySmth(std::string filename)
|
|
{
|
|
std::string s = "This is a small text with little quantity of symbols created in Microsoft Visual Studio.\n";
|
|
std::ofstream outfile(filename);
|
|
|
|
if (!outfile)
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
std::cout << "File \"" << filename << "\" is open successfully.\n";
|
|
|
|
outfile << s;
|
|
|
|
outfile.close();
|
|
return 0;
|
|
}
|
|
|
|
int GlueTwoFilesInThird(std::string filename_1, std::string filename_2, std::string outfilename)
|
|
{
|
|
std::string s1 = "";
|
|
std::string s2 = "";
|
|
std::ifstream in_file_1(filename_1);
|
|
std::ifstream in_file_2(filename_2);
|
|
|
|
if (!in_file_1 || !in_file_2)
|
|
{
|
|
return -2;
|
|
}
|
|
std::cout << "Files \"" << filename_1 << "\" and \"" << filename_2 << "\" are succesfully open.\n";
|
|
|
|
while (!in_file_1.eof())
|
|
{
|
|
char tmp[MAX_SENTENTECE_SIZE + 1] = {};
|
|
in_file_1.getline(tmp, MAX_SENTENTECE_SIZE, '\n');
|
|
s1 += tmp;
|
|
s1 += "\n";
|
|
}
|
|
while (!in_file_2.eof())
|
|
{
|
|
char tmp[MAX_SENTENTECE_SIZE + 1] = {};
|
|
in_file_2.getline(tmp, MAX_SENTENTECE_SIZE, '\n');
|
|
s2 += tmp;
|
|
s2 += "\n";
|
|
}
|
|
|
|
in_file_1.close();
|
|
in_file_2.close();
|
|
std::cout << "Files \"" << filename_1 << "\" and \"" << filename_2 << "\" are closed.\n";
|
|
|
|
std::ofstream out_file(outfilename);
|
|
if (!out_file)
|
|
{
|
|
return -2;
|
|
}
|
|
std::cout << "File \"" << outfilename << "\" is successfully open.\n";
|
|
|
|
out_file << s1 + s2;
|
|
out_file.close();
|
|
std::cout << "File \"" << outfilename << "\" is closed.\n";
|
|
|
|
return 0;
|
|
}
|