Вы находитесь на странице: 1из 10

//#include <bits/stdc++.

h>
#include <iostream>
#include <windows.h>
using namespace std;

#define CP_WIN1251 1251// Кодовая страница русской кодировки для Windows

//функция конвертации std::string в unsigned integer


inline unsigned int
stoui(const string& str, size_t* idx = 0, int __base = 10)
{ return gnu_cxx::stoa<long, unsigned int>(&std::strtol, "stoui", __str.c_str(),
idx, base); }

//функция валидации репрезентации целого беззнакового числа - команды


inline bool
validate(string input)
{
return input.size()==1&&input[0]>='0'&&input[0]<='7';
}

void practice0()
{
// var_6.cpp :
#include <iostream>
#include <windows.h>
#include <string>

using namespace std;

struct Date {
unsigned short day;
unsigned short month;
unsigned short year;
};

struct Record
{
char surName[17];
char commandCode;
double score;
unsigned short place;
struct Date date;
};

void myCentr(string s, int wLine) {

int w = s.length();
int delta = (wLine - w) / 2;
cout << left;
cout.width(delta); cout << " ";
cout << s;
cout.width(delta + 1); cout << " ";

void printDate(unsigned short day, unsigned short month, unsigned short year, int
wLine) {
int w = 10;
int delta = (wLine - w) / 2 - 1;
cout << left;
cout.width(delta); cout << " ";
if (day > 9) {
cout << day;
}
else {
cout << "0" << day;
}
cout << ".";
if (month > 9) {
cout << month;
}
else {
cout << "0" << month;
}
cout << ".";
cout << year;
cout.width(delta); cout << " ";
}

void printWhithZero(int num, int width) {


if (num > 999 and num < 10000) {
cout.width(width + 1);
cout << right << "00" << num;
}
if (num > 9999 and num < 100000) {
cout.width(width);
cout << right << "0" << num;
}
}

void Draw(struct Record* records) {


unsigned short width = 78 + 16;
cout << endl; cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "|Ведомость спортивных
состязаний"; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
cout << left << "| Фамилия участника ";
cout << left << "| Код команды ";
cout << left << "| Количество балов ";
cout << left << "| Место в итоге ";
cout << left << " | Дата |" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
for (int i = 0; i < 3; i++) {
cout << left << "|"; cout.width(22); cout << left << records[i].surName;
cout << left << "|"; cout.width(15); cout << left << records[i].commandCode;
cout.precision(4);
cout << left << "|"; cout << left << fixed << records[i].score;
unsigned short w = 12;
if (records[i].score > 9 and records[i].score < 100)
w += 1;
cout.width(w); cout.fill(' '); cout << " ";
cout << left << "|"; cout.width(18); cout << left << records[i].place;
cout << left << "|";
printDate(records[i].date.day, records[i].date.month, records[i].date.year, 16);
cout << "|" << endl;
}
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "|Примечание: Д - \"Динамо\",
С - \"Спартак\", Ш - \"Шахтер\""; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
}

int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);

struct Record records[10];

records[0] = { "Баландин", 'С', 123.7000, 2, {06,06,2022} };


records[1] = { "Шишков", 'Ш', 79.9800, 3, {07,07,2022} };
records[2] = { "Кравченко", 'Д', 134.8000, 1, {07,06,2022}};

Draw(records);
}
}

void practice1()
{
#include <iostream>

using namespace std;

struct Date {
int day;
int month;
int year;
};

struct Record {
char username[25];
char code;
double points;
int place_in_rating;
struct Date date;
};

void printDate(int day, int month, int year, int wl) {


int w = 10;
int delta = (wl - w) / 2 - 1;
cout << left;
cout.width(delta); cout << " ";
";
if (day > 9) {
cout << day;
}
else {
cout << "0" << day;
}
cout << ".";
if (month > 9) {
cout << month;
}
else {
cout << "0" << month;
}
cout << ".";
cout << year;
cout.width(delta); cout << " ";
}

void Draw(struct Record* line, int n) {


int width = 91;
cout << endl; cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "| Ведомость спортивных
состязаний"; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
cout << left << "| Фамилия участника ";
cout << left << "| Код команды ";
cout << left << "| Количество баллов ";
cout << left << "| Место в итоге ";
cout << left << "| Дата выступления ";
cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
for (int i = 0; i < n; i++) {
cout << left << "|"; cout.width(19); cout << left << line[i].username;
cout << left << "|"; cout.width(13); cout << left << line[i].code;
cout << left << "|"; cout.width(19); cout << right << line[i].points;
cout << left << "|"; cout.width(15); cout << left <<
line[i].place_in_rating;
cout << left << "|";
printDate(line[i].date.day, line[i].date.month, line[i].date.year, 22);
cout << "|" << endl;
}
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "| Примечание: Д -
'Динамо', С - 'Спартак', Ш - 'Шахтер' "; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
}

struct Record getMax(struct Record* line) {


int maxpr = line[0].place_in_rating;
double maxp = line[0].points;
for (int i = 1; i < 3; i++) {
if (line[i].place_in_rating > maxpr)
{
maxpr = line[i].place_in_rating;
}
if (line[i].points > maxp)
{
maxp = line[i].points;
}
}
struct Record maxVal = {"Баландин", 'C', maxp, maxpr, {6, 6, 2022} };
return maxVal;
}
int main()
{
setlocale(LC_ALL, "ru");

struct Record line[10];

line[0] = { "Баландин", 'С', 123.7000, 2, {6, 6, 2022}};


line[1] = { "Шишков", 'Ш', 79.9800, 3, {7, 7, 2020}};
line[2] = { "Кравченко", 'Д', 134.8000, 1, {7, 6, 2022}};

cout << "Исходные данные ( 26 вариант ): " << endl;


Draw(line, 3);

cout << "=====================================================" << endl;


cout << "Добавить новую запись (элемент массива структур)" << endl;
cout << "содержащие максимальные числовые значения в столбцах" << endl;
cout << "=====================================================" << endl <<
endl;

struct Record newTable[10];


for (int i = 0; i < 3; i++)
{
newTable[i] = line[i];
}
newTable[3] = getMax(line);
cout << "Максимальное количество баллов: " << newTable[3].points << " балл(ов)"
<< endl;
cout << "Максимальное значение места в рейтинге: " <<
newTable[3].place_in_rating << endl;
Draw(newTable, 4);

void practice2()
{

void practice3()
{

void practice4()
{
#include <iostream>
#include <fstream>
#include <windows.h>

using namespace std;

struct Date {
int day;
int month;
int year;
};

struct Record {
char username[25];
char code;
double points;
int place_in_rating;
struct Date date;
};

void printDate(int day, int month, int year, int wl) {


int w = 10;
int delta = (wl - w) / 2 - 1;
cout << left;
cout.width(delta); cout << " ";
if (day > 9) {
cout << day;
}
else {
cout << "0" << day;
}
cout << ".";
if (month > 9) {
cout << month;
}
else {
cout << "0" << month;
}
cout << ".";
cout << year;
cout.width(delta); cout << " ";
}

vo

id Draw(struct Record* line, int n) {


int width = 91;
cout << endl; cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "| Ведомость спортивных
состязаний"; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
cout << left << "| Фамилия участника ";
cout << left << "| Код команды ";
cout << left << "| Количество баллов ";
cout << left << "| Место в итоге ";
cout << left << "| Дата выступления ";
cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' ');
for (int i = 0; i < n; i++) {
cout << left << "|"; cout.width(19); cout << left << line[i].username;
cout << left << "|"; cout.width(13); cout << left << line[i].code;
cout << left << "|"; cout.width(19); cout << right << line[i].points;
cout << left << "|"; cout.width(15); cout << left <<
line[i].place_in_rating;
cout << left << "|";
printDate(line[i].date.day, line[i].date.month, line[i].date.year, 22);
cout << "|" << endl;
}
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
cout.fill(' '); cout.width(width); cout << left << "| Примечание: Д -
'Динамо', С - 'Спартак', Ш - 'Шахтер' "; cout << "|" << endl;
cout.width(width + 1); cout.fill('-'); cout << "-" << endl;
}

int main()
{
SetConsoleCP(1251);
SetConsoleOutputCP(1251);

struct Record line[10];

line[0] = { "Баландин", 'С', 123.7000, 2, {6, 6, 2022} };


line[1] = { "Шишков", 'Ш', 79.9800, 3, {7, 7, 2020} };
line[2] = { "Кравченко", 'Д', 134.8000, 1, {7, 6, 2022} };

cout << "=====================================================" << endl;


cout << "Поменять местами строковые значения в 3 и 4 записях " << endl;
cout << "файла. Данные считываются из файла." << endl;
cout << "=====================================================" << endl <<
endl;

ofstream fileRecord("Алешкин.txt");
for (int i = 0; i < 3; i++) {
fileRecord << line[i].username << " ";
fileRecord << line[i].code << " ";
fileRecord << line[i].points << " ";
fileRecord << line[i].place_in_rating << " ";
fileRecord << line[i].date.day << " ";
fileRecord << line[i].date.month << " ";
fileRecord << line[i].date.year << " \n";
}
fileRecord.close();

ifstream textFstream;
textFstream.open("Алешкин.txt", ios_base::in);
struct Record readLine[3];
for (int i = 0; i < 3; i++) {
textFstream >> readLine[i].username;
textFstream >> readLine[i].code;
textFstream >> readLine[i].points;
textFstream >> readLine[i].place_in_rating;
textFstream >> readLine[i].date.day;
textFstream >> readLine[i].date.month;
textFstream >> readLine[i].date.year;
}
textFstream.close();
Draw(readLine, 3);
ofstream filenewrecord;
filenewrecord.open("Алешкин.txt", ios::app);
struct Record new_record;
cout << "Введите фамилию участника: ";
cin >> new_record.username;
cout << "Введите код команды: ";
cin >> new_record.code;
cout << "Введите количество баллов: ";
cin >> new_record.points;
cout << "Введите место в итоге: ";
cin >> new_record.place_in_rating;
cout << "Введите дату выступления: ";
cin >> new_record.date.day >> new_record.date.month >> new_record.date.year;
filenewrecord << new_record.username << " ";
filenewrecord << new_record.code << " ";
filenewrecord << new_record.points << " ";
filenewrecord << new_record.place_in_rating << " ";
filenewrecord << new_record.date.day << " " << new_record.date.month << " " <<
new_record.date.year << "\n";
filenewrecord.close();

ifstream fileswaplines;
fileswaplines.open("Алешкин.txt", ios_base::in);
struct Record readLinenew[4];
for (int i = 0; i < 4; i++) {

fileswaplines >> readLinenew[i].username;


fileswaplines >> readLinenew[i].code;
fileswaplines >> readLinenew[i].points;
fileswaplines >> readLinenew[i].place_in_rating;
fileswaplines >> readLinenew[i].date.day;
fileswaplines >> readLinenew[i].date.month;
fileswaplines >> readLinenew[i].date.year;
}
Draw(readLinenew, 4);

swap(readLinenew[2].username, readLinenew[3].username);
swap(readLinenew[2].code, readLinenew[3].code);
fileswaplines.close();

ofstream fileswapliness;
fileswapliness.open("Алешкин.txt", ios_base::out);
for (int i = 0; i < 4; i++) {
fileswapliness << readLinenew[i].username << " ";
fileswapliness << readLinenew[i].code << " ";
fileswapliness << readLinenew[i].points << " ";
fileswapliness << readLinenew[i].place_in_rating << " ";
fileswapliness << readLinenew[i].date.day << " " <<
readLinenew[i].date.month << " " << readLinenew[i].date.year << "\n";
}
fileswapliness.close();
Draw(readLinenew, 4);

}
void practice5()
{

void practice6()
{
#include <iostream>

using namespace std;

class A {
public:
void f() { cout << "A"; }
A() { cout << "constructor A\n"; }

};

class B : public virtual A {


public:
void f() { cout << "B"; }
B() { cout << "constructor B\n"; }
};

class C : public virtual A {


public:
void f() { cout << "C"; }
C() { cout << "constructor C\n"; }
};

class E : public virtual A, public virtual C {


public:
void f() { cout << "E"; }
E() { cout << "constructor E\n"; }
};

class D : public virtual C, public virtual E, public virtual B {


public:
void f() { cout << "D"; }
D() { cout << "constructor D\n"; }
};

class F : public virtual E, public virtual D {


public:
F() { cout << "constructor F\n"; }

};

int main()
{
F object; object.f();
return 0;
}

int main(void)
{
UINT ConsoleCP=GetConsoleCP(),ConsoleOutputCP=GetConsoleOutputCP();
SetConsoleCP(CP_WIN1251),SetConsoleOutputCP(CP_WIN1251);
bool state=true;
while(state)
{
const int q=7;
for(auto i=0;i<q;++i)cout<<i+1<<" Практика "<<i<<'\n';
cout<<"0. Выход";
fflush(stdin);
string buff={};
cout<<'\n'<<"Введите команду: ";
cin>>buff;
if(!validate(buff))
{
cout<<"Некорректная команда"<<'\n';
system("pause&&cls");
continue;
}
switch(stoui(buff))
{
case 0:
state=false;
continue;
case 1:
practice0();
break;
case 2:
practice1();
break;
case 3:
practice2();
break;
case 4:
practice3();
break;
case 5:
practice4();
break;
case 6:
practice5();
break;
case 7:
practice6();
break;
default:
cout<<"Некорректная команда"<<'\n';
system("pause&&cls");
continue;
//etc
}
system("pause&&cls");
}
SetConsoleCP(ConsoleCP),SetConsoleOutputCP(ConsoleOutputCP);
}

Вам также может понравиться