diff --git a/CPP_lab_2.cpp b/CPP_lab_2.cpp new file mode 100644 index 0000000..ae682bf --- /dev/null +++ b/CPP_lab_2.cpp @@ -0,0 +1,164 @@ +#include +#include +#include +#include + +using namespace std; + +const double PI = 3.1415926; // PI и E в ответах означают, +const double E = 2.7182818; // что нет действительных решений + + +vector SolveQuadraticEquation(double a, double b, double c) { + double D = b * b - 4 * a * c; + vector roots; + + if (D >= 0.0) { + double x1 = (-b + sqrt(D)) / (2 * a); + double x2 = (-b - sqrt(D)) / (2 * a); + roots.push_back(x1); + roots.push_back(x2); + } + else { + roots.push_back(PI); + roots.push_back(E); + } + + return roots; +} + + +class Student { +public: + string surname; + vector> answers; + + Student(string surname) : surname(surname) {} + + virtual void Solve(vector> tasks) = 0; +}; + + +class GoodStudent : public Student { +public: + GoodStudent(string surname) : Student(surname) {} + + void Solve(vector> tasks) override { + for (const vector& task : tasks) { + answers.push_back(SolveQuadraticEquation(task[0], task[1], task[2])); + } + } +}; + + +class BadStudent : public Student { +public: + BadStudent(string surname) : Student(surname) {} + + void Solve(vector> tasks) override { + for (const vector& task : tasks) { + answers.push_back({ 0, 0 }); + } + } +}; + + +class MiddleStudent : public Student { +public: + MiddleStudent(string surname) : Student(surname) {} + + void Solve(vector> tasks) override { + for (const vector& task : tasks) { + if (rand() % 2 == 0) { + answers.push_back(SolveQuadraticEquation(task[0], task[1], task[2])); + } + else { + answers.push_back({ 0, 0 }); + } + } + } +}; + + +class Teacher { +protected: + vector> right_answers; + +public: + void GetRightAnswers(const vector>& tasks) { + for (const vector& task : tasks) { + right_answers.push_back(SolveQuadraticEquation(task[0], task[1], task[2])); + } + } + + int Check(const Student* student) { + int scores = 0; + for (size_t i = 0; i < right_answers.size(); i++) { + if (right_answers[i] == student->answers[i]) { + scores++; + } + } + return scores; + } + + void PrintProgressTable(const vector& students) { + for (int i = 0; i < students.size(); i++) { + cout << students[i]->surname << " " << Check(students[i]) << " " << right_answers.size() << endl; + } + } + +}; + + +void input() { + setlocale(LC_ALL, "Russian"); + srand(time(NULL)); + + ifstream fin_surnames("surnames.txt"); + vector surnames; + if (fin_surnames) { + string surname; + while (getline(fin_surnames, surname)) { + surnames.push_back(surname); + } + fin_surnames.close(); + } + + ifstream fin_tasks("tasks.txt"); + vector> tasks; + if (fin_tasks) { + double a, b, c; + while (fin_tasks >> a >> b >> c) { + tasks.push_back({ a, b, c }); + } + fin_tasks.close(); + } + + vector students; + for (const string& surname : surnames) { + Student* student = nullptr; + + int intellect = rand() % 3; + switch (intellect) { + case 0: + student = new GoodStudent(surname); + break; + case 1: + student = new BadStudent(surname); + break; + case 2: + student = new MiddleStudent(surname); + break; + } + student->Solve(tasks); + students.push_back(student); + } + + Teacher teacher = Teacher(); + teacher.GetRightAnswers(tasks); + teacher.PrintProgressTable(students); +} + +void main() { + input(); +} \ No newline at end of file diff --git a/CPP_lab_2.sln b/CPP_lab_2.sln new file mode 100644 index 0000000..4043f55 --- /dev/null +++ b/CPP_lab_2.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34031.279 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CPP_lab_2", "CPP_lab_2\CPP_lab_2.vcxproj", "{D6A5276E-97ED-4147-BD26-46A2EB2581A2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Debug|x64.ActiveCfg = Debug|x64 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Debug|x64.Build.0 = Debug|x64 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Debug|x86.ActiveCfg = Debug|Win32 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Debug|x86.Build.0 = Debug|Win32 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Release|x64.ActiveCfg = Release|x64 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Release|x64.Build.0 = Release|x64 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Release|x86.ActiveCfg = Release|Win32 + {D6A5276E-97ED-4147-BD26-46A2EB2581A2}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3B55B514-489C-4C05-904A-B696DD7E7E22} + EndGlobalSection +EndGlobal diff --git a/CPP_lab_2.vcxproj b/CPP_lab_2.vcxproj new file mode 100644 index 0000000..b304357 --- /dev/null +++ b/CPP_lab_2.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {d6a5276e-97ed-4147-bd26-46a2eb2581a2} + CPPlab2 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/CPP_lab_2.vcxproj.filters b/CPP_lab_2.vcxproj.filters new file mode 100644 index 0000000..dc8442d --- /dev/null +++ b/CPP_lab_2.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/CPP_lab_2.vcxproj.user b/CPP_lab_2.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/CPP_lab_2.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file