
C/C++
Срочно, помогите с C++

#include <iostream>
#include <iomanip>
using namespace std;
void fill(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Input " << n << " elements: ";
while (begin != end) {
cin >> *begin;
++begin;
}
}
void show(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Elements: ";
while (begin != end) {
cout << *begin << ' ';
++begin;
}
puts("");
}
void squeeze(int* box, size_t& n) {
auto begin = box + 2;
const auto end = box + n;
auto m = n >> 1;
if (n & 1) ++m;
auto next = box + 1;
while (begin < end) {
*next = *begin;
++next;
begin += 2;
}
n = m;
}
void addresses(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Addresses: ";
while (begin != end) {
if (!*begin) cout << setw(8) << setfill('0') << begin << ' ';
++begin;
}
puts("");
}
void replace(int* box, size_t& n, int x) {
auto begin = box;
const auto end = box + n;
while (begin != end) {
*begin = x;
++begin;
}
}
int main() {
cout << "Input n: ";
size_t n;
cin >> n;
auto m = new int[n];
fill(m, n);
show(m, n);
squeeze(m, n);
show(m, n);
replace(m, n, 0);
show(m, n);
cout << "Input k: ";
size_t k;
cin >> k;
addresses(m, k);
delete[] m;
system("pause > nul");
}
#include <iomanip>
using namespace std;
void fill(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Input " << n << " elements: ";
while (begin != end) {
cin >> *begin;
++begin;
}
}
void show(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Elements: ";
while (begin != end) {
cout << *begin << ' ';
++begin;
}
puts("");
}
void squeeze(int* box, size_t& n) {
auto begin = box + 2;
const auto end = box + n;
auto m = n >> 1;
if (n & 1) ++m;
auto next = box + 1;
while (begin < end) {
*next = *begin;
++next;
begin += 2;
}
n = m;
}
void addresses(int* box, const size_t n) {
auto begin = box;
const auto end = box + n;
cout << "Addresses: ";
while (begin != end) {
if (!*begin) cout << setw(8) << setfill('0') << begin << ' ';
++begin;
}
puts("");
}
void replace(int* box, size_t& n, int x) {
auto begin = box;
const auto end = box + n;
while (begin != end) {
*begin = x;
++begin;
}
}
int main() {
cout << "Input n: ";
size_t n;
cin >> n;
auto m = new int[n];
fill(m, n);
show(m, n);
squeeze(m, n);
show(m, n);
replace(m, n, 0);
show(m, n);
cout << "Input k: ";
size_t k;
cin >> k;
addresses(m, k);
delete[] m;
system("pause > nul");
}
Сико Бико
А можно как-то реализовать все это в 1 функции? Мы просто функции не проходили, поэтому я не могу ничего понять (
Похожие вопросы
- СРОЧНО! Помогите решить 2 задачи C++
- Помогите в C/C++. Пример в столбик
- Помогите пожалуйста C++.
- Срочно!!! Помогите пожалуйста написать код к задачке на с++! Заранее спасибо!
- Пожалуйста, помогите с C++
- Помогите в C++ Включить CPP файл по условию
- Помогите мне! C++ (текст, текст)
- Помогите с c++ пожалуйста
- СРОЧНО! Помогите с задачей.
- Помогите по c++.