C++ — Блог по программированию https://ot7.ru Курсы по веб дизайну, программированию, графике и дизайну Sun, 18 Nov 2018 17:00:53 +0000 ru-RU hourly 1 https://wordpress.org/?v=6.7.2 https://ot7.ru/wp-content/uploads/2019/11/cropped-it2-32x32.jpg C++ — Блог по программированию https://ot7.ru 32 32 Урок 11, с++, работа с массивами, добавление элементов и вставка элементов в массив. https://ot7.ru/2018/11/18/%d1%83%d1%80%d0%be%d0%ba-11-%d1%81-%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%b0-%d1%81-%d0%bc%d0%b0%d1%81%d1%81%d0%b8%d0%b2%d0%b0%d0%bc%d0%b8-%d0%b4%d0%be%d0%b1%d0%b0%d0%b2%d0%bb%d0%b5%d0%bd%d0%b8%d0%b5/ Sun, 18 Nov 2018 17:00:53 +0000 http://manuscript.ikurs.kz/?p=2339 Видео к уроку.

Код к уроку.

// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void add(int value, int *product,int &count)
{
  product[count] = value;
  count++;

}
void insert(int value, int pos,int *product, int &count)
{
  for (int i = count - 1; i >=pos; i--)
    product[i + 1] = product[i];
  product[pos] = value;
  count++;
}
void print(int *product, int &count)
{
  for (int i = 0; i < count; i++)
    cout << product[i]<<"\n";
  cout << "------------------------------";
}
int main()
{
  int product[100];
  int count = 0;
  add(1, product, count);
  add(3, product, count);
  add(5, product, count);
  insert(2,1, product, count);
  insert(4, 3, product, count);
  print( product, count);
  int a;
  cin >> a;
  return 0;
}

 

]]>
Урок 10. с++. Стеки в с++. Программирование стеков. https://ot7.ru/2018/11/18/%d1%83%d1%80%d0%be%d0%ba-10-%d1%81-%d1%81%d1%82%d0%b5%d0%ba%d0%b8-%d0%b2-%d1%81-%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-%d1%81%d1%82/ Sun, 18 Nov 2018 07:50:13 +0000 http://manuscript.ikurs.kz/?p=2336 Видео к уроку.

Код к уроку.

Стек  FIFO

// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
//пример реализации стека FIFO

int pop(int *product, int &pos)//извлекать товары
{
  if (pos == 0)
  {
    cout << "stack empty";
    return -1;
  }
  pos--;
  int ret=product[0];
  for (int i = 1; i <= pos; i++)
  {
    product[i - 1] = product[i];
  }
  return ret;
}
void push(int item, int *product, int &pos)//помещаем в массив
{
  if (pos == 99)
  {
    cout << "stack overflow";
    return;
  }
  product[pos] = item;
  pos++;
}
int main()
{
  int pos = 0;
  int product[100];
  push(10, product, pos);
  push(11, product, pos);
  push(12, product, pos);
  cout << pop(product, pos) << "\n";
  cout << pop(product, pos) << "\n";
  cout << pop(product, pos) << "\n";
  int a;
  cin >> a;
  return 0;
}

Стек LIFO

// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
//пример реализации стека LIFO

int pop(int *product, int &pos)//извлекать товары
{
  if (pos ==0)
  {
    cout << "stack empty";
    return -1;
  }
  pos--;
  product[pos];
  
  return product[pos];
}
void push(int item, int *product, int &pos)//помещаем в массив
{
  if (pos == 99)
  {
    cout << "stack overflow";
    return;
  }
  product[pos] = item;
  pos++;
}
int main()
{
  int pos = 0;
  int product[100];
  push(10, product, pos);
  push(11, product, pos);
  push(12, product, pos);
  cout << pop(product, pos)<<"\n";
  cout << pop(product, pos) << "\n";
  cout << pop(product, pos) << "\n";
  int a;
  cin >> a;
  return 0;
}

 

]]>
Урок 9. Работа с файлами в с++ https://ot7.ru/2018/11/15/%d1%80%d0%b0%d0%b1%d0%be%d1%82%d0%b0-%d1%81-%d1%84%d0%b0%d0%b9%d0%bb%d0%b0%d0%bc%d0%b8-%d0%b2-%d1%81/ Thu, 15 Nov 2018 14:44:54 +0000 http://manuscript.ikurs.kz/?p=2334 Видео для урока.

Код урока.

// ConsoleApplication3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
  ofstream myfile;
  myfile.open("login.txt");
  myfile << "admin";
  myfile.close();
  myfile.open("password.txt");
  myfile << "123";
  myfile.close();
  ifstream file("password.txt");
  char *pass1;
  pass1 = new char[100];
  char *login1;
  login1 = new char[100];
  
  file.getline(pass1,'\n');
  file.close();
  file.open("login.txt");
  file.getline(login1, '\n');
  
  char *login;
  char *password;
  login = new char[100];
  password = new char[100];
  cout << "Enter login: ";
  cin >> login;
  cout << "Enter password: ";
  cin >> password;
  if (strcmp(login, login1) == 0 && strcmp(pass1, password) == 0)
  {
    cout << "Hello admin.";
  }
  else
    {
    cout << "You are wrong.";
    }
  cin >> password;
  delete [] pass1;
  delete [] login;
  delete [] password;
  return 0;
}

 

]]>
Урок 4. Функции в C++ https://ot7.ru/2018/10/05/%d1%83%d1%80%d0%be%d0%ba-4-%d1%84%d1%83%d0%bd%d0%ba%d1%86%d0%b8%d0%b8-%d0%b2-c/ Fri, 05 Oct 2018 16:19:57 +0000 http://manuscript.ikurs.kz/?p=2328 Задания на функции.

  1. Написать функцию которая возвращает true если число четное и false если число нечетное.
  2. Написать функцию которая переводит градусы Цельсия в градусы Фаренгейта.
  3. Написать функцию которая возвращает сумму целых чисел в указанном диапазоне.
  4. Написать функцию которая возводит число в указанную степень. В функцию передаются два параметра число и степень в которую его нужно возвести.
  5. Написать функцию которая разворачивает число. К примеру если в функцию передать 123 то она вернет 321.
  6. Написать функцию которая будет высчитывать одну 12 от переданного числа.
  7. Написать функцию которая будет переводить в шестнадцатеричный формат входящее десятичное число от 0 до 15.
  8. Написать функцию которая будет возвращать столицу по переданному как параметр городу.
  9. Написать функцию которая из трех переданных переменных вернет максимальную.
  10. Написать функцию которая из 4х переданных переменных в виде параметров функции вернет среднее значение.
]]>
Урок 3. C++. Массивы и структуры https://ot7.ru/2018/09/22/%d1%83%d1%80%d0%be%d0%ba-3-c-%d0%bc%d0%b0%d1%81%d1%81%d0%b8%d0%b2%d1%8b-%d0%b8-%d1%81%d1%82%d1%80%d1%83%d0%ba%d1%82%d1%83%d1%80%d1%8b/ Sat, 22 Sep 2018 10:32:35 +0000 http://manuscript.ikurs.kz/?p=2325 Код урока.

// ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;

struct student
{
  int age;
  string name;
  
};
struct group
{
  student s[10];
  string name;
};
int main()
{
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);
  int age[30];
  string name[3];
  name[0] = "Василий";
  name[1] = "Михаил";
  name[2] = "Павел";
  for (int i = 0; i < 30; i++)
  {
    age[i] = rand()%100;
  }
  for (int i = 0; i < 30; i++)
  {
    cout << age[i] << " ";
  }
  cout << "\n";
  for (int i = 0; i < 3; i++)
  {
    cout << name[i] << " ";
  }
  //----------------Поиск максимального значения.
  int max = age[0];
  for (int i = 1; i < 30; i++)
  {
    if(max < age[i])
      max=age[i];
  }
  cout <<"\nМаксимальное значение = "<< max << " ";
  //----------------смена двух переменных местами-----------------------
  int a, b;
  a = 10;
  b = 12;
  int temp=a;
  a = b;
  b = temp;
  cout << "\na=" << a<< " ";
  cout << "\nb=" << b << " ";
  //----------------сортировка массива-----------------------
  for (int i = 0; i < 30; i++)
  {
    int max, pos;
    pos = i;
    max = age[i];
    for (int j = i; j < 30; j++)
      {
      if (max < age[j])
        {
        max = age[j];
        pos = j;
        }
      }
    int temp = age[i];
    age[i] = age[pos];
    age[pos] = temp;

  }
  //---------------------Вывод массива
  cout << "\n";
  for (int i = 0; i < 30; i++)
  {
    cout << age[i] << " ";
  }
  
  student vasya;
  vasya.age = 20;
  
  vasya.name = "Василий";
  student stud[10];
  stud[0].age = 10;
  stud[0].name = "Николай";
  
  group g[10];
  g[0].name = "ЭА 2015";
  g[0].s[0].age = 20;
  g[0].s[0].name= "Василий";

}

 

]]>
Урок 2. C++. Операторы ветвления кода и циклы. https://ot7.ru/2018/09/19/%d1%83%d1%80%d0%be%d0%ba-2-c-%d0%be%d0%bf%d0%b5%d1%80%d0%b0%d1%82%d0%be%d1%80%d1%8b-%d0%b2%d0%b5%d1%82%d0%b2%d0%bb%d0%b5%d0%bd%d0%b8%d1%8f-%d0%ba%d0%be%d0%b4%d0%b0-%d0%b8-%d1%86%d0%b8%d0%ba%d0%bb/ Wed, 19 Sep 2018 15:08:04 +0000 http://manuscript.ikurs.kz/?p=2323 Код к уроку:

// ConsoleApplication1.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

#include "pch.h"
#include <iostream>
#include <Windows.h>
#include <string>
using namespace std;
int main()
{
  SetConsoleCP(1251);
  SetConsoleOutputCP(1251);

  int a, b;
  a = 1;
  b = 1;

  if (a == b) {
    std::cout << "Переменная а=b!\n";
  }
  if (a != b) {
    std::cout << "Переменная а не равна b!\n";
  }
  if (a > b) {
    std::cout << "Переменная а больше b!\n";
  }
  if (a < b) {
    std::cout << "Переменная а меньше b!\n";
  }
  if (a >= b) {
    std::cout << "Переменная а больше или равна b!\n";
  }
  if (a <= b) {
    std::cout << "Переменная а меньше или равна b!\n";
  }
  //полная форма оператора if
  if (a==b){
    std::cout << "Переменная а=b!\n";
  }
  else {
    std::cout << "Переменная а не равна b!\n";
  }

  string  login, password;
  string  login1, password1;
  login = "admin";
  password = "123";
  login1 = "admin1";
  password1 = "1234";

  if (login == "admin" && password == "123")
  {
    std::cout << "Логин и пароль введены верно. !\n";
  }
  if ((login == "admin" && password == "123") || (login1 == "admin1" && password1 == "1234"))
  {
    std::cout << "Логин и пароль введены верно. !\n";
  }

  if(login == "admin" && password == "123")
    std::cout << "Логин и пароль введены верно. !\n";
  else 
    std::cout << "Логин и пароль введены неверно. !\n";
  if (login == "admin")
  {
    std::cout << "Логин введен неверно. !\n";
    if (password == "123")
    {
      std::cout << "Пароль введен неверно. !\n";
    }
  }

  int answer = 1;
  if (answer == 1)
  {
    //выполняем код для ответа 1
  }
  else
  {
    if (answer == 2)
    {
      // код для ответа 2
    }
    else
    {
      if (answer == 3)
      {
      //код для ответа 3
      }
    }
  }
  answer =2;
  switch (answer)
  {
  case 1:
    std::cout << "Верно. !\n";
    break;
  case 2:
    std::cout << "Неверно. !\n";
    break;
  case 3:
    std::cout << "Неверно. !\n";
    break;
  default:
    std::cout << "Вы ввели  неверное значение. !\n";
    

  }
  cout << "a= " << a;

  for (int i = 0; i < 10; i++)
  {
    cout << "\n i= " << i;

  }
  cout << "\n Конец цикла";
  for (int i = 0; i < 10; i+=2)
  {
    cout << "\n i= " << i;

  }
  cout << "\n Конец цикла";
  for (int i = 9; i >=0; i--)
  {
    cout << "\n i= " << i;

  }
  cout << "\n Конец цикла\n";
  for (int i = 1; i < 10; i++)
  {
    for (int j =1; j < 10; j++)
    {
      cout <<i <<"*"<<j<<"="<<i*j<<"\t";
    }
    cout << "\n";

  }
  cout << "\n Конец цикла";
  int i = 10;
  while (i > 0)
  {
    i--;
    cout << "\n i= " << i;

  }
  i =10;
  do {
    i--;
    cout << "\n i= " << i;

  } while (i > 0);


}

// Запуск программы: CTRL+F5 или меню "Отладка" > "Запуск без отладки"
// Отладка программы: F5 или меню "Отладка" > "Запустить отладку"

// Советы по началу работы 
//   1. В окне обозревателя решений можно добавлять файлы и управлять ими.
//   2. В окне Team Explorer можно подключиться к системе управления версиями.
//   3. В окне "Выходные данные" можно просматривать выходные данные сборки и другие сообщения.
//   4. В окне "Список ошибок" можно просматривать ошибки.
//   5. Последовательно выберите пункты меню "Проект" > "Добавить новый элемент", чтобы создать файлы кода, или "Проект" > "Добавить существующий элемент", чтобы добавить в проект существующие файлы кода.
//   6. Чтобы снова открыть этот проект позже, выберите пункты меню "Файл" > "Открыть" > "Проект" и выберите SLN-файл.

 

]]>
Урок 1. С++ Первый урок. https://ot7.ru/2018/09/15/%d1%83%d1%80%d0%be%d0%ba-1-%d1%81-%d0%bf%d0%b5%d1%80%d0%b2%d1%8b%d0%b9-%d1%83%d1%80%d0%be%d0%ba/ Sat, 15 Sep 2018 08:45:52 +0000 http://manuscript.ikurs.kz/?p=2316 План урока:

  1.  Переменные.
  2. Системы исчисления.
  3. Арифметические операторы.
  4. Битовые операторы
  5. Переполнение переменных.
  6. Вывод в консоль.
  7. Чтение из консоли.
  8. Операторы ветвления кода. Понятие алгоритм.
  9. Алгоритм смены двух переменных местами.
  10. Оператор if else
  11. Оператор switch case
  12. Кодировка CP1251

Задания.

  1. Прочитать с консоли свое имя и вывести строку приветствия.  Приветствуем вас ИМЯ в нашей первой программе. Вместо слова имя нужно подставить значение считанное с консоли.
  2. Вывести в консоль значения от 1 до 10 используя инкремент.
  3. Вывести в консоль значения от 10 до 1 используя декремент.
  4. Показать результат переполнения переменной на примере своего кода.
  5. В бинарном виде выставить третий бит в 1.
  6. Проверить наличие 1 в третьем бите и вывести результат в консоль.
  7. Составьте алгоритм для задания 8.
  8. Используя алгоритмы смены двух переменных местами и алгоритм  поиска максимального числа поменяйте две переменные местами если a>b. Иными словами нужно написать код для того чтобы переменная а всегда была меньше b не зависимо от исходных значений.

 

]]>
Примеры решения заданий по c++ в visual studio https://ot7.ru/2018/01/18/%d0%bf%d1%80%d0%b8%d0%bc%d0%b5%d1%80%d1%8b-%d1%80%d0%b5%d1%88%d0%b5%d0%bd%d0%b8%d1%8f-%d0%b7%d0%b0%d0%b4%d0%b0%d0%bd%d0%b8%d0%b9-%d0%bf%d0%be-c-%d0%b2-visual-studio/ Thu, 18 Jan 2018 07:45:59 +0000 http://manuscript.ikurs.kz/?p=2193 Решение к задаче 1.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "1. Выводим в строку значения от 0 до 10 \n";

  for (int i = 0; i <= 10; i++)
  {
    cout << i;
    cout << ";";
  }
  system("pause");
  return 0;
}

Решение к задаче 2.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n2. Выводим в строку значения от 10 до 0 \n";

  for (int i = 10; i >= 0; i--)
  {
    cout << i;
    cout << ";";

  }
  system("pause");
  return 0;
}

Решение к задаче 3.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n3. Выводим в строку значения от 60 до 100 \n";

  for (int i = 60; i <= 100; i++)
  {
    cout << i;
    cout << ";";
  }
  system("pause");
  return 0;
}

Решение к задаче 4.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n4. Выводим в строку значения от -39 до 100 \n";

  for (int i = -39; i <= 100; i++)
  {
    cout << i;
    cout << ";";
  }
  system("pause");
  return 0;
}

Решение к задаче 5.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n5. Выводим в строку четные числа от 2 до 50\n";

  for (int i = 2; i <= 50; i += 2)
  {
    cout << i;
    cout << ";";
  }
  system("pause");
  return 0;
}

Решение к задаче 6.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n6. Выводим в строку нечетные числа от 1 до 49\n";

  for (int i = 1; i <= 49; i += 2)
  {
    cout << i;
    cout << ";";
  }
  system("pause");
  return 0;
}

Задачи на вложенные циклы и на матрицы с использованием операторов for и if на c++.

Решение к задаче 7.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n7. Выводим таблицу  нулей 10x10\n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1; x <= 10; x++)
    {

      cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;
}

Решение к задаче 8.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n8. Выводим таблицу  нулей с диагональю из единиц 10x10\n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x==y)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 9.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n9. Выводим таблицу  с рамочкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x==1 || x==10 ||y==1 || y==10 )
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решения к задаче 10.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n10. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(y<=5)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 11.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n11. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(y<=5)
        cout << 0;
      else
        cout << 1;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 12.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n12. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x<=5)
        cout << 0;
      else
        cout << 1;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 13.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n13. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x<=5)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 14.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n14. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x>y)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 15.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n15. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x>=10-y+1)
        cout << 0;
      else
        cout << 1;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 16.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n16. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if(x>=10-y+1)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 17.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n17. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ( (x >= 10 - y + 1 && x<=y) || (x <= 10 - y + 1 && x>=y))
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 18.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n18. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ( y >= 10 - x + 1 && y<=x)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 19.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n19. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ( x >= 10 - y + 1 && x<=y)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 20.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n20. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ( y <= 10 - x + 1 && y>=x)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 21.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n21. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if (x <= 10 - y + 1 && x>=y)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 22.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n22. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ((x <10 - y + 1 && x>y) || (x > 10 - y + 1 && x < y))
        cout << 0;
      else
        cout << 1;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

Решение к задаче 23.

#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;

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



  cout << "\n23. Выводим таблицу  с заливкой \n";

  for (int y = 1; y <= 10; y++)
  {
    for (int x = 1;x <= 10;x++)
    {

      if ( (x ==3 && y>2 && y<9)  || (x == 8 && y>2 && y<9) || (y == 3 && x>2 && x<9) || (y == 8 && x>2 && x<9) || x==1 || y==1 || x==10 || y==10)
        cout << 1;
      else
        cout << 0;
      cout << " ";
    }
    cout << "\n";
  }
  system("pause");
  return 0;

}

 

 

]]>
Задания по программированию на C++ https://ot7.ru/2018/01/18/%d0%b7%d0%b0%d0%b4%d0%b0%d0%bd%d0%b8%d1%8f-%d0%bf%d0%be-%d0%bf%d1%80%d0%be%d0%b3%d1%80%d0%b0%d0%bc%d0%bc%d0%b8%d1%80%d0%be%d0%b2%d0%b0%d0%bd%d0%b8%d1%8e-%d0%bd%d0%b0-c/ Thu, 18 Jan 2018 07:45:11 +0000 http://manuscript.ikurs.kz/?p=2191 Задание:

  1. Вывести в строку значения от 0 до 10 включительно
  2. Вывести в строку значения от 10 до 0 включительно
  3. Вывести в строку значения от 60 до 100
  4. Вывести в столбец значения от -39 до 100
  5. Вывести в строку четные числа от 0 до 10
  6. Вывести в строку нечетные числа от 1 до 9.
  7. Вывести в строку ряд 100 200 300 …..1000
  8. Вывести рисунки как на картинке ниже используя циклы

 

9. Вывести таблицу из нулей

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

10. Вывести таблицу c диагональю из 1

1 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0
0 0 0 1 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1

11. Вывести таблицу c рамочкой из 1

1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1

12. Вывести таблицу c заливкой верхней части 

1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

13. Вывести таблицу c заливкой нижней части

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1

14. Вывести таблицу c заливкой по образцу

0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 1 1 1 1

15. Вывести таблицу c заливкой по образцу

1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 0 0 0 0 0

15. Вывести таблицу c заливкой по образцу
0 1 1 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1
0 0 0 1 1 1 1 1 1
0 0 0 0 1 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0

16. Вывести таблицу c заливкой по образцу

1 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 0 0
1 1 1 1 1 1 0 0 0
1 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

17. Вывести таблицу c заливкой по образцу
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1 1
0 0 0 1 1 1 1 1 1
0 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1

18. Вывести таблицу c заливкой по образцу
1 1 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 0 0
0 0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0
1 1 1 1 1 1 1 1 1

19. Вывести таблицу c заливкой по образцу
0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1 1
0 0 0 0 0 1 1 1 1
0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0 1

20. Вывести таблицу c заливкой по образцу

0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 1 1 1 0 0 0
0 0 1 1 1 1 1 0 0
0 1 1 1 1 1 1 1 0

21. Вывести таблицу c заливкой по образцу
1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0

22. Вывести таблицу c заливкой по образцу
0 1 1 1 1 1 1 1 0
0 0 1 1 1 1 1 0 0
0 0 0 1 1 1 0 0 0
0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

23. Вывести таблицу c заливкой по образцу
1 0 0 0 0 0 0 0 1
1 1 0 0 0 0 0 1 1
1 1 1 0 0 0 1 1 1
1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1
1 1 1 0 0 0 1 1 1
1 1 0 0 0 0 0 1 1
1 0 0 0 0 0 0 0 1

24. Вывести таблицу c заливкой по образцу
1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 1
1 0 1 1 1 1 1 0 1
1 0 1 0 0 0 1 0 1
1 0 1 0 1 0 1 0 1
1 0 1 0 0 0 1 0 1
1 0 1 1 1 1 1 0 1
1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1

25. Вывести таблицу c заливкой по образцу
1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 0 1
1 0 0 0 0 0 1 0 1
1 0 1 1 1 0 1 0 1
1 0 1 0 0 0 1 0 1
1 0 1 1 1 1 1 0 1
1 0 0 0 0 0 0 0 1
1 1 1 1 1 1 1 1 1

]]>