C++ Tasks

Hello, I started learning C++ about a week ago and I got two tasks that I cannot do. I see them really hard, and I was hoping someone would show me how they must be done.
Task 1:
To write functions:
• entering values ​​of elements of the one-dimensional array of integers;
• print the values ​​of the elements of the one-dimensional array of integers;
• finding the average of the elements (of one-dimensional array of integers), which are divided into 5;
• finding the smallest positive number in a one-dimensional array;
• remove items ending in 7 among an array of integers. Function returns as adjusted array and the number of its elements.
Using these functions to solve the following problem:
Given are n number of integers (n <1000). To create a new array containing all elements of the given numbers that do not end in 7. about new array to find and print the average of its elements that are divisible by 5, and his youngest positive element. To print and values ​​on newly array.
Eg. when n = 10 and an array of elements: 5, 20, 17, 107, 45, 2, 16, 37, -50, 97

The program must create a new array with 6 elements: 5, 20, 45, 2, 16, -50, which to print and print more:
    5 - average of the elements of the second array, which are divided into 5;
    2 - the smallest positive number in the second array.

Task 2:
To write functions:
• entering values ​​of elements of the one-dimensional array of integers;
• print the values ​​of the elements of the one-dimensional array of integers;
• finding the average of the elements (of one-dimensional array of integers), whose record has at least one of the numbers 1 and 5;
• Finding the largest negative number in a one-dimensional array and its index. If the numbers are more than one, to return the indices of all;
• remove items multiples of 5 among an array of integers. Function returns as adjusted array and the number of its elements.
Using these functions to solve the following problem:
Given are n number of integers (n <1000). To create a new array containing all elements of the given numbers that do not divide by 5. about new array to find and print the average of its elements, which has one of the numbers 1 or 5, and his greatest negative element (or elements), including print and indexes them. To print and values ​​on newly array.
Eg. when n = 10 and an array of elements: 5, 20, -17, 108, 45, 2, -16, 37, -50, 97

The program must create a new array with 6 elements: -17, 108, 2, -16, 37, 97, to print them and to print more:
    25 - arithmetic mean of the elements of the second array, in which there is one of the numbers 1 or 5;
    -16 - The largest negative number in the second array and has index 3
I've read it , but I can't figure out what to use where and how to arrange them, so if you could atleast show me how to start i would be greatful :)
#include <iostream>
#include <climits>
using namespace std;

//vavezhdane na stojnosti na elementi na ednomeren masif ot celi chisla
void vasto(int* masif, int length)
{
int i;
for (i = 0; i < length; i++)
{
cout << "vavedete i[" << i << "] = ";
cin >> masif[i];
}
}

//otpechatvane na stojnosti na elementi na ednomeren masif ot celi chisla
void otpe(int* masif, int length)
{
int i;
cout << endl << endl;
for (i = 0; i < length; i++)
{
cout << "i[" << i << "] = " << masif[i] << "\n";
}
cout << endl;
}

//namirane na sar na elementite, koito se delat na 5
double sar(int* masif, int length, bool* flag)
{
int i;
int count5 = 0;
int sum = 0;
double answer;
*flag = false;
for (i = 0; i < length; i++)
{
if (masif[i] % 5 == 0)
{
sum = sum + masif[i];
count5++;
*flag = true;
}
}
if (*flag == false) return 0;
answer = (double)sum / (double)count5;
return answer;
}

//nai malko polozhitelno chislo (nulata e polozhitelno chislo) f ednomeren masif

int napochi(int* masif, int length)
{
int i;
int x = INT_MAX;
bool flag = false;
for (i = 0; i < length; i++)
{
if (masif[i] < 0) continue;
if (masif[i] < x) x = masif[i];
flag = true;
}
if (flag == false) return -1;
return x;
}

// premahvane na edin element
int rase(int* masif, int index, int length)
{
int i;
for (i = index; i < length - 1; i++)
{
masif[i] = masif[i + 1];
}
return (length - 1);
}

// premahvane na sichko shto zavarshva na 7
int ma7(int* masif, int length)
{
int i;
for (i = 0; i < length; i++)
{
if ((masif[i] % 10 == 7) || (masif[i] % 10 == -7))
{
length = rase(masif, i, length);
i--;
}
}
return length;
}


int main()
{
bool flag;
int length;
int masif[1000];
double sredno5;
int napole;
cout << "length = ";
cin >> length;
vasto(masif, length);
length = ma7(masif, length);
sredno5 = sar(masif, length, &flag);
if (flag == true)
{
cout << "\n\nsredno aritmetichno na elementite de se delat na 5 -> " << sredno5;
}
else cout << "\n\nsredno aritmetichno na elementite de se delat na 5 -> " << "nema takivi !!!";
napole = napochi(masif, length);
if (napole >= 0) cout << "\n\nnai malak polozhitelen element -> " << napole;
else cout << "\n\nmasifat niama polozhitelni elementi";
cout << endl << "\n\nskivai sa novopoluchenia masif !!!";
otpe(masif, length);
return 0;
}
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
using namespace std;

//vavezhdane na stojnosti na elementi na ednomeren masif ot celi chisla
void vasto(int* masif, int length)
{
int i;
for (i = 0; i < length; i++)
{
cout << "vavedete i[" << i << "] = ";
cin >> masif[i];
}
}

//otpechatvane na stojnosti na elementi na ednomeren masif ot celi chisla
void otpe(int* masif, int length)
{
int i;
cout << endl << endl;
for (i = 0; i < length; i++)
{
cout << "i[" << i << "] = " << masif[i] << "\n";
}
cout << endl;
}

//namirane na sar na elementite, koito imat cifra 5 ili 1
double sar(int* masif, int length, bool* flag)
{
char buffer[32];
int i;
int count5 = 0;
int sum = 0;
double answer;
*flag = false;
for (i = 0; i < length; i++)
{
sprintf(buffer, "%d", masif[i]);
if (strchr(buffer, '1') || strchr(buffer, '5'))
{
sum = sum + masif[i];
count5++;
*flag = true;
}
}
if (*flag == false) return 0;
answer = (double)sum / (double)count5;
return answer;
}

//nai goliamo otricatelno chislo f ednomeren masif

int napochi(int* masif, int* index, int length)
{
int i;
int x = INT_MIN;
bool flag = false;
for (i = 0; i < length; i++)
{
if (masif[i] >= 0) continue;
if (masif[i] > x) x = masif[i];
*index = i;
flag = true;
}
if (flag == false) return 0;
return x;
}

// premahvane na edin element
int rase(int* masif, int index, int length)
{
int i;
for (i = index; i < length - 1; i++)
{
masif[i] = masif[i + 1];
}
return (length - 1);
}

// premahvane na kratni na 5
int ma7(int* masif, int length)
{
int i;
for (i = 0; i < length; i++)
{
if (masif[i] % 5 == 0)
{
length = rase(masif, i, length);
i--;
}
}
return length;
}


int main()
{
int index;
bool flag;
int length;
int masif[1000];
double sredno5;
int napole;
cout << "length = ";
cin >> length;
vasto(masif, length);
length = ma7(masif, length);
sredno5 = sar(masif, length, &flag);
if (flag == true)
{
cout << "\n\nsredno aritmetichno na elementite de imat cifra 1 ili 5 -> " << sredno5;
}
else cout << "\n\nsredno aritmetichno na elementite de imat cifra 1 ili 5 -> " << "nema takivi !!!";
napole = napochi(masif, &index, length);
if (napole < 0) cout << "\n\nnai goliam otricatelen element -> " << napole << " sas index -> " << index;
else cout << "\n\nmasifat niama otricatelni elementi";
cout << endl << "\n\nskivai sa novopoluchenia masif !!!";
otpe(masif, length);
return 0;
}
Can someone check the programs , If you can fix them , because I was told i have mistakes .
Or atleast explain where the mistake is , and why
What is it doing that you don't expect it to? What isn't it doing that you expect it to?
Topic archived. No new replies allowed.