Thread: Arrays: mean, largest value, function count,

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    3

    Arrays: mean, largest value, function count,

    Hi everyone, I need a bit of help in this assignment I need to hand in for university. Can anyone help me? here is the problem:-

    "Read a program that will read in a file of integers into an array. Hence, writing your own functions, compute their mean, the largest value, and a function count to count how many times an integer occurs int he data. Output your results to a file aswell as the screen."

    *Apparently these arays must also be read from a text file*

    If anyone has any ideas I will be very greatful for your comments and help.

    I know that something like this should be in it (I wrote most of this down, my lecturer edited it for me), but can anyone by any chance give me the codes to help complete this assignment.

    PHP Code:
    #include <iostream.h>

    void main()

    {

    float myArray[100];
    int lasti;

    for (
    i=0i<=99i=i+1)

    {

    float mean (float A[],int Size)      ***********************

            {

            
    float mean;
            
    float sum 0;
            for (
    int i=0Sizei=i+1);
           
            {
                    
    sum sum A[i];

            } 
    //end loop
           
            
    mean sum/(Size);
            return 
    mean;

            }
    //end loop    +++++++++++++++++

    }  //end loop

    last =i-1;

    for (
    i=0i<=lasti=i+1)

    {

    cout << "X[i]" << " ";

    //end loop

    }//end main 
    A quote my lecturer sent me through his email says;

    "The lines from the **** to the ++++ are a function defintion and should be AFTER the end of the main program. You aonly need to call the mean function in the main program

    e.g. cout << Mean(X,size) "


    THANKS AND KIND REGARDS


    ARYAN

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    mean() is a function, like main. It must be out of the { and } of the main function. Main returns an int. Use std:: before cout. or put "using namespace std;" under the includes. Format your code. iostream.h is outdated, use iostream. It's a weird code, what is the "Size" variable? What's that "X" array?

    Code:
    #include <iostream>
    
    using namespace std;
    
    float mean(float A[], int Size);
    
    int main()
    {
        float myArray[100];
        int last, i;
    
        for (i=0; i < 99; i++) // i = i + 1 is the same as i++
        {
            mean(myArray, i) // what variable is "Size"?
        }
    
        last =i-1;
    
        for (i=0; i <= last; i++)
        {
            cout << X[i] << " "; // don't quote around variables
        } //end loop
    
        return 0;
    }
    
    float mean (float A[], int Size)      // what variable is Size?
    {
        float m;
        float sum = 0;
        for (int i=0; i < Size; i++) // wrong semi-colon,
        {
            sum = sum + A[i];
        }
           
        m = sum/Size;
        return m;
    }
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    the set of arrays ca be any random amount of numbers as longh asd its read from a file, im also not quite sure of the 'Size' variable, could you elaborate what that means a little bit.

    So how would I read a set of arrays from a txt file, and where would i put it?

    Thank you so much

    KIND REGARDS ARYAN

  4. #4
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    You should read some cprogramming.com tutorials

    All about filestreaming, too. You should read the basics again, because you had a lot of syntax errors. Don't you try to compile codes before you post them?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    3
    i had done actually but i thought i would put it in alond with my errors so peple coud help rectify my mistakes.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM