GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 03-Sep-2008, 05:01
glacier glacier is offline
New Member
 
Join Date: Sep 2006
Posts: 19
glacier is an unknown quantity at this point

Understanding passing function through arrays


Hi there,
I am very Confuse in C++program I took introduction C++ programming 4 years ago so now I forgot everything which I learnet on that time.My question is that.
I have to write a program in C++ to use a function by entering upto 10 floating point values and these values should be stored in arrays, and the values should be displayed the user with identifying text: sum of all values,average values I/p, largest values i/p,smallest value I/p.

we need to write 2 function getData and processData where get get data recieve 3 parameter list, maximum number, and actual number of values. and processData two parameter-list and current number and do all thing sumand avg, large and small.

so that was the program description now my question is that here first of all what is list and I tried to write few lines of codes which are here

CPP / C++ / C Code:
# include< iostream>
using namespace std;

void getData (const int [], int, int);
void processData (const int [], int);

int main()
{
const int a[arraySize];
int value;

cout<<"enter the floating point value"<< a[arraySize]<<value;
getData( const a[arraySize]);
getData(int value);

return 0;
}

void getData (const int [], int, int)
{
for( int value= 0; value< a[arraySize]; value++)

}
Last edited by LuciWiz : 03-Sep-2008 at 07:16. Reason: Please insert your C++ code between [cpp] & [/cpp] tags
  #2  
Old 03-Sep-2008, 11:09
Mexican Bob's Avatar
Mexican Bob Mexican Bob is offline
Member
 
Join Date: Mar 2008
Location: Chicxulub, Yucatán
Posts: 226
Mexican Bob is a jewel in the roughMexican Bob is a jewel in the roughMexican Bob is a jewel in the rough

Re: need help in understanding passing function through arrays


You need to work with "float" data type and not "int" data type.

CPP / C++ / C Code:
#include <iostream>

using namespace std;

int main()
{
    cout << "Enter a floating point number: ";
    float f;
    cin >> f;
    cout << "You entered: " << f << endl;

    return 0;
}


Output:

Code:
$ ./getfloat Enter a floating point number: 23.10389 You entered: 23.1039

...there is no benefit to using an "int" array.


Mexican Bob
  #3  
Old 03-Sep-2008, 22:33
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: need help in understanding passing function through arrays


Quote:
my question is that here first of all what is list
A list is just what it says: a list!
A list is a group of data of the same type which are stored in some sequential
fashion so that they can be accessed and manipulted.

A simple example would be an array as in this random list of chars:
CPP / C++ / C Code:
char charray[10]= { h, f, c, k, e, b, g, a, i, d, j };
An IMPORTANT thing to note here is that the identifier 'charray' is a pointer
to a contiguous block of 10 chars in memory.

A more advanced example might be an array of arrays or 'list of lists' ...like this 'list' of 3 words:
CPP / C++ / C Code:
char charray[3][10]= {
  {  a,  p,  p,  l,  e, \0, \0, \0, \0, \0 }
  {  o,  r,  a,  n,  g,  e, \0, \0, \0, \0 }
  {  p,  e,  a,  r, \0, \0, \0, \0, \0, \0 }
};
In this example the identifier 'charray' is a pointer to a 3 pointers which
each point to a block of 10 chars. This too is stored in a contiguous block of memory.

You can have a 'list' of any data type: int, float, even structures or classes. A list does not have to be an stored in an array. A 'list' can be allocated as the program runs and so would be stored at non-contiguous memory and so other means used to determine where the members are located (which is for later study).

From what I can understand from your description above, your 'list' is to be:
Quote:
up to 10 floating point values and these values should be stored in arrays
What is not said is how many arrays...
But like above here are 3 arrays of 10 each except they are in type float:
CPP / C++ / C Code:
float float-array[3][10]= { 
  { 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9 }
  { 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.0 }
  { 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 1.0, 1.1 }
};
You could make that 10 arrays or 1000 arrays,,, the principles are the same.
What you will need to learn to do is pass a pointer to the array (or array member) to the functions along with the sizes of the array.
Are you with us so far? Do you understand pointers?
Practice by passing a c string (array of type char) to a function and printing it from the function.
Last edited by Howard_L : 03-Sep-2008 at 23:21.
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
run script command on ns2.26 newbie06 Computer Software Forum - Linux 65 19-Aug-2009 08:50
Flex and bison coding lucky88star C++ Forum 5 24-Dec-2007 12:57
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Arrays as function arguments - return arrays from functions pisuke C Programming Language 2 25-Jul-2007 12:03
need help with passing 3 arrays into a function tommy69 C Programming Language 14 07-Apr-2004 01:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:25.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.