Reformat to webkit style

This commit is contained in:
Inex Code 2020-09-19 11:41:40 +00:00
parent 90c171fa58
commit bbede5b1e9
3 changed files with 67 additions and 111 deletions

View file

@ -3,8 +3,7 @@
using namespace std; using namespace std;
class Student class Student {
{
uint number; uint number;
string first_name; string first_name;
string second_name; string second_name;
@ -19,8 +18,7 @@ public:
uint first_var(uint num_of_vars) uint first_var(uint num_of_vars)
{ {
if (num_of_vars == 0) if (num_of_vars == 0) {
{
return 0; return 0;
} }
@ -28,22 +26,21 @@ public:
} }
uint second_var(uint num_of_vars) uint second_var(uint num_of_vars)
{ {
if (num_of_vars == 0) if (num_of_vars == 0) {
{
return 0; return 0;
} }
return (uint)first_name.front() % num_of_vars; return (uint)first_name.front() % num_of_vars;
} }
uint third_var(uint num_of_vars) uint third_var(uint num_of_vars)
{ {
if (num_of_vars == 0) if (num_of_vars == 0) {
{
return 0; return 0;
} }
return (uint)second_name.front() % num_of_vars; return (uint)second_name.front() % num_of_vars;
} }
void print_name () { void print_name()
{
cout << number << ". " << first_name << " " << second_name << "\n"; cout << number << ". " << first_name << " " << second_name << "\n";
} }
}; };

View file

@ -5,42 +5,37 @@ using namespace std;
void part1(uint N, uint M) void part1(uint N, uint M)
{ {
for (uint n = 0; n < N; n++) for (uint n = 0; n < N; n++) {
{ for (uint m = 0; m < M; m++) {
for (uint m = 0; m < M; m++) cout << "*";
{ }
cout << "*"; cout << "\n";
} }
cout << "\n"; cout << "\n";
}
cout << "\n";
} }
void part2(uint N, uint M) void part2(uint N, uint M)
{ {
for (uint n = 0; n < N; n++) for (uint n = 0; n < N; n++) {
{ if (n < M)
if (n < M) for (uint i = 0; i < M - n; i++) {
for (uint i = 0; i < M-n; i++) cout << " ";
{ }
cout << " "; for (uint j = 0; j < n * 2; j++) {
} cout << "*";
for (uint j = 0; j < n*2; j++) }
{ cout << "\n";
cout << "*"; }
} cout << "\n";
cout << "\n";
}
cout << "\n";
} }
int main() int main()
{ {
uint N = 6; uint N = 6;
uint M = 6; uint M = 6;
part1(N, M); part1(N, M);
part2(N, M); part2(N, M);
return 0; return 0;
} }

View file

@ -1,5 +1,5 @@
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include <string> #include <string>
using namespace std; using namespace std;
@ -14,22 +14,19 @@ using namespace std;
y y
*/ */
class Image class Image {
{
uint mx; uint mx;
uint my; uint my;
uint *data; uint* data;
public: public:
Image(uint tmx, uint tmy) Image(uint tmx, uint tmy)
{ // Должен инициализировать изображение 0 { // Должен инициализировать изображение 0
mx = tmx; mx = tmx;
my = tmy; my = tmy;
data = (uint *)malloc(sizeof(uint) * mx * my); data = (uint*)malloc(sizeof(uint) * mx * my);
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{ for (uint x = 0; x < mx; x++) {
for (uint x = 0; x < mx; x++)
{
data[mx * y + x] = 27; data[mx * y + x] = 27;
} }
} }
@ -52,10 +49,8 @@ public:
void show() void show()
{ // Должен выдавать на экран изображение при помощи printf или std::cout { // Должен выдавать на экран изображение при помощи printf или std::cout
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{ for (uint x = 0; x < mx; x++) {
for (uint x = 0; x < mx; x++)
{
cout << "\033[48;5;" << data[mx * y + x] << "m \033[0m"; cout << "\033[48;5;" << data[mx * y + x] << "m \033[0m";
} }
cout << "\n"; cout << "\n";
@ -70,52 +65,42 @@ public:
void set(uint x, uint y, uint color) void set(uint x, uint y, uint color)
{ {
if (x >= mx) if (x >= mx) {
{
throw(x); throw(x);
} }
if (y >= my) if (y >= my) {
{
throw(y); throw(y);
} }
data[mx * (y) + (x)] = color; data[mx * (y) + (x)] = color;
} }
void copy(Image &original) void copy(Image& original)
{ {
freemem(); freemem();
mx = original.getMx(); mx = original.getMx();
my = original.getMy(); my = original.getMy();
data = (uint *)malloc(sizeof(uint) * mx * my); data = (uint*)malloc(sizeof(uint) * mx * my);
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{ for (uint x = 0; x < mx; x++) {
for (uint x = 0; x < mx; x++)
{
data[mx * y + x] = original.get(x, y); data[mx * y + x] = original.get(x, y);
} }
} }
} }
// Returns true if equal // Returns true if equal
bool compare(Image &original) bool compare(Image& original)
{ {
if (original.getMx() == mx && original.getMy() == my) if (original.getMx() == mx && original.getMy() == my) {
{ for (uint y = 0; y < my; y++) {
for (uint y = 0; y < my; y++) for (uint x = 0; x < mx; x++) {
{ if (data[mx * y + x] != original.get(x, y)) {
for (uint x = 0; x < mx; x++)
{
if (data[mx * y + x] != original.get(x, y))
{
cout << "Not equal: x = " << x << "; y = " << y << "\n"; cout << "Not equal: x = " << x << "; y = " << y << "\n";
return false; return false;
} }
} }
} }
return true; return true;
} } else {
else
{
cout << "original size: " << original.getMx() << "x" << original.getMy() << "\n"; cout << "original size: " << original.getMx() << "x" << original.getMy() << "\n";
cout << "current size: " << mx << "x" << my << "\n"; cout << "current size: " << mx << "x" << my << "\n";
return false; return false;
@ -124,24 +109,20 @@ public:
void draw_horizontal(uint y, uint color) void draw_horizontal(uint y, uint color)
{ {
if (y >= my) if (y >= my) {
{
throw(y); throw(y);
} }
for (uint x = 0; x < mx; x++) for (uint x = 0; x < mx; x++) {
{
data[mx * y + x] = color; data[mx * y + x] = color;
} }
} }
void draw_vertical(uint x, uint color) void draw_vertical(uint x, uint color)
{ {
if (x >= mx) if (x >= mx) {
{
throw(x); throw(x);
} }
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{
data[mx * y + x] = color; data[mx * y + x] = color;
} }
} }
@ -150,22 +131,17 @@ public:
{ {
ofstream writefile; ofstream writefile;
writefile.open(filename); writefile.open(filename);
if (writefile.is_open()) if (writefile.is_open()) {
{
writefile << mx << "\n" writefile << mx << "\n"
<< my << "\n"; << my << "\n";
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{ for (uint x = 0; x < mx; x++) {
for (uint x = 0; x < mx; x++)
{
writefile << data[mx * y + x] << "\n"; writefile << data[mx * y + x] << "\n";
} }
} }
writefile << "\n"; writefile << "\n";
writefile.close(); writefile.close();
} } else {
else
{
cerr << "saving to file failed\n"; cerr << "saving to file failed\n";
} }
} }
@ -175,32 +151,24 @@ public:
string line; string line;
ifstream readfile; ifstream readfile;
readfile.open(filename); readfile.open(filename);
if (readfile.is_open()) if (readfile.is_open()) {
{ try {
try
{
getline(readfile, line); getline(readfile, line);
mx = stoi(line); mx = stoi(line);
getline(readfile, line); getline(readfile, line);
my = stoi(line); my = stoi(line);
for (uint y = 0; y < my; y++) for (uint y = 0; y < my; y++) {
{ for (uint x = 0; x < mx; x++) {
for (uint x = 0; x < mx; x++)
{
getline(readfile, line); getline(readfile, line);
data[mx * y + x] = stoi(line); data[mx * y + x] = stoi(line);
} }
} }
} } catch (const exception& e) {
catch (const exception &e)
{
cerr << e.what() << '\n'; cerr << e.what() << '\n';
} }
} } else {
else
{
cerr << "reading file failed"; cerr << "reading file failed";
} }
readfile.close(); readfile.close();
@ -217,18 +185,14 @@ int main()
cout << "Image b \n"; cout << "Image b \n";
b.show(); b.show();
b.copy(a); b.copy(a);
if (b.compare(a) == true) if (b.compare(a) == true) {
{
cout << "a == b after copy\n"; cout << "a == b after copy\n";
} } else {
else
{
cout << "a != b after copy!\n"; cout << "a != b after copy!\n";
} }
b.set(4, 3, 20); b.set(4, 3, 20);
for (int i = 5; i < 9; i++) for (int i = 5; i < 9; i++) {
{
b.set(i, 5, 45); b.set(i, 5, 45);
} }
b.set(9, 3, 20); b.set(9, 3, 20);