Write a program that reads in an array of type int. Provide facility to either read this array from keyboard or from a file, at the user’s option. The output for the file input option should be stored in a file while the output for the keyboard input option should be displayed on the computer screen. If the user chooses file input, the program should request file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be a two column list. The first column is a list of distinct array elements; the second column is the count of the number of occurrences of each element. The list should be sorted on entries in the first column, largest to smallest."

This is the part of it. But it doesnt answered the question 100%. Can someone "genius" help me to complete this. I in urgency..Help...

#include <iostream>
#include <fstream>
using namespace std;
void Keyboard(int *pNum, int *pCount); //case 1
void CountNums(int *pNum, int **pCount, int count);
int FindHighestNum(int *pNum, int count);
int main()
{
    int *pNum = NULL;
    int *pCount = NULL;
    int i = 3;

    while (i != 0)
    {
        cout << "Hi Welcome To the System " << endl;
        cout << "Do you want to input the numbers from a file or from the keyboard? " << endl;
        cout << "1) Keyboard." << endl;
        cout << "2) File." << endl;
        cout << "Enter 1 or 2 or 0 to exit.";
        cin >> i;

        switch (i)
        {
        case 0:
            return 0;
            break;
        case 1:
            Keyboard(pNum, pCount);
            break;
        case 2:
            break;
        default:
            break;
        };
    }
    return 0;
}
void Keyboard(int *pNum, int *pCount)
{
    int count = 0;
    cout << "How many numbers to be put in ? (up to 50)";
    cin >> count;

    if (count > 50)

        count = 50;
    pNum = new int[count];
    cout << "Enter the numbers:" << endl;

    for (int i = 0; i < count; i++)
    {
        cout << i+1 << ": ";
        cin >> pNum[i];
    }
    CountNums(pNum, &pCount, count);
    for (int j = 0; j < (FindHighestNum(pNum, count)+1); j++)
    {
        if (pCount[j] > 0)
            cout << j << ": " << pCount[j] << endl;
    }
}
void CountNums(int *pNum, int **pCount, int count)
{
    (*pCount) = new int[FindHighestNum(pNum, count)+1];
    for (int j = 0; j <= FindHighestNum(pNum, count); j++)
        (*pCount)[j] = 0;
    for (int i = 0; i < count; i++)
        (*pCount)[pNum[i]]++;
}

int FindHighestNum(int *pNum, int count)
{
    int highnum = 0;
    for (int i = 0; i < count; i++)
    {
        if (pNum[i] > highnum)
            highnum = pNum[i];
    }
    return highnum;
}

People here generally ignore threads marked Urgent.

>>Can someone "genius" help me to complete this.
What parts do you have problems implementing?

Am so sorry. Am new here. So not really sure how the proper way to start new thread..

Actually, based on my coding,
1. i dont know how to sort the output from largest to smallest.
2. How to read from file?
3. if i key in the negetive number, i didnt been count..

Can you help me to modify the coding...am blurr.. i can sleep..so stress..now it around 3am at Malaysia.

>>void Keyboard(int *pNum, int *pCount)

You need to pass those pointers by value so that Keyboard() function can change them, like this: void Keyboard(int **pNum, int **pCount) Then from main Keyboard( &pNum, &pCount); Then in Keybord() when you reference pNum you have to use *pNum. Same with pCount.

i got 4 errors..

--------------------Configuration: P1 - Win32 Debug--------------------
Compiling...
array.cpp
D:\PROJECT\P1\array.cpp(74) : error C2440: '=' : cannot convert from 'int *' to 'int ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\PROJECT\P1\array.cpp(80) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'int *' (or there is no acceptable conversion)
D:\PROJECT\P1\array.cpp(85) : error C2664: 'CountNums' : cannot convert parameter 1 from 'int ** ' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
D:\PROJECT\P1\array.cpp(86) : error C2664: 'FindHighestNum' : cannot convert parameter 1 from 'int ** ' to 'int *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.

array.obj - 4 error(s), 0 warning(s)

This article has been dead for over six months. Start a new discussion instead.