C/C++
Помогите написать на с++
Класс принимает два одномерных массива. Добавить функцию, подсчитывающую количество совпадающих элементов с одинаковыми индексами
#include <iostream>
using namespace std;
template<typename Type>
struct CompareArrays {
static size_t equal_position(const Type* a, const Type* b, const size_t n) {
auto m = 0U;
for (auto i = 0U; i < n; ++i) if (a[i] == b[i]) ++m;
return m;
}
};
template<typename Type>
void print_array(const Type* box, const size_t n) {
for (auto i = 0U; i < n; ++i) cout << box[i] << ' ';
puts("");
}
int main() {
const auto n = 10U;
int a[n] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
print_array(a, n);
int b[n] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 };
print_array(b, n);
auto m = CompareArrays<int>::equal_position(a, b, n);
cout << "Matches: " << m << '\n';
system("pause > nul");
}
using namespace std;
template<typename Type>
struct CompareArrays {
static size_t equal_position(const Type* a, const Type* b, const size_t n) {
auto m = 0U;
for (auto i = 0U; i < n; ++i) if (a[i] == b[i]) ++m;
return m;
}
};
template<typename Type>
void print_array(const Type* box, const size_t n) {
for (auto i = 0U; i < n; ++i) cout << box[i] << ' ';
puts("");
}
int main() {
const auto n = 10U;
int a[n] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
print_array(a, n);
int b[n] = { 2, 2, 4, 4, 6, 6, 8, 8, 0, 0 };
print_array(b, n);
auto m = CompareArrays<int>::equal_position(a, b, n);
cout << "Matches: " << m << '\n';
system("pause > nul");
}
#include
#include
#include
#include
#include
using namespace std;
class SearchElement
{
public:
int cnt;
SearchElement(int *arr1, int *arr2, int nn)
{
cnt=0;
for (int a=0; a<nn; a++)
{
if (arr1[a]==arr2[a]) cnt++;
}
}
///////////////
void OutCnt()
{
cout<<"Количество совпадающих элементов с одинаковыми индексами= "<< cnt<<" штук"<<endl;
}
};
void RusText(void);
int main()
{
RusText();
const int N=5;
int FirstArr[N]={10,2,3,20,20};
int SecArr[N]={10,4,3,20,1};
SearchElement SE(FirstArr, SecArr, N);
SE.OutCnt();
cout<<endl;
system("pause");
return 0;
}
////////// Руссификация сообщений //////////////////////////////////
void RusText(void)
{
setlocale(LC_ALL, "rus");
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
SetConsoleTitle(TEXT("ОтветыМейлРу")); //Для совместимости с VS
return;
}
#include
#include
#include
#include
using namespace std;
class SearchElement
{
public:
int cnt;
SearchElement(int *arr1, int *arr2, int nn)
{
cnt=0;
for (int a=0; a<nn; a++)
{
if (arr1[a]==arr2[a]) cnt++;
}
}
///////////////
void OutCnt()
{
cout<<"Количество совпадающих элементов с одинаковыми индексами= "<< cnt<<" штук"<<endl;
}
};
void RusText(void);
int main()
{
RusText();
const int N=5;
int FirstArr[N]={10,2,3,20,20};
int SecArr[N]={10,4,3,20,1};
SearchElement SE(FirstArr, SecArr, N);
SE.OutCnt();
cout<<endl;
system("pause");
return 0;
}
////////// Руссификация сообщений //////////////////////////////////
void RusText(void)
{
setlocale(LC_ALL, "rus");
SetConsoleOutputCP(1251);
SetConsoleCP(1251);
SetConsoleTitle(TEXT("ОтветыМейлРу")); //Для совместимости с VS
return;
}
Похожие вопросы
- Помогите написать программу на С
- Помогите написать программу на C++
- Помогите написать программу на с++
- Помоги написать лабу по программированию на c++
- Помогите написать программу на с++
- Помогите написать программу
- С++. Структуры(struct). Помогите написать программу
- Помогите написать программу на С++
- Программирование , помогите написать контрольную
- Язык Си.помогите написать формулу пожалуйста