Struct and nested structs

I'm having trouble how to figure out this problem I'm assigned. When I'm referencing the code I keep getting a message saying "no matching function for call to 'getStudentInfo'.

//Here's what I'm supposed to do

Objectives:
 Structured Data: struct, array of struct, and nested struct
Assignment: Write a C++ program to record and display a list of student records.
1. Define a structure to hold the following information of a Student:
 char name[NAME_SIZE];
 char id[ID_SIZE];
 int years;
 double gpa;
 Course courses[COURSE_SIZE];
2. Define a structure to hold the following information for a Course
 char cName[CNAME_SIZE];
 int cNum;
 char days[DAYS];
 char instructor[NAME_SIZE];
3. Define a array variable students to hold students’ records
4. getStudentInfo(Student [ ], int&) This function asks user to input data for student name, id, years, gpa,
and the courses he/she is taking this semester.
5. getCourses(Course [ ], int &) This function is called by getStudentInfo to get the information of the
courses for a student.
6. displayStudents(Student [ ], int) This function displays the students information
Sample output:
Student Name: John Smith
Student ID: 000123456
Year in school: 2
GPA: 4.0
Course Name: CSI
Course Number: 1470
Schedule: MWF
Instructor: Wei
More courses? y
Course Name: DataStructure
Course Number: 2320
Schedule: TH
Instructor: Jim
More courses? n
More students? y
Student Name: Peter Pan
Student ID: 000234567
Year in school: 10
GPA: 1.0
Course Name: HowToFly
Course Number: 1000
Schedule: MTWHFS
Instructor: Captain Hook
More courses? n
More students? n
Here shows the students’ records:
******************
Student Name: John Smith
Student ID: 000123456
Year in school: 2
GPA: 4.0
Courses:
Name:CS1
Number: 1470
Schedule: MWF
Instructor: Wei
Name: DataStructure
Number: 2320
Schedule: TH
Instructor: Jim
*****************
Student:
Name: Peter Pan
......
......

// And here's my current code


#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int NAME_SIZE = 50;
const int ID_SIZE = 10;
const int COURSE_SIZE = 10;
const int CNAME_SIZE = 50;
const int DAYS = 5;

struct Course{
char cName[CNAME_SIZE];
int cNum;
char days[DAYS];
char instructor[NAME_SIZE];
};

struct Student{
char name[NAME_SIZE];
char id[ID_SIZE];
int years;
double gpa;
Course courses[COURSE_SIZE];
};

Student getStudentInfo(Student [ ], int&);
void getCourses(Course [ ], int &);
void displayStudents(Student [ ], int);

int main()
{
const int NUM_STUDENTS = 12;

//Decalring a new array
Student *students = new Student[NUM_STUDENTS];
getStudentInfo(students[NUM_STUDENTS], &NUM_STUDENTS)
return 0;
}

Student getStudentInfo(Student stu[ ], int &numstu)
{
// Get the student name.
cout << "Student name: ";
cin >> stu-> name;

// Get the student ID number.
cout << "Student ID Number: ";
cin >> stu-> id;

// Get the credit hours enrolled.
cout << "Credit Hours Enrolled: ";
cin >> stu-> years;

// Get the GPA.
cout << "Current GPA: ";
cin >> stu-> gpa;
}
getStudentInfo(students[NUM_STUDENTS], &NUM_STUDENTS)

Here is your attempt to call the function. It makes no sense. The function accepts an array of Student, and an int.

Here is what I expect you meant to do:
getStudentInfo(students, NUM_STUDENTS)


How to call a function is very very basic. If you are getting this wrong, stop. Go back. Learn what a variable is and how to use one. Learn what a function is and how to use one.
The professor required we called it that way, that's why I'm having trouble
I actually expected the index of the students array to be passed into the function. Needs documentation on what that second integer parameter is supposed to be. I imagined it like so:

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
76
77
78
79
80
81
82
83
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int NAME_SIZE = 50;
const int ID_SIZE = 10;
const int COURSE_SIZE = 10;
const int CNAME_SIZE = 50;
const int DAYS = 5;

struct Course{
  char cName[CNAME_SIZE];
  int cNum;
  char days[DAYS];
  char instructor[NAME_SIZE];
};

struct Student{
  char name[NAME_SIZE];
  char id[ID_SIZE];
  int years;
  double gpa;
  Course courses[COURSE_SIZE];
};

Student getStudentInfo(Student[], int);
void getCourses(Course[], int);
void displayStudents(Student [ ], int);

int main()
{
  const int NUM_STUDENTS = 12;
  
  //Declaring a new array
  Student* students = new Student[NUM_STUDENTS];
  getStudentInfo(students, 0);
  getStudentInfo(students, 1);
  
  
  for(int i=0; i<NUM_STUDENTS; ++i)
  {
    auto& stu = students[i];
    if (stu.years)
    {
      cout << "#"<<i<<":\n";
      cout << stu.name << endl;
      cout << stu.id << endl;
      cout << stu.years << endl;
      cout << stu.gpa << endl;
      cout << endl;
    }
    else
    {
      cout << "student "<<i<<" not yet enrolled\n";
    }
  }
  
  
  //TODO: Remember to delete students array when you're done
  
  return 0;
} 
  
Student getStudentInfo(Student stu[ ], int student_index)
{
  // Get the student name.
  cout << "Student #" << student_index << " information input: " << endl;
  cout << "  name: ";
  cin >> stu[student_index].name;
  
  // Get the student ID number.
  cout << "  id: ";
  cin >> stu[student_index].id;
  
  // Get the credit hours enrolled.
  cout << "  year: ";
  cin >> stu[student_index].years;
  
  // Get the GPA.
  cout << "  GPA: ";
  cin >> stu[student_index].gpa;
  cout << endl;
}


Example input/output:
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
Student #0 information input: 
  name:  John_Smith
  id:  S111
  year:  2
  GPA:  3.14

Student #1 information input: 
  name:  Lily_Jones
  id:  S233
  year:  4
  GPA:  3.62

#0:
John_Smith
S111
2
3.14

#1:
Lily_Jones
S233
4
3.62

student 2 not yet enrolled
student 3 not yet enrolled
student 4 not yet enrolled
student 5 not yet enrolled
student 6 not yet enrolled
student 7 not yet enrolled
student 8 not yet enrolled
student 9 not yet enrolled
student 10 not yet enrolled
student 11 not yet enrolled


Online compiler: https://repl.it/repls/RegalLegitimateUsers

It's not feature-complete but is one way to solve the filling of the array with a little test on the year to see if a student had been added. No idea why you'd want the original method signature to fill the array...
Update: I think I have figured out most of the coded, but when I attempt to build the code I keep getting an error that states the following.

"Linker command failed with exit code 1 (use -v to see invocation)"

I'm not sure what that means and if someone could help me understand that would be much appreciated

This is the code that I currently have:
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int NAME_SIZE = 50;
const int ID_SIZE = 10;
const int COURSE_SIZE = 10;
const int CNAME_SIZE = 50;
const int DAYS = 5;

struct Course{
    char cName[CNAME_SIZE];
    int cNum;
    char days[DAYS];
    char instructor[NAME_SIZE];
};

struct Student{
    char name[NAME_SIZE];
    char id[ID_SIZE];
    int years;
    double gpa;
    Course courses[COURSE_SIZE];
    int numberOfCourses;
};

void getStudentInfo(Student [ ], int &);
void getCourses(Course [ ], int &);
void displayStudents(Student [ ], int);

int main()
{
    int NUM_STUDENTS = 0;
    int NUM_COURSE = 0;
    char courseContine;
    char studentContine;
    
    Student *students = nullptr;
    Course *course = nullptr;
    //Decalring a new array
    students = new Student[NUM_STUDENTS];
    course = new Course[NUM_COURSE];
    do{
        getStudentInfo(students, NUM_STUDENTS);
        do{
            getCourses(course, NUM_COURSE);
            cout << "More courses?";
            cin >> courseContine;
            if(courseContine == 'y' || courseContine == 'Y')
                students->numberOfCourses++;
        }while(courseContine == 'y' || courseContine == 'Y');
        cout << "More students?";
        cin >> studentContine;
    }while(studentContine == 'y' || studentContine == 'Y');
    return 0;
}

void getStudentInfo(Student students[], int &numstu)
{
    // Get the student name.
    cout << "Student name: ";
    cin >> students-> name;
    
    // Get the student ID number.
    cout << "Student ID Number: ";
    cin >> students-> id;
    
    // Get the year enrolled.
    cout << "Year in school: ";
    cin >> students-> years;
    
    // Get the GPA.
    cout << "Current GPA: ";
    cin >> students-> gpa;
    
    numstu++;
}

void getCourses(Course cour[], int &numcour)
{
    cout << "Course Name: ";
    cin >> cour -> cName;
    
    cout << "Course Number: ";
    cin >> cour -> cNum;
    
    cout << "Schedule: ";
    cin >> cour -> days;
    
    cout << "Instructor: ";
    cin >> cour -> instructor;
}

void displayStudents(Student stu[ ], int numstu)
{
    cout << "Here shows the students' records:\n\n";
    for(int i = 0; i < numstu; i++)
    {
        cout << "******************\n\n";
        cout << "Student Name: " << stu[i].name << endl;
        cout << "Student ID: " << stu[i].id << endl;
        cout << "Year in school: " << stu[i].years << endl;
        cout << "GPA: " << stu[i].gpa << endl << endl;
        cout << "Courses: \n";
        for (int index = 0; index < stu->numberOfCourses; index++)
        {
            cout << "Name: " << stu[i].courses[index].cName << endl;
            cout << "Number: " << stu[i].courses[index].cNum << endl;
            cout << "Schedule " << stu[i].courses[index].days << endl;
            cout << "Instrutor: " << stu[i].courses[index].instructor << endl;
        }
    }
}
Last edited on
Update pt. 2:

Okay I figured out the error part, but now that the program is running I think my display students is messed up and I don't know what to do.

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int NAME_SIZE = 50;
const int ID_SIZE = 10;
const int COURSE_SIZE = 10;
const int CNAME_SIZE = 50;
const int DAYS = 5;

struct Course{
    char cName[CNAME_SIZE];
    int cNum;
    char days[DAYS];
    char instructor[NAME_SIZE];
};

struct Student{
    char name[NAME_SIZE];
    char id[ID_SIZE];
    int years;
    double gpa;
    Course courses[COURSE_SIZE];
    int numberOfCourses;
};

void getStudentInfo(Student [ ], int &);
void getCourses(Course [ ], int &);
void displayStudents(Student [ ], int);

int main()
{
    int NUM_STUDENTS = 0;
    int NUM_COURSE = 0;
    char courseContine;
    char studentContine;
    
    Student *students = nullptr;
    Course *course = nullptr;
    //Decalring a new array
    students = new Student[NUM_STUDENTS];
    course = new Course[NUM_COURSE];
    do{
        getStudentInfo(students, NUM_STUDENTS);
        do{
            getCourses(course, NUM_COURSE);
            cout << "More courses?";
            cin >> courseContine;
            if(courseContine == 'y' || courseContine == 'Y')
                students->numberOfCourses++;
        }while(courseContine == 'y' || courseContine == 'Y');
        cout << "More students?";
        cin >> studentContine;
    }while(studentContine == 'y' || studentContine == 'Y');
    displayStudents(students, NUM_STUDENTS);
    return 0;
}

void getStudentInfo(Student students[], int &numstu)
{
    // Get the student name.
    cout << "Student name: ";
    cin >> students[numstu].name;
    
    // Get the student ID number.
    cout << "Student ID Number: ";
    cin >> students[numstu].id;
    
    // Get the year enrolled.
    cout << "Year in school: ";
    cin >> students[numstu].years;
    
    // Get the GPA.
    cout << "Current GPA: ";
    cin >> students[numstu].gpa;
    
    numstu++;
}

void getCourses(Course cour[], int &numcour)
{
    cout << "Course Name: ";
    cin >> cour[numcour].cName;
    
    cout << "Course Number: ";
    cin >> cour[numcour].cNum;
    
    cout << "Schedule: ";
    cin >> cour[numcour].days;
    
    cout << "Instructor: ";
    cin >> cour[numcour].instructor;
}

void displayStudents(Student stu[ ], int numstu)
{
    cout << "Here shows the students' records:\n\n";
    for(int i = 0; i < numstu; i++)
    {
        cout << "******************\n\n";
        cout << "Student Name: " << stu[i].name << endl;
        cout << "Student ID: " << stu[i].id << endl;
        cout << "Year in school: " << stu[i].years << endl;
        cout << "GPA: " << stu[i].gpa << endl << endl;
        cout << "Courses: \n";
        for (int index = 0; index < stu[i].numberOfCourses; index++)
        {
            cout << "Name: " << stu[i].courses[index].cName << endl;
            cout << "Number: " << stu[i].courses[index].cNum << endl;
            cout << "Schedule " << stu[i].courses[index].days << endl;
            cout << "Instrutor: " << stu[i].courses[index].instructor << endl;
        }
    }
}


and here's the output

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
Student name: Jayme
Student ID Number: 767092
Year in school: 1
Current GPA: 3.5
Course Name: STATS
Course Number: 432
Schedule: MWF
Instructor: Tung
More courses?n
More students?n
Here shows the students' records:

******************

Student Name: Jayme
Student ID: 767092
Year in school: 1
GPA: 3.5

Courses: 
Name: \214
Number: 0
Schedule edirMap
Instrutor: ap
Name: &8>\306\334&\300A\300ys
Number: 0
Schedule 
Instrutor: 
Name: \300
Number: 0
Schedule Uen_US
Instrutor: S
Name: /Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc
Number: 1869833554
Schedule urces/Camera RGB Profile.icc
Instrutor: /Camera RGB Profile.icc
Name: 
Number: 1
Schedule 
Instrutor: 
Name: \300
Number: 0
Schedule 
Instrutor: 
Name: `\240s\263\377
Number: 1
Schedule `\231s
Instrutor: 
Name: \230[\255\377
Number: 1701736296
Schedule 
Instrutor: 
Name: \360\231s
Number: 0
Schedule Uen_US
Instrutor: S
Name: 
Number: 0
Schedule 
Instrutor: 
Name: \214
Number: 1802661751
Schedule /Versions/A/Resources/Camera RGB Profile.icc
Instrutor: ions/A/Resources/Camera RGB Profile.icc
Name: \300
Number: 0
Schedule 0\232s
Instrutor: 
Name: 
Number: 1
Schedule 
Instrutor: 
Name: \225\254\247v\236\272\256+\270y
\255\377
Number: 8396812
Schedule @
Instrutor: P
Name: \200\233s
Number: 1
Schedule Apple iPhone
Instrutor: e iPhone
Name: 
Number: -1
Schedule Uen_US
Instrutor: S
Name: 
Number: 0
Schedule 
Instrutor: 
Name: \214
Number: 1802661751
Schedule /Versions/A/Resources/Camera RGB Profile.icc
Instrutor: ions/A/Resources/Camera RGB Profile.icc
Name: \300
Number: 0
Schedule @\235s
Instrutor: 
Name: \331Q`
\255\377\377
Number: 1
Schedule \237s
Instrutor: 
Name: \225\254\247v\236\272\256+\270y
\255\377
Number: 8396812
Schedule @
Instrutor: P
Name: ColorSyn
Number: 1
Schedule 
Jayme's Phone
Instrutor: e's Phone
Name: \240s
Number: 1964642420
Schedule Uen_US
Instrutor: S
Name: 
Number: 0
Schedule 
Instrutor: 
Name: \214
Number: 1802661751
Schedule /Versions/A/Resources/Camera RGB Profile.icc
Instrutor: ions/A/Resources/Camera RGB Profile.icc
Name: \300
Number: 0
Schedule P\240s
Instrutor: 
Name: 5
Number: 1
Schedule  \242s
Instrutor: 
Name: \225\254\247v\236\272\256+\270y
\255\377
Number: 131072
Schedule Pws\263\377
Instrutor: 
Name: 
Number: 0
Schedule %US
Instrutor: 
Name: Чs
Number: 0
Schedule \220\244s
Instrutor: 
Name: 8<
\255\377
Number: 8396812
Schedule @
Instrutor: P
Name: 
Number: 1
Schedule Ъs
Instrutor: 
Name: le.preferences.timezone.new.selected_city
Number: 0
Schedule \341a
\255\377\377
Instrutor: \377
Name: ntryCode
Number: 909194798
Schedule 66331-3830-3964-3061-613365333930
Instrutor: -3830-3964-3061-613365333930
Name: \214
Number: 909325105
Schedule 4
Instrutor: 
Name: 63-6630-6534-336133326539
Number: 1
Schedule 0Device.cmra.62383939-3839-3464-3534-336535343633
Instrutor: ce.cmra.62383939-3839-3464-3534-336535343633
Name: 
Number: 1
Schedule \200\246s
Instrutor: 
Name: 
Number: 2037539186
Schedule /ColorSync/Profiles/sRGB Profile.icc
Instrutor: rSync/Profiles/sRGB Profile.icc
Name: \3642\255XؿA\341a
\255\377\377
Number: 778399343
Schedule selected_city
Instrutor: ted_city
Name: 
Number: 0
Schedule \341a
\255\377\377
Instrutor: \377
Name: \204
Number: 12262407
Schedule &0
Instrutor: 
Name: \240\247s
Number: 0
Schedule \341a
\255\377\377
Instrutor: \377
Program ended with exit code: 0 


The actually output goes on for much longer but I can't include all of that in here
Topic archived. No new replies allowed.