Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in a list of integers into and array with base type i

ID: 3644438 • Letter: W

Question

Write a program that reads in a list of integers into and array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array.


#include <iostream>
using namespace std;


void fill_array(int a[], int size, int number_used);
void sort(int a[],int number_used);
void swap_values(int& v1, int& v2);
int index_of_smallest(const int a[], int start_index,
int number_used);
void countOccurences(const int a[], int number_used);

int main( )
{
using namespace std;
int sample_array[10], number_used;
cout<<"Enter size of array:";
cin>>number_used;
fill_array(sample_array, 10, number_used);
sort(sample_array, number_used);
countOccurences (sample_array, number_used);

system("pause");
return 0;
}

void fill_array (int a[], int size, int number_used)
{
using namespace std;
cout<<" Enter up elements";

int next, index=0;
while ( (index< number_used))
{
cin >> next;
a[index] = next;
index++;
}
}

void sort(int a [], int number_used)
{
int index_of_next_smallest;
for (int index = 0; index < number_used - 1; index++)
{
index_of_next_smallest =
index_of_smallest (a, index, number_used);
swap_values(a[index], a[index_of_next_smallest]);
}
}

void swap_values(int& v1, int& v2)
{
int temp;
temp = v1;
v1= v2;
v2= temp;
}

int index_of_smallest (const int a[], int start_index, int
number_used)
{
int min = a[start_index],
index_of_min = start_index;
for (int index = start_index + 1;
index <number_used; index++)
if (a[index] > min)
{
min = a[index];
index_of_min = index;
}

return index_of_min;
}
void countOccurences (const int a[], int number_used)
{
cout<<"N Count"<<endl;
int x=0;
for(int i=0; i,number_used; i++)
{int count;
if(i==0)
count=0;
else
count=1;
while (a[x]==a[i])
{
count++;
i++;
}
cout<<a[x]<<" "<<count<<endl;
x=i;
}
}

Not sure why I keep getting errors.

Explanation / Answer

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int[] score = new int[100]; string inValue; int scoreCnt = 0; int total = 0; Console.Write(" Enter score {0}: " + "((-99 to exit)) ", scoreCnt + 1); inValue = Console.ReadLine(); while (inValue != "-99") { score[scoreCnt] = Convert.ToInt32(inValue); ++scoreCnt; Console.Write("Enter Score {0}: " + "(( -99 to exit)) ", scoreCnt + 1); inValue = Console.ReadLine(); } foreach (int val in score) { total += val; } double count; { if (inValue > 0) ++count; Console.WriteLine("There are {0}" + count + "number 1's.", count); } Console.WriteLine(" The number of scores: " + scoreCnt); Console.WriteLine(" The addition of the scores are: " + total); } This is the error I am getting: Error 1 Operator '>' cannot be applied to operands of type 'string' and 'int' I want to print the array out and then I want to print the number of times each number was entered.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote