I was asked to do this assignment by my teacher. However i was absent for 3 days so i missed his lecture, would you help me just to get started with this program. Thank you for your help.
The primary purpose of this program is exercising your knowledge of complex function calls and
nested looping statements. You are to read in a series of numbers into an array of fixed length not to
exceed 100 numbers. Your program will stop accepting input when a negative number is input. Once
the negative number is input, your program will sort the numbers using a unique sorting algorithm
called the Hamming Sort and output the sorted array and the average (mean).
Programming Specifications:
Your program will prompt the user to enter in from 2 to 100 positive integers.
Input will be stopped when a negative number is entered.
Your program will store the numbers in an array and sort them using the Hamming Sort
algorithm.
You must not use Global Variables and pass values as parameters.
The output will include the array sorted in ascending order with the average printed out at the
end.
If you start doing something, we will tell you what's wrong with it. But if you show no work no one will help you. People want to see at least some effort man. You can do it!
#include <iostream>
usingnamespace std;
void hamming_sort(int* numbers, int size)
{
//your hamming sorting algorithm here
}
int get_input(int* numbers)
{
int size = 0; //counts numbers entered
//while correct data are entered and numbers entered are less than or equal to 100
// ++numbers means go to the next element in an array
for (int num; cin >> num && size <= 100 ; ++size, ++numbers)
{
if (num < 0) break; //exit loop if negative number is entered
numbers[size] = num; //else write number you got into the array
}
return size; //return number of integers entered
}
int main()
{
int number_array[100]; //create build in array for 100 integers
//build in array implicitly converts to pointer to its 1st element
int size = get_input(number_array);
//sort array
hamming_sort(number_array, size);
//print out array
//calculate the mean and print it out
//and the most important part :D
return 0;
}
/* Your program will prompt the user to enter in from 2 to 100 positive integers.
Input will be stopped when a negative number is entered.
Your program will store the numbers in an array and sort them using the Hamming Sort
algorithm.
You must not use Global Variables and pass values as parameters.
The output will include the array sorted in ascending order with the average printed out at the
end.*/
#include <iostream>
usingnamespace std;
void hamming_sort(int* numbers, int size)
{
//your hamming sorting algorithm here
}
int get_input(int* numbers)
{
int size = 0; //counts numbers entered
cout << "Enter numbers : ";
//while correct data are entered and numbers entered are less than 100 (0 ... 99)
for (int num; cin >> num && size < 100 ; ++size)
{
if (num < 0) break; //exit loop if negative number is entered
numbers[size] = num; //else write number you got into the array
}
return size; //return number of integers entered
}
void print_array(int* numbers, int size)
{
cout << "{ ";
for (int i = 0; i < size; ++i)
{
cout << numbers[i];
if (i + 1 < size) cout << ", ";
}
cout << " }\n";
}
int main()
{
int number_array[100]; //create build in array for 100 integers
//build in array implicitly converts to pointer to its 1st element
int size = get_input(number_array);
//sort array
hamming_sort(number_array, size);
//print out array
print_array(number_array, size);
//calculate the mean
//and the most important part :D
return 0;
}