#include <iostream>
void reverse(int *a, const int x, const int y) {
int i = x + 1;
int j = y - 1;
int tmp = 0;
while(i < j) {
tmp = a[i];
a[i] = a[j];
a[j] = tmp;
i++;
j--;
}
}
int main() {
int a[] = {16, 8, 3, 5, 2021, 2016, 1, 500, 15, 8, 7, 1914, 27};
// Here we output the source array
for(auto elt: a) {
std::cout << elt << ' ';
}
// Delimiter for arrays
std::cout << '\n';
reverse(a, 0, 5);
// Here we output the changed array
for(auto elt: a) {
std::cout << elt << ' ';
}
return 0;
}
16 8 3 5 2021 2016 1 500 15 8 7 1914 27
16 2021 5 3 8 2016 1 500 15 8 7 1914 27
#include <cstdlib>
int main() {
std::system("start C:\\Folder\\proga.exe");
return 0;
}
#include <iostream>
#include <vector>
#include <Windows.h>
using namespace std;
class Animal {
string name;
string gender;
int age;
public:
// Default constructor
Animal() {
name = "";
gender = "";
age = 0;
}
// Constructor which can be called when creating an object
Animal(string n, string g, int a) {
name = n;
gender = g;
age = a;
}
void set(string n, string g, int a) {
name = n;
gender = g;
age = a;
}
void const print() {
cout << "Животное: " << name << endl << "Пол: " << gender << endl << "Возраст: " << age << endl;
}
};
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
/* Creating a vector container and adding an object by calling the constructor of the Animal class and calling the container-vector method */
vector <Animal> animals;
animals.push_back(Animal("dog", "male", 3));
// Creating an object and calling the set method
Animal cat;
cat.set("cat", "male", 1);
animals.push_back(cat);
// Content of vector
for(auto animal: animals) {
animal.print();
cout << "" << endl;
}
return 0;
}
#include <iostream>
#include <vector>
#include <Windows.h>
using namespace std;
class Animal {
string name;
string gender;
int age;
public:
// Default constructor
Animal() {
name = "";
gender = "";
age = 0;
}
void set(string n, string g, int a) {
name = n;
gender = g;
age = a;
}
void const print() {
cout << "Животное: " << name << endl << "Пол: " << gender << endl << "Возраст: " << age << endl;
}
};
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
vector <Animal> animals(3);
animals[0].set("dog", "male", 3);
animals[1].set("cat", "male", 1);
animals[2].set("pig", "female", 5);
// Content of vector
for(auto animal: animals) {
animal.print();
cout << "" << endl;
}
return 0;
}
void getValues(Properties* objectValues);
.Properties obj;
Properties* objectValues = new Properties;
objectValues->getValues(&obj);
#include <iostream>
class Properties
{
public:
void getValues();
int a = 13;
int b = 82;
float c = 27.01f;
};
void Properties::getValues()
{
std::cout << a << std::endl;
}
int main()
{
setlocale(0, "");
Properties* ptr = new Properties;
ptr->getValues();
std::cin.get();
return 0;
}
#include <iostream>
class Properties
{
public:
void getValues();
int a = 13;
int b = 82;
float c = 27.01f;
};
void Properties::getValues()
{
std::cout << a << std::endl;
}
int main()
{
setlocale(0, "");
Properties obj;
obj.getValues();
std::cin.get();
return 0;
}
std::string
using namespace std::string
#include <iostream>
#include <fstream>
int main() {
// переменные, отвечающие за посимвольный перебор
char sim1, sim2, n;
// abbreviation: not identical
bool ni = false;
// открытие двух материнских файлов для чтения
std::ifstream txt1("txt1.txt");
std::ifstream txt2("txt2.txt");
// открытие файла для записи
std::ofstream txt3("txt3.txt");
if (!txt1.is_open() || !txt2.is_open()) {
std::cout << "I can't open a file for reading" << std::endl;
return 1;
}
if(!txt3.is_open()) {
std::cout << "I can't open a file for writing" << std::endl;
return 1;
}
std::cout << "txt1 and txt2 files are open" << std::endl;
// посимвольное сравниваем два файла
while(!txt1.eof() && !txt2.eof()) {
txt1.get(sim1);
txt2.get(sim2);
if(sim1 == sim2) {
txt3.put(sim1);
} else {
ni = true;
}
}
if(!ni && txt1.eof() && txt2.eof()) {
// сообщение о успехе
std::cout << "The file contents are identical" << std::endl;
} else {
// Если посимвольное сравнение не увенчалось успехом
std::cout << "The contents of the files are not identical" << std::endl;
}
// закрываем файлы
txt1.close();
txt2.close();
txt3.close();
std::cout << "End of program" << std::endl;
return 0;
}
int counter;
Инициализируйте её: int counter = 0;
.#include <iostream>
#include <string>
#include <vector>
void change_status(int i, std::vector<bool>& people) {
if (i > people.size()) {
people.resize(i + 1);
}
if (i > 0) {
people[i] = true;
}
}
void come(int k, std::vector<bool>& people) {
people.resize(people.size() + k + 1);
}
void worry_count(const std::vector<std::string>& commands, const std::vector<int>& values, std::vector<bool>& people) {
int counter = 0;
for (bool person : people) {
if (person) {
++counter;
}
}
std::cout << counter << std::endl;
}
int main(void) {
std::vector<std::string> commands = {"COME", "WORRY", "WORRY", "COME", "WORRY_COUNT", "COME", "WORRY", "WORRY_COUNT"};
std::vector<int> values = {5, 1, 4, -2, 0, 3, 3, 0};
std::vector<bool> people; // true - беспокоящийся человек, false - спокойный
int i = 0;
for (std::string command : commands) {
if (command == "WORRY" || command == "QUIET") {
change_status(i, people);
} else if (command == "COME") {
come(i, people);
} else {
worry_count(commands, values, people);
}
++i;
}
return 0;
}
#include <stdio.h>
#include "header.h"
int main(int argc, char* argv[]) {
htype_t htval;
htval.num = 10;
printf("%i\n", htval.num);
}
#include <iostream>
#include <vector>
int main() {
std::vector<int> arr;
int n;
std::cout << "Enter numbers: ";
while(std::cin >> n)
arr.push_back(n);
for (int starti = 0, mini, len = arr.size(); starti < len-1; starti++) {
// тут мы принимаем начальное значение за минимальное//
mini = starti;
// тут мы ищем //
for (int currentIndex = starti+1; currentIndex < len; currentIndex++) {
if (arr[currentIndex] < arr[mini])
mini = currentIndex;
}
std::swap(arr[starti], arr[mini]);
}
for (int i = 0, len = arr.size(); i < len; i=i+1)
std::cout << arr[i] << ' ';
return 0;
}
string WritingToFile, path = "file.txt";
ofstream out(path , ios::app);
if(out.is_open()) {
cout << "Write whatever you want\n";
while (WritingToFile != "exit") {
SetConsoleCP(1251);
getline(cin, WritingToFile);
if(WritingToFile != "exit")
out << WritingToFile << endl;
SetConsoleCP(866);
}
}
out.close();