Материал: Отчёт по ЛР Информатика

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

while (s[i])

{

if (s[i] == ch) { k = 1; cout << "yes\n"; break; }

i++;

}

if (k == 0) cout << "no\n";

system("pause");

return 0;

}

ПРИЛОЖЕНИЕ И (обязательное)

Программный код 3.3.1

#include <conio.h>

#include <iostream>

void main()

{

int x, y, k, l, count;

count = 0;

std::cout << "Input x:";

std::cin >> x; //Длина поля

std::cout << "Input y:";

std::cin >> y; //Ширина поля

std::cout << "Input k:";

std::cin >> k; //Положение коня по длине

std::cout << "Input l:";

std::cin >> l; //Положение коня по ширине

if ((k >= 1) && (k <= x) && (l >= 1) && (l <= y))

{

if ((k + 2 <= x) && (l + 1 <= y)) { //1

count++;

}

if ((k + 1 <= x) && (l + 2 <= y)) { //2

count++;

}

if ((k - 2 <= x) && (l + 1 <= y) && (k-2 > 0)) { //3

count++;

}

if ((k - 1 <= x) && (l + 2 <= y) && (k-1 > 0)) { //4

count++;

}

if ((k - 2 <= x) && (l - 1 <= y) && (k-2 > 0) && (l-1 > 0)) { //5

count++;

}

if ((k - 1 <= x) && (l - 2 <= y) && (k -1> 0) && (l -2> 0)) { //6

count++;

}

if ((k + 2 <= x) && (l - 1 <= y) && (l -1> 0)) { //7

count++;

}

if ((k + 1 <= x) && (l - 2 <= y) && (l -2> 0)) { //8

count++;

}

std::cout << count;

}

else

{

std::cout << "Invalid input";

}

_getch();}

ПРИЛОЖЕНИЕ К (обязательное)

Программный код 4.1.1

#include <conio.h>

#include <iostream>

void main()

{

float x,y;

x = 2;

while (x < 3)

{

y = (pow(x, 2) + 4 * x + 4) / (2 * (pow(x, 2) + 1));

std::cout << y << "\n";

x = x + 0.02;

}

_getch();

}

ПРИЛОЖЕНИЕ Л (обязательное)

Программный код 4.2.1

#include <conio.h>

#include <iostream>

void main()

{

int n;

float s = 0;

float f = 1;

float d = 1;

std::cout << "Input N \n";

std::cin >> n;

for (int i=1; i <=n; i++ )

{

f *= i;

int b = 1;

d = 1;

while (b <= (n + i))

{

d *= b++;

}

s += (f / d);

}

std::cout << s;

_getch();

}

ПРИЛОЖЕНИЕ М (обязательное)

Программный код 5.1.1

#include <conio.h>

#include <iostream>

void main()

{

int i;

char str[101];

std::cout << "Input string:";

std::cin.getline(str, 101);

std::cout << "\n\n";

for (i = 0; i < strlen(str); i++)

if (str[i] == ' ')

str[i] = '*';

std::cout << str;

_getch();

}

ПРИЛОЖЕНИЕ Н (обязательное)

Программный код 5.2.1

#include <conio.h>

#include <iostream>

void main()

{

int n;

int b = 1;

int c = 0;

std::cout << "Input mas size \n";

std::cin >> n;

int* mas = new int[n];

for (int i = 0; i <= n; i++)

{

if (i % 2 == 0)

{

mas[i] = b;

b++;

std::cout << mas[i] << "\n";

}

else

{

mas[i] = n - c;

c++;

std::cout << mas[i] << "\n";

}

}

_getch();}

ПРИЛОЖЕНИЕ П (обязательное)

Программный код 5.3.1

#include <conio.h>

#include <iostream>

using namespace std;

int main()

{

setlocale(LC_ALL, "RUS");

int i, st, j, N, M, S, a[20][20];

int max = 0;

int* A;

cout << "Введите количество строк,N=";

cin >> N;

cout << "Введите количество столбцов,M=";

cin >> M;

A = new int[N * M];

cout << "Составьте матрицу А\n";

for (i = 0; i < N; i++)

for (j = 0; j < M; j++)

cin >> a[i][j];

for (i = 0; i < N; i++)

{

for (j = 0; j < M; j++)

if (a[i][j] > max)

{

max = a[i][j];

st = i;

}

}

for (S = j = 0; j < M; j++)

S += a[st][j];

cout << "сумма равна,S=" << S << endl;

system("pause");

return 0;

}

Приложение р (обязательное) Программный код 6.1.1

#include <iostream>

#include <conio.h>

int Median(double a, double b, double c)

{

double m;

m = 0.5 * sqrt(2 * b * b + 2 * c * c - a * a);

std::cout << m;

return(m);

}

int main()

{

setlocale(LC_ALL, "RUS");

double A, B, C, m;

std::cout << "Введите длину стороны А:";

std::cin >> A;

std::cout << "Введите длину стороны B:";

std::cin >> B;

std::cout << "Введите длину стороны C:";

std::cin >> C;

m = Median(A, B, C);

_getch();

}

Приложение с (обязательное) Программный код 6.2.1

#include <iostream>

#include <conio.h>

int Compare(int X, int Y, int Z, int& min, int& max)

{

if (X > Y)

{

max = X;

min = Y;

}

else

{

max = Y;

min = X;

}

if (max < Z)

{

max = Z;

}

else if (min > Z)

{

min = Z;

}

return 0;

}

int main()

{

setlocale(LC_ALL, "RUS");

int min, max, x, y, z;

std::cout << "Введите 1-е число: ";

std::cin >> x;

std::cout << "Введите 2-е число: ";

std::cin >> y;

std::cout << "Введите 3-е число: ";

std::cin >> z;

Compare(x, y, z, min, max);

std::cout << "\nМинимальное значение: ";

std::cout << min;

std::cout << "\nМаксимальное значение: ";

std::cout << max;

_getch();

}

Приложение т (обязательное) Программный код 6.3.1

#include <iostream>

#include <conio.h>

int Shift(int N, int M[])

{

int c;

for (int i = 10; i > 0; i--)

{

c = M[N];

M[i] = M[i - 1];

}

M[0] = c;

for (int i = 0; i < N; i++)

std::cout << M[i] << " ";

return 0;

}

int main()

{

int n;

std::cout << "Input mas size: ";

std::cin >> n;

int* mas = new int[n];

std::cout << "Input mas: ";

for (int i = 0; i < n; i++)

std::cin >> mas[i];

Shift(n, mas);

_getch();

Приложение у (обязательное) Программный код 7.1.1

#include <iostream>

#include <conio.h>

using namespace std;

struct Book

{

string name, publ, author;

int year, page;

};

int search(Book mas[2])

{

string searchname;

cout << "Введите название книги: ";

cin >> searchname;

for (int i = 0; i < 2; i++)

{

if (mas[i].name == searchname)

{

cout << "\n Название: " << mas[i].name << "\n Издание: " << mas[i].publ

<< "\n Автор: " << mas[i].author << "\n Год: " << mas[i].year

<< "\n Страниц: " << mas[i].page;

}

}

return 0;

}

int aubook( Book aumas[2])

{

string auau;

cout << "Введите автора: ";

cin >> auau;

for (int i = 0; i < 2; i++)

{

if (aumas[i].author == auau)

{

cout << "\n Название: " << aumas[i].name << "\n Издание: " << aumas[i].publ

<< "\n Автор: " << aumas[i].author << "\n Год: " << aumas[i].year

<< "\n Страниц: " << aumas[i].page;

}

}

return 0;

}

int main()

{

int c;

setlocale(LC_ALL, "RUS");

Book xeq[2]; //каталог книг

xeq[0].name = "Hudo";

xeq[0].publ = "Kniga";

xeq[0].author = "P.I.Author";

xeq[0].year = 2020;

xeq[0].page = 35;

//-------------------------------

xeq[1].name = "ABC";

xeq[1].publ = "Vizantiya";

xeq[1].author = "Drevniy";

xeq[1].year = 1632;

xeq[1].page = 255;

//-----------------------------

cout << "Для поиска по названию введите 1\n"

<<"Для поиска по автору любое число\n";

cin >> c;

if (c == 1)

{

search (xeq);

}

else

aubook (xeq);

_getch();

}

Приложение ф (обязательное) Программный код 7.2.1

#include <iostream>

#include <conio.h>

using namespace std;

struct strochki

{

string a;

};

strochki operator+ (const strochki& X, const strochki& Y)

{

strochki c;

c.a = X.a + Y.a;

return c;

}

void operator += (strochki& k, const strochki& l)

{

k.a += l.a;

}

int main()

{

strochki pervaya, vtoraya;

pervaya.a = "Gutten ";

vtoraya.a = "Morgen ";

strochki tri = pervaya + vtoraya;

cout << tri.a << "\n";

pervaya += vtoraya;

cout << pervaya.a;

_getch();

}

Приложение х (обязательное) Программный код 8.1.1

#include <iostream>

using namespace std;

long int StrLen(char* _str)

{

long int size = 0;

for (; _str[size] != 0; size++);

return size;

}

void StrCpy(char* in_str, char* src_str)

{

for (int i = 0; i < StrLen(in_str); i++)

in_str[i] = src_str[i];

}

class MyString

{

private:

char* str;

long int length;

long int capacity;

public:

MyString()

{

str = NULL;

NewStr();

}

MyString(char* str, int length)

{

this->str = str;

this->length = length;

}

void AddChar(char c)

{

if (length + 1 >= capacity)

{

capacity += 128;

char* newStr = new char[capacity];

if (length > 0)

{

StrCpy(newStr, str);

}

delete[] str;

str = newStr;

}

str[length] = c;

length++;

}

void NewStr()

{

// delete str;

str = NULL;

length = 0;

capacity = 0;

char c;

while ((c = getchar()) != '\n')

{

AddChar(c);

}

}

void display()

{

for (int i = 0; i < length; i++)

cout << str[i];

}

void operator+=(const MyString& rhs)

{

int sz = this -> length + rhs.length;

char* ts = new char[sz];

for (int i = 0; i < this->length; i++)

ts[i] = this->str[i];

for (int i = this->length, j = 0; i <= sz; i++, j++)

ts[i] = rhs.str[j];

delete[] this->str;

this->str = ts;

this->length = sz;

}

MyString& operator+(const MyString& rhs)

{

int sz = this-> length + rhs.length;

char* ts = new char[sz];

for (int i = 0; i < this->length; i++)

ts[i] = this->str[i];

for (int ii = this->length, j = 0; ii <= sz; ii++, j++)

ts[ii] = rhs.str[j];

MyString a(ts, sz);

return a;

}

void GetStrPtr()

{

cout << &this->str;

}

};

int main(int argc, char** argv) {

MyString s1;

s1.display();

cout << endl;

MyString s2;

s2.display();

cout << endl;

s1 += s2;

s1.display();

cout << endl;

s2.display();

cout << endl;

s1.NewStr();

s1.display();

cout << endl;

s2 = s2 + s1;

s2.display();

cout << endl;

s2.NewStr();

s2.display();

cout << endl;

s1.GetStrPtr();

cout << endl;

s2.GetStrPtr();

cin.get();

return 0;

}

Москва 2020

Источник: https://studfile.net/preview/16421899/