init repo

This commit is contained in:
2025-10-01 17:58:51 +07:00
commit 8a310fe9fc
6 changed files with 91 additions and 0 deletions

1
.gitignore vendored Normal file
View File

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

View File

@@ -0,0 +1,3 @@
//
// Created by pajjilykk on 10/1/25.
//

5
LAB_1/ilya`s/file.in Normal file
View File

@@ -0,0 +1,5 @@
Hi! This is a test.
Wait: are commas, periods, and exclamations replaced?
Let's check!
@#$%&*)_+

6
LAB_1/ilya`s/file.out Normal file
View File

@@ -0,0 +1,6 @@
Hi9 This is a test9
Wait9 are commas9 periods9 and exclamations replaced9
Let's check9
@#$%&*)_+

BIN
LAB_1/ilya`s/signs Executable file

Binary file not shown.

76
LAB_1/ilya`s/signs.cpp Normal file
View File

@@ -0,0 +1,76 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h>
using namespace std;
// ???????? ????????????? ?????
bool fileExists(const string& filename) {
struct stat buffer;
return (stat(filename.c_str(), &buffer) == 0);
}
// ????????? ????? ????????? ????? ? ??????? ?????????? ?? ".out"
string getOutputFileName(const string& inputFileName) {
size_t pos = inputFileName.find_last_of('.');
if (pos == string::npos) {
// ???? ?????????? ???, ????????? .out
return inputFileName + ".out";
}
return inputFileName.substr(0, pos) + ".out"; // ???????? ??????????
}
// ????????, ???????? ?? ?????? ?????? ??????????, ?????????? ??????
bool isSign(char c) {
return (c == '!' || c == '?' || c == '.' || c == ',' || c == ';' || c == ':');
}
int main(int argc, char* argv[]) {
if (argc != 3) {
cerr << "Error: Missing arguments.\nUsage: " << argv[0] << " <inputfile> <symbol>\n";
return -1;
}
string inputFileName = argv[1];
char replacementSymbol = argv[2][0];
if (!fileExists(inputFileName)) {
cerr << "Error: Input file \"" << inputFileName << "\" does not exist.\n";
return -1;
}
string outputFileName = getOutputFileName(inputFileName);
ifstream inFile(inputFileName);
if (!inFile) {
cerr << "Error: Cannot open input file.\n";
return -1;
}
ofstream outFile(outputFileName);
if (!outFile) {
cerr << "Error: Cannot create output file.\n";
return -1;
}
int replaceCount = 0;
char ch;
while (inFile.get(ch)) {
if (isSign(ch)) {
ch = replacementSymbol;
replaceCount++;
}
outFile.put(ch);
if (!outFile) {
cerr << "Error: Write error occurred.\n";
return -1;
}
}
inFile.close();
outFile.close();
cout << replaceCount << endl; // ??????? ????? ?????
return replaceCount;
}