Art said:
Here's the code I have.
I get an undefined reference to getInfo, error.
Thanks
Art
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h> //necessary for the _getch function
using namespace std;
I know that I'll be disagreed with, but I dislike using namespace std;
const int SIZE = 15; //size for all arrays in student structure
struct Student
{
char fName[SIZE]; //array for first name
char lName[SIZE]; //array for last name
char attendance[SIZE]; //array for attendance
int days[SIZE]; //array for days
};
I am somewhat confused by what Student is, or more to the point, why
SIZE is the same for fName, lName, attendance and days.
Are you trying to make a struct that has information for SIZE students?
Or is this information for just one student?
If its for one student think about:
const int NameSize = 15;
const int NumberOfDays = 15;
or something. Because I think it's a little confusing for the size of
the first name and last name to be the same symbolically as the size of
attendance and days.
If its for more than one student, then I think you're going to have
trouble storing the names.
Also, your comments are less than helpful. Sorry. Don't mean to be
brusque, but I know those things are arrays. In the case of attendance
and days, I'm not really certain what they're for. And lName and fName
might be clearer as lastName and firstName or something.
getInfo is a function taking an array of Student as an argument and
returning void.
int main()
{
Student studentInfo[30]; //define an array of 30 students
Magic numbers are generally frowned upon.
getInfo(studentInfo);
system("PAUSE");
return 0;
}
void getInfo(Student &s)
{
}
But here, getInfo is a function taking a reference to a Student as an
argument and returning void.
Forget about structs for a while. Too complicated. Just do an array.
Personally, I think it saves time in small test programs to just put the
functions I'm calling before main. But since you specifically want to
think about prototypes...
So here's a simpler example.
#include <iostream>
int sum(const int [], const int);
int main() {
static const int x[] = { 5,7,9,};
const int s = sum(x, sizeof(x)/sizeof(x[0]));
std::cout << s << std::endl;
}
int sum(const int a[], const int n) {
int result = 0;
for(int i=0; i<n; i++) {
result += a
;
}
return result;
}
Now, a struct is easy.
#include <iostream>
struct T {
int t_;
T &operator+=(const T &t) {
t_ += t.t_;
return *this;
}
};
T sum(const T [], const int);
int main() {
static const T x[] = { {5},{7},{9},};
const T s = sum(x, sizeof(x)/sizeof(x[0]));
std::cout << s.t_ << std::endl;
}
T sum(const T a[], const int n) {
T result = {0};
for(int i=0; i<n; i++) {
result += a;
}
return result;
}
Now, I don't want to say that the above code is any good. I don't think
it is. It's just for illustration. Just something to get you started.
HTH
> I've not got any examples in my text and that is
> exactly what i'm trying to find out.
What text are you using?
Did your text cover std::vector<> yet?
LR