v1 done
This commit is contained in:
parent
003a258572
commit
04e2b81674
32 changed files with 878 additions and 20 deletions
BIN
feladat3/IFPQYY_feladat3V1/IFPQYY_feladat3V1.zip
Normal file
BIN
feladat3/IFPQYY_feladat3V1/IFPQYY_feladat3V1.zip
Normal file
Binary file not shown.
113
feladat3/IFPQYY_feladat3V1/UnitTest1.cpp
Normal file
113
feladat3/IFPQYY_feladat3V1/UnitTest1.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
// IFPQYY | Tóth Dániel Mátyás | V1
|
||||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "feladat3.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTest1
|
||||
{
|
||||
TEST_CLASS(UnitTest1)
|
||||
{
|
||||
public:
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
|
||||
|
||||
TEST_METHOD(InvalidFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"doesntexist"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(AllValidFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\datasets.txt"
|
||||
//couldn't find the working directory :(
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), OK);
|
||||
}
|
||||
TEST_METHOD(NoFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
""
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(1, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(EmptyFile)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\empty.txt"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(InvalidFile)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\bad.txt"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(SortSomeMoodleFiles)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\somedatasets.txt"
|
||||
};
|
||||
GetFilenames(2, argv, infn, outfn); //valid files, too lazyto write in by hand
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), OK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(SortAllMoodleFiles)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\datasets.txt"
|
||||
};
|
||||
GetFilenames(2, argv, infn, outfn); //also valid files
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), OK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(NullPtrs)
|
||||
{
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(nullptr, nullptr, nullptr, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(InvalidFileNames)
|
||||
{
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
Assert::AreEqual(SortFile("bad", "morebad", buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
TEST_METHOD(BadBufferSize)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[2];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
Assert::AreEqual(SortFile(infn[0], outfn[0], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
};
|
||||
}
|
||||
221
feladat3/IFPQYY_feladat3V1/feladat3.cpp
Normal file
221
feladat3/IFPQYY_feladat3V1/feladat3.cpp
Normal file
|
|
@ -0,0 +1,221 @@
|
|||
// IFPQYY | Tóth Dániel Mátyás | V1
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include "feladat3.h"
|
||||
using namespace std;
|
||||
|
||||
static int CopyStr(char* dest, const char* src, const char* concat = "\0");
|
||||
static void BubbleSort(unsigned char* arr, int len);
|
||||
|
||||
int GetFilenames(int argc, char* argv[],
|
||||
char infilenames[MYMAXFILES][MYMAXFN],
|
||||
char outfilenames[MYMAXFILES][MYMAXFN]) {
|
||||
if (argc != 2 || argv == nullptr || infilenames == nullptr
|
||||
|| outfilenames == nullptr) {
|
||||
return NOK;
|
||||
}
|
||||
|
||||
cout << "Parameter allomany:\n" << argv[1] << '\n';
|
||||
ifstream argifs(argv[1]);
|
||||
if (!argifs.is_open())
|
||||
{
|
||||
cout << "Nem lehet megnyitni a " << argv[1] << " nevu allomanyt\n";
|
||||
return NOK;
|
||||
}
|
||||
int readAmount = 0;
|
||||
int i = 0;
|
||||
char buf[MYMAXFN-1];
|
||||
cout << "Feldolgozando allomanyok:\n";
|
||||
while (readAmount < 5 && argifs.getline(buf, MYMAXFN-1))
|
||||
{
|
||||
readAmount++;
|
||||
ifstream inputfile(buf);
|
||||
if (!inputfile.fail())
|
||||
{
|
||||
CopyStr(infilenames[i], buf);
|
||||
CopyStr(outfilenames[i], buf, ".srt");
|
||||
cout << infilenames[i] << " " << outfilenames[i] << "\tOK\n";
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "<" << buf << ">" << "\tNOK\n";
|
||||
}
|
||||
}
|
||||
argifs.close();
|
||||
int status = OK;
|
||||
if (i == 0)
|
||||
{
|
||||
status = NOK;
|
||||
cout << "Ures\tNOK\n";
|
||||
}
|
||||
while (i < 5) {
|
||||
infilenames[i][0] = '\0';
|
||||
outfilenames[i][0] = '\0';
|
||||
i++;
|
||||
}
|
||||
cout << "*DONE\n";
|
||||
return status;
|
||||
}
|
||||
|
||||
static int CopyStr(char* dest, const char* src, const char* concat) {
|
||||
if (dest == nullptr || src == nullptr) {
|
||||
return NOK;
|
||||
}
|
||||
int i = 0;
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
dest[i++] = src[i];
|
||||
}
|
||||
int j = 0;
|
||||
while (concat[j] != '\0')
|
||||
{
|
||||
dest[i++] = concat[j++];
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return OK;
|
||||
}
|
||||
|
||||
int SortFile(char* infn, char* outfn, unsigned char* buf,
|
||||
unsigned short* pmin, unsigned short* pmax,
|
||||
unsigned short* pavg, unsigned short* pn,
|
||||
unsigned short bufsize, bool test) {
|
||||
if (infn == nullptr || outfn == nullptr
|
||||
|| buf == nullptr || pmin == nullptr
|
||||
|| pmax == nullptr || pavg == nullptr
|
||||
|| pn == nullptr) // there has to be a better way than this
|
||||
{
|
||||
return NOK;
|
||||
}
|
||||
if (bufsize != MYBUFSIZE) // I guess?
|
||||
{
|
||||
return NOK;
|
||||
}
|
||||
|
||||
ifstream readifs(infn, ios_base::binary);
|
||||
ofstream outofs(outfn, ios_base::binary);
|
||||
if (!readifs.is_open() || outofs.bad())
|
||||
{
|
||||
return NOK;
|
||||
}
|
||||
unsigned short files[16][MYBUFSIZE/2]; //this is probably a terrible solution. too bad!
|
||||
int filesizes[16] = { 0 };
|
||||
int ptrshifts[16] = { 0 };
|
||||
|
||||
*pmin = MYMAXVALUE;
|
||||
*pmax = 0;
|
||||
*pavg = 0;
|
||||
*pn = filesystem::file_size(infn)/2; // this can't be more than MYMAXVALUE anyways, so warning dully ignored
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\nSTART: " << infn << " ----> " << outfn << "\n";
|
||||
cout << "*READ\n";
|
||||
}
|
||||
|
||||
unsigned short n;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int usedfilescnt = 0;
|
||||
while (readifs.read((char*)&n, sizeof(n))) {
|
||||
if (*pmax < n) {
|
||||
*pmax = n;
|
||||
}
|
||||
if (*pmin > n) {
|
||||
*pmin = n;
|
||||
}
|
||||
*pavg += n;
|
||||
buf[(i * 2) % (MYBUFSIZE)] = n;
|
||||
buf[((i * 2)+1) % (MYBUFSIZE)] = n >> 8;
|
||||
if (test)
|
||||
{
|
||||
cout << i << ".\t" << n << "\n";
|
||||
}
|
||||
i++;
|
||||
if (i % (MYBUFSIZE / 2) == 0)
|
||||
{
|
||||
BubbleSort(buf, MYBUFSIZE);
|
||||
while (j < MYBUFSIZE/2)
|
||||
{
|
||||
files[usedfilescnt][j] = buf[j * 2] + buf[(j * 2) + 1] * 256;
|
||||
j++;
|
||||
}
|
||||
filesizes[usedfilescnt] = MYBUFSIZE / 2;
|
||||
usedfilescnt++;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
readifs.close();
|
||||
|
||||
int size = (*pn * 2) % MYBUFSIZE;
|
||||
BubbleSort(buf, size);
|
||||
while (j < size / 2)
|
||||
{
|
||||
files[usedfilescnt][j] = buf[j * 2] + buf[(j * 2) + 1] * 256;
|
||||
j++;
|
||||
}
|
||||
filesizes[usedfilescnt] = size/2;
|
||||
usedfilescnt++;
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\n*SORT, WRITE\n";
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < *pn)
|
||||
{
|
||||
int savedJ = 0;
|
||||
unsigned short smallest = MYMAXVALUE;
|
||||
for (j = 0; j < usedfilescnt; j++)
|
||||
{
|
||||
if (ptrshifts[j] >= filesizes[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (files[j][ptrshifts[j]] < smallest)
|
||||
{
|
||||
smallest = files[j][ptrshifts[j]];
|
||||
savedJ = j;
|
||||
}
|
||||
}
|
||||
if (test)
|
||||
{
|
||||
cout << i << ".\t" << smallest << "\n";
|
||||
}
|
||||
outofs.write((char *)&smallest, sizeof(smallest));
|
||||
ptrshifts[savedJ]++;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
*pavg = *pavg / *pn;
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\n*DONE\n";
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void BubbleSort(unsigned char* arr, int len) { //note: this is a char*. you need to sort unsigned short*. kill 7 billion people
|
||||
for (int i = 0; i < len / 2; i++)
|
||||
{
|
||||
for (int j = 0; j < (len / 2) - i - 1; j++)
|
||||
{
|
||||
unsigned short first = arr[j * 2] + arr[j * 2 + 1] * 256;
|
||||
unsigned short second = arr[(j + 1) * 2] + arr[(j + 1) * 2 + 1] * 256;
|
||||
if (first > second)
|
||||
{
|
||||
unsigned char temp = arr[j * 2];
|
||||
arr[j * 2] = arr[(j + 1) * 2];
|
||||
arr[(j + 1) * 2] = temp;
|
||||
|
||||
temp = arr[j * 2 + 1];
|
||||
arr[j * 2 + 1] = arr[(j + 1) * 2 + 1];
|
||||
arr[(j + 1) * 2 + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
feladat3/IFPQYY_feladat3V1/feladat3.h
Normal file
15
feladat3/IFPQYY_feladat3V1/feladat3.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// IFPQYY | Tóth Dániel Mátyás | V1
|
||||
#pragma once
|
||||
#define MYBUFSIZE 8192
|
||||
#define MYMAXVALUE 65535
|
||||
#define MYMAXFILES 5
|
||||
#define MYMAXFN 128
|
||||
#define OK 0
|
||||
#define NOK (-1)
|
||||
int GetFilenames(int argc, char* argv[],
|
||||
char infilenames[MYMAXFILES][MYMAXFN],
|
||||
char outfilenames[MYMAXFILES][MYMAXFN]);
|
||||
int SortFile(char* infn, char* outfn, unsigned char* buf,
|
||||
unsigned short* pmin, unsigned short* pmax,
|
||||
unsigned short* pavg, unsigned short* pn,
|
||||
unsigned short bufsize = MYBUFSIZE, bool test = false);
|
||||
27
feladat3/IFPQYY_feladat3V1/main.cpp
Normal file
27
feladat3/IFPQYY_feladat3V1/main.cpp
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// IFPQYY | Tóth Dániel Mátyás | V1
|
||||
#include "feladat3.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
char infn[MYMAXFILES][MYMAXFN];
|
||||
char outfn[MYMAXFILES][MYMAXFN];
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
if (GetFilenames(argc, argv, infn, outfn) == NOK)
|
||||
{
|
||||
return(NOK);
|
||||
}
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
if (SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true) == NOK)
|
||||
return(NOK);
|
||||
}
|
||||
/*cout << argc;
|
||||
for (size_t i = 0; i < argc; i++)
|
||||
{
|
||||
cout << '\n';
|
||||
cout << argv[i];
|
||||
}*/
|
||||
return(OK);
|
||||
}
|
||||
113
feladat3/UnitTest1/UnitTest1.cpp
Normal file
113
feladat3/UnitTest1/UnitTest1.cpp
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
// IFPQYY | Tóth Dániel Mátyás | V1
|
||||
#include "pch.h"
|
||||
#include "CppUnitTest.h"
|
||||
#include "feladat3.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
namespace UnitTest1
|
||||
{
|
||||
TEST_CLASS(UnitTest1)
|
||||
{
|
||||
public:
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
|
||||
|
||||
TEST_METHOD(InvalidFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"doesntexist"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(AllValidFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\datasets.txt"
|
||||
//couldn't find the working directory :(
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), OK);
|
||||
}
|
||||
TEST_METHOD(NoFileParameter)
|
||||
{
|
||||
char* argv[] = {
|
||||
""
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(1, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(EmptyFile)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\empty.txt"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(InvalidFile)
|
||||
{
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\bad.txt"
|
||||
};
|
||||
Assert::AreEqual(GetFilenames(2, argv, infn, outfn), NOK);
|
||||
}
|
||||
TEST_METHOD(SortSomeMoodleFiles)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\somedatasets.txt"
|
||||
};
|
||||
GetFilenames(2, argv, infn, outfn); //valid files, too lazyto write in by hand
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), OK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(SortAllMoodleFiles)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
char* argv[] = {
|
||||
"",
|
||||
"C:\\Users\\danit\\Desktop\\2026-27-cpp-homework\\feladat3\\UnitTest1\\datasets.txt"
|
||||
};
|
||||
GetFilenames(2, argv, infn, outfn); //also valid files
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), OK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(NullPtrs)
|
||||
{
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
Assert::AreEqual(SortFile(nullptr, nullptr, nullptr, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
}
|
||||
TEST_METHOD(InvalidFileNames)
|
||||
{
|
||||
static unsigned char buf[MYBUFSIZE];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
Assert::AreEqual(SortFile("bad", "morebad", buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
TEST_METHOD(BadBufferSize)
|
||||
{
|
||||
char infn[MYMAXFILES][MYMAXFN] = {};
|
||||
char outfn[MYMAXFILES][MYMAXFN] = {};
|
||||
static unsigned char buf[2];
|
||||
unsigned short minv, maxv, avgv, nv;
|
||||
Assert::AreEqual(SortFile(infn[0], outfn[0], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true), NOK);
|
||||
}
|
||||
};
|
||||
}
|
||||
192
feladat3/UnitTest1/UnitTest1.vcxproj
Normal file
192
feladat3/UnitTest1/UnitTest1.vcxproj
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>18.0</VCProjectVersion>
|
||||
<ProjectGuid>{5768658D-5753-57BE-9F55-89088097DC31}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>UnitTest1</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectSubType>NativeUnitTestProject</ProjectSubType>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v145</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\feladat3;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<AdditionalLibraryDirectories>C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\feladat3\x64\Debug;$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>feladat3;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Manifest>
|
||||
<EnableSegmentHeap>true</EnableSegmentHeap>
|
||||
</Manifest>
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<UseFullPaths>true</UseFullPaths>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="UnitTest1.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\feladat3\feladat3.vcxproj">
|
||||
<Project>{05ad42de-8f96-4351-b07d-784a20d752bd}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
30
feladat3/UnitTest1/UnitTest1.vcxproj.filters
Normal file
30
feladat3/UnitTest1/UnitTest1.vcxproj.filters
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="UnitTest1.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="pch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
BIN
feladat3/UnitTest1/dataset/testin10.dat
Normal file
BIN
feladat3/UnitTest1/dataset/testin10.dat
Normal file
Binary file not shown.
BIN
feladat3/UnitTest1/dataset/testin10.dat.srt
Normal file
BIN
feladat3/UnitTest1/dataset/testin10.dat.srt
Normal file
Binary file not shown.
BIN
feladat3/UnitTest1/dataset/testin100.dat
Normal file
BIN
feladat3/UnitTest1/dataset/testin100.dat
Normal file
Binary file not shown.
BIN
feladat3/UnitTest1/dataset/testin100.dat.srt
Normal file
BIN
feladat3/UnitTest1/dataset/testin100.dat.srt
Normal file
Binary file not shown.
BIN
feladat3/UnitTest1/dataset/testin10000.dat
Normal file
BIN
feladat3/UnitTest1/dataset/testin10000.dat
Normal file
Binary file not shown.
BIN
feladat3/UnitTest1/dataset/testin10000.dat.srt
Normal file
BIN
feladat3/UnitTest1/dataset/testin10000.dat.srt
Normal file
Binary file not shown.
1
feladat3/UnitTest1/dataset/testin5.dat
Normal file
1
feladat3/UnitTest1/dataset/testin5.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
婆ワ~:#q/#
|
||||
1
feladat3/UnitTest1/dataset/testin5.dat.srt
Normal file
1
feladat3/UnitTest1/dataset/testin5.dat.srt
Normal file
|
|
@ -0,0 +1 @@
|
|||
#:#q/婆ワ~
|
||||
1
feladat3/UnitTest1/dataset/testin50.dat
Normal file
1
feladat3/UnitTest1/dataset/testin50.dat
Normal file
|
|
@ -0,0 +1 @@
|
|||
krc0ŽCÆâ.ri‰HŸH9S*9<
7s)oPMíLHYµ
D-Äy*&øp€O>*r]DFt^PßuXû+á!Ëëiß<!ézF>ù}±pƒUÎ8™?a'Óp(<
|
||||
1
feladat3/UnitTest1/dataset/testin50.dat.srt
Normal file
1
feladat3/UnitTest1/dataset/testin50.dat.srt
Normal file
|
|
@ -0,0 +1 @@
|
|||
ÆËßµ
r<!á!*&a's)*>*û+D-â.c0
7Î8(<9<F>™?ŽCDFH‰HŸHíLPM€OP9SƒUXYr]t^riëiko±pÓpøpßuÄyézù}
|
||||
5
feladat3/UnitTest1/datasets.txt
Normal file
5
feladat3/UnitTest1/datasets.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin5.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin50.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin100.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10000.dat
|
||||
0
feladat3/UnitTest1/empty.txt
Normal file
0
feladat3/UnitTest1/empty.txt
Normal file
5
feladat3/UnitTest1/pch.cpp
Normal file
5
feladat3/UnitTest1/pch.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
// pch.cpp: source file corresponding to the pre-compiled header
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
// When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
|
||||
12
feladat3/UnitTest1/pch.h
Normal file
12
feladat3/UnitTest1/pch.h
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
// pch.h: This is a precompiled header file.
|
||||
// Files listed below are compiled only once, improving build performance for future builds.
|
||||
// This also affects IntelliSense performance, including code completion and many code browsing features.
|
||||
// However, files listed here are ALL re-compiled if any one of them is updated between builds.
|
||||
// Do not add files here that you will be updating frequently as this negates the performance advantage.
|
||||
|
||||
#ifndef PCH_H
|
||||
#define PCH_H
|
||||
|
||||
// add headers that you want to pre-compile here
|
||||
|
||||
#endif //PCH_H
|
||||
8
feladat3/UnitTest1/somedatasets.txt
Normal file
8
feladat3/UnitTest1/somedatasets.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin5.dat
|
||||
no
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin50.dat
|
||||
|
||||
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin100.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10000.dat
|
||||
|
|
@ -4,4 +4,5 @@
|
|||
<Platform Name="x86" />
|
||||
</Configurations>
|
||||
<Project Path="feladat3/feladat3.vcxproj" Id="05ad42de-8f96-4351-b07d-784a20d752bd" />
|
||||
<Project Path="UnitTest1/UnitTest1.vcxproj" />
|
||||
</Solution>
|
||||
|
|
|
|||
BIN
feladat3/feladat3/dataset/testin10.dat.srt
Normal file
BIN
feladat3/feladat3/dataset/testin10.dat.srt
Normal file
Binary file not shown.
BIN
feladat3/feladat3/dataset/testin100.dat.srt
Normal file
BIN
feladat3/feladat3/dataset/testin100.dat.srt
Normal file
Binary file not shown.
0
feladat3/feladat3/dataset/testin10000.dat.srt
Normal file
0
feladat3/feladat3/dataset/testin10000.dat.srt
Normal file
1
feladat3/feladat3/dataset/testin5.dat.srt
Normal file
1
feladat3/feladat3/dataset/testin5.dat.srt
Normal file
|
|
@ -0,0 +1 @@
|
|||
#:#q/婆ワ~
|
||||
1
feladat3/feladat3/dataset/testin50.dat.srt
Normal file
1
feladat3/feladat3/dataset/testin50.dat.srt
Normal file
|
|
@ -0,0 +1 @@
|
|||
ÆËßµ
r<!á!*&a's)*>*û+D-â.c0
7Î8(<9<F>™?ŽCDFH‰HŸHíLPM€OP9SƒUXYr]t^riëiko±pÓpøpßuÄyézù}
|
||||
|
|
@ -1,12 +1,5 @@
|
|||
dataset\testin5.dat
|
||||
|
||||
|
||||
C:\nonexistent.dum
|
||||
dataset\testin10.dat
|
||||
|
||||
dataset\testin50.dat
|
||||
dataset\testin100.dat
|
||||
|
||||
dataset\testin10000.dat
|
||||
|
||||
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin5.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin50.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin100.dat
|
||||
C:\Users\danit\Desktop\2026-27-cpp-homework\feladat3\UnitTest1\dataset\testin10000.dat
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
using namespace std;
|
||||
|
||||
static int CopyStr(char* dest, const char* src, const char* concat = "\0");
|
||||
static void BubbleSort(unsigned char* arr, int len);
|
||||
|
||||
int GetFilenames(int argc, char* argv[],
|
||||
char infilenames[MYMAXFILES][MYMAXFN],
|
||||
|
|
@ -44,7 +45,7 @@ int GetFilenames(int argc, char* argv[],
|
|||
}
|
||||
argifs.close();
|
||||
int status = OK;
|
||||
if (readAmount == 0)
|
||||
if (i == 0)
|
||||
{
|
||||
status = NOK;
|
||||
cout << "Ures\tNOK\n";
|
||||
|
|
@ -57,6 +58,7 @@ int GetFilenames(int argc, char* argv[],
|
|||
cout << "*DONE\n";
|
||||
return status;
|
||||
}
|
||||
|
||||
static int CopyStr(char* dest, const char* src, const char* concat) {
|
||||
if (dest == nullptr || src == nullptr) {
|
||||
return NOK;
|
||||
|
|
@ -74,6 +76,7 @@ static int CopyStr(char* dest, const char* src, const char* concat) {
|
|||
dest[i] = '\0';
|
||||
return OK;
|
||||
}
|
||||
|
||||
int SortFile(char* infn, char* outfn, unsigned char* buf,
|
||||
unsigned short* pmin, unsigned short* pmax,
|
||||
unsigned short* pavg, unsigned short* pn,
|
||||
|
|
@ -85,20 +88,134 @@ int SortFile(char* infn, char* outfn, unsigned char* buf,
|
|||
{
|
||||
return NOK;
|
||||
}
|
||||
if (bufsize != MYBUFSIZE) //I guess?
|
||||
if (bufsize != MYBUFSIZE) // I guess?
|
||||
{
|
||||
return NOK;
|
||||
}
|
||||
|
||||
ifstream argifs(infn, ios_base::binary);
|
||||
if (!argifs.is_open())
|
||||
ifstream readifs(infn, ios_base::binary);
|
||||
ofstream outofs(outfn, ios_base::binary);
|
||||
if (!readifs.is_open() || outofs.bad())
|
||||
{
|
||||
return NOK;
|
||||
}
|
||||
unsigned short files[16][MYBUFSIZE/2]; //this is probably a terrible solution. too bad!
|
||||
int filesizes[16] = { 0 };
|
||||
int ptrshifts[16] = { 0 };
|
||||
|
||||
int size = filesystem::file_size(infn);
|
||||
cout << size;
|
||||
short* allVals[MYMAXVALUE];
|
||||
*pmin = MYMAXVALUE;
|
||||
*pmax = 0;
|
||||
*pavg = 0;
|
||||
*pn = filesystem::file_size(infn)/2; // this can't be more than MYMAXVALUE anyways, so warning dully ignored
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\nSTART: " << infn << " ----> " << outfn << "\n";
|
||||
cout << "*READ\n";
|
||||
}
|
||||
|
||||
unsigned short n;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int usedfilescnt = 0;
|
||||
while (readifs.read((char*)&n, sizeof(n))) {
|
||||
if (*pmax < n) {
|
||||
*pmax = n;
|
||||
}
|
||||
if (*pmin > n) {
|
||||
*pmin = n;
|
||||
}
|
||||
*pavg += n;
|
||||
buf[(i * 2) % (MYBUFSIZE)] = n;
|
||||
buf[((i * 2)+1) % (MYBUFSIZE)] = n >> 8;
|
||||
if (test)
|
||||
{
|
||||
cout << i << ".\t" << n << "\n";
|
||||
}
|
||||
i++;
|
||||
if (i % (MYBUFSIZE / 2) == 0)
|
||||
{
|
||||
BubbleSort(buf, MYBUFSIZE);
|
||||
while (j < MYBUFSIZE/2)
|
||||
{
|
||||
files[usedfilescnt][j] = buf[j * 2] + buf[(j * 2) + 1] * 256;
|
||||
j++;
|
||||
}
|
||||
filesizes[usedfilescnt] = MYBUFSIZE / 2;
|
||||
usedfilescnt++;
|
||||
j = 0;
|
||||
}
|
||||
}
|
||||
readifs.close();
|
||||
|
||||
int size = (*pn * 2) % MYBUFSIZE;
|
||||
BubbleSort(buf, size);
|
||||
while (j < size / 2)
|
||||
{
|
||||
files[usedfilescnt][j] = buf[j * 2] + buf[(j * 2) + 1] * 256;
|
||||
j++;
|
||||
}
|
||||
filesizes[usedfilescnt] = size/2;
|
||||
usedfilescnt++;
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\n*SORT, WRITE\n";
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < *pn)
|
||||
{
|
||||
int savedJ = 0;
|
||||
unsigned short smallest = MYMAXVALUE;
|
||||
for (j = 0; j < usedfilescnt; j++)
|
||||
{
|
||||
if (ptrshifts[j] >= filesizes[j])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (files[j][ptrshifts[j]] < smallest)
|
||||
{
|
||||
smallest = files[j][ptrshifts[j]];
|
||||
savedJ = j;
|
||||
}
|
||||
}
|
||||
if (test)
|
||||
{
|
||||
cout << i << ".\t" << smallest << "\n";
|
||||
}
|
||||
outofs.write((char *)&smallest, sizeof(smallest));
|
||||
ptrshifts[savedJ]++;
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
*pavg = *pavg / *pn;
|
||||
|
||||
if (test)
|
||||
{
|
||||
cout << "\n*DONE\n";
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
static void BubbleSort(unsigned char* arr, int len) { //note: this is a char*. you need to sort unsigned short*. kill 7 billion people
|
||||
for (int i = 0; i < len / 2; i++)
|
||||
{
|
||||
for (int j = 0; j < (len / 2) - i - 1; j++)
|
||||
{
|
||||
unsigned short first = arr[j * 2] + arr[j * 2 + 1] * 256;
|
||||
unsigned short second = arr[(j + 1) * 2] + arr[(j + 1) * 2 + 1] * 256;
|
||||
if (first > second)
|
||||
{
|
||||
unsigned char temp = arr[j * 2];
|
||||
arr[j * 2] = arr[(j + 1) * 2];
|
||||
arr[(j + 1) * 2] = temp;
|
||||
|
||||
temp = arr[j * 2 + 1];
|
||||
arr[j * 2 + 1] = arr[(j + 1) * 2 + 1];
|
||||
arr[(j + 1) * 2 + 1] = temp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ int main(int argc, char* argv[]) {
|
|||
}
|
||||
for (int n = 0; (n < MYMAXFILES) && (infn[n][0] != '\0'); n++)
|
||||
{
|
||||
if (SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv) == NOK)
|
||||
if (SortFile(infn[n], outfn[n], buf, &minv, &maxv, &avgv, &nv, MYBUFSIZE, true) == NOK)
|
||||
return(NOK);
|
||||
}
|
||||
/*cout << argc;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue