Help please!

Need help starting the getDATA function please!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <iostream>
#include<fstream>
#include<cmath>
#include<iomanip>
using namespace std ;

/*
 Some global constants.  With this set up, to make the program work
 with a different array size or filename, all we have to do is change
 the value of the constant in the declaration below, and recompile --
 no need to search through the rest of the program to change anything
 there.
 */

const int sizeLimit = 100 ;
const char fileName[ ] = "numbers.txt" ;

void getData (int data[ ], const char fname[ ],
              int arraySize, int & numSlotsUsed);
void showData (int data[ ], int numSlotsUsed) ;
double average (int data[ ], int numSlotsUsed ) ;
double stndrdDev (double average, int data[ ], int numSlotsUsed ) ;
void findMin (int data[ ], int & minValue, int & minPos, int numSlotsUsed ) ;
void findMax (int data[ ], int & maxValue, int & maxPos, int numSlotsUsed ) ;
void showResults (int min, int minIndex, int max, int maxIndex,
                  double average, double stdDev) ;

int main (void)
{
    int theData[sizeLimit], dataSize, min, max, minIndex, maxIndex ;
    double theAve, theStdDev ;
    
    getData(theData, fileName, sizeLimit, dataSize) ;
    showData (theData, dataSize) ;
    findMin (theData, min, minIndex, dataSize) ;
    findMax (theData, max, maxIndex, dataSize) ;
    theAve = average(theData, dataSize) ;
    theStdDev = stndrdDev(theAve, theData, dataSize) ;
    showResults (min, minIndex, max, maxIndex,theAve, theStdDev) ;
    
    return 0;
}
/* ******************************************** */
/*                     GETDATA                  */
/* ******************************************** */
/*
 The purpose of function getData is to
 + read from the input file whose name is stored in: fname,
 + read the first number in the file to determine how many
 data items are in the rest of the file,
 + copy the data items in the file into the array called: data, and
 + set the parameter numSlotsUsed equal to the number of
 items copied into the array.
 
 (Function getData copies the first data item in the file, if one
 exists, into data[0], copies the second data item into data[1], and so
 on.)
 
 Function getData handles the following exceptional situations:
 + input file cannot be opened,
 + input file has no data items, and
 + input file contains more data items than the value of arraySize.
 
 In those situations, function getData prints an error message and
 terminates execution of the program (It calls the exit() function.).
 */
void getData (int data[ ], const char fname[ ],
              int arraySize, int & numSlotsUsed)
{
    
    
    
    
    
}
Hi @unik,

This is a
simple example.


Eyenrique-MacBook-Pro:Desktop Eyenrique$ ./getData 
Enter name: Alex Ferguson                
Enter his/her number: 10
Enter name: David Moyes
Enter his/her number: -1
Enter name: Jose Mourinho
Enter his/her number: 10

Name              Number
Alex Ferguson        10
David Moyes          -1
Jose Mourinho        10


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//getData.cpp
//##

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::getline;
using std::string;

#include <iomanip>
using std::setw;

void getData(string names[],int numbers[],int const SIZE_ARRAY);
void print_info(string names[],int numbers[],int const SIZE_ARRAY);

int main(){

int const SIZE=3;
string names[SIZE];
int numbers[SIZE];

getData(names,numbers,SIZE);
print_info(names,numbers,SIZE);

return 0; //indicates success
}//end maina

void getData(string names[],int numbers[],const int SIZE_ARRAY){
        for(int i=0;i<SIZE_ARRAY;i++){
                cout<<"Enter name: ";
                getline(cin,names[i]);
                cout<<"Enter his/her number: ";
                cin>>numbers[i];
                cin.clear();
                cin.ignore(1000,'\n');
        }//end for 
}//end function getData

void print_info(string names[],int numbers[],int const SIZE_ARRAY){
        int space1=20;
        int space2=23;  
        cout<<"\nName"<<setw(space1)<<"Number"<<endl;
        for(int i=0;i<SIZE_ARRAY;i++){
                cout<<names[i]<<setw(space2-names[i].size())<<numbers[i]<<endl; 
        }//end for 
}//end function print_info 
Topic archived. No new replies allowed.