classroom roster struct

Problem Scenario: A basic class roster application is to be developed. The
application has the following functionalities:
1. ADD
Adds a new Student record if the assigned studentID has not been
already assigned to another student or displays a message indicating
that the student ID # has been already assigned,
2. DELETE
Deletes the student’s record whose ID # is entered or displays a message
indicating that the ID # has not been assigned,
3. EDIT
Edits a student’s record if the ID # is on the class roster or displays
a message indicating that the ID # has not been assigned (the first
name, middle initial and/or last name may be changed),
4. INQUIRY
displays the name of the student with the specified ID # or displays a
message indicating that the ID # has not been assigned, and
5. LISTING
Sorts by student ID # and generates the class row.
C L A S S R O S T E R
Student ID # First Name M.I. Last Name
---------------------------------------------
105-85-7251 Paul Z. Abramson
125-78-5241 Zachary Q. Bourgeois
410-78-3415 Emmanuel T. Woods
417-85-4554 Sarah H. Hallowanger
604-89-7142 Julia M. Morgan
902-54-7852 Jamesetta R. Hudson
---------------------------------------------
Enrollment: 6

I have everything except for the edit student function and the student inquiry function. Does anyone have any tips or hints on how to approach these?

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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
  #include <iostream>
#include<iomanip>
#include <fstream>

using namespace std;

/* 1. define MAX_SIZE here */


/* 2. define the Student struct here */


/**
 * displays the menu for the class roster program
 */
void menu()
{ 
   cout<<"         CLASS ROSTER APPLICATION"<<endl;           
   cout<<"========================================="<<endl;
   cout<<"ADD a student record..................[A]"<<endl;
   cout<<"DELETE a student......................[D]"<<endl;
   cout<<"EDIT a student record.................[E]"<<endl;
   cout<<"INQUIRY about a student...............[I]"<<endl;
   cout<<"LIST all students.....................[L]"<<endl;
   cout<<"QUIT the system.......................[Q]"<<endl;
}

/**
 * does a linear search for a specified student ID #
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 * @param sID a student ID number
 * @return the subscript/index at which the record with
 * the specifed student ID can be found on the class
 * roster or -1 if it cannot be found
 */
int linearSearch(const Student roster[], int numStuds, string sID)
{
   int i;
   for (i=0; i<numStuds; i++)
   {
      if (roster[i].studentID == sID)
	     return i;
   }
   return -1;
}

/**
 * sort the class roster by student ID # using selection sort
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 */
void selSort(Student roster[], int numStuds)
{
   int minIDPos;
   Student tempStudRecord;
   int i,j;
   for (i=0; i<numStuds-1; i++)
   {
      minIDPos = i;
      for (j=i+1; j<numStuds; j++)
      {
         if (roster[j].studentID < roster[minIDPos].studentID)
            minIDPos = j;
      }
      tempStudRecord = roster[i];
      roster[i] = roster[minIDPos];
      roster[minIDPos] = tempStudRecord;
   }
}

/**
 * adds a new Student record as the last record in the roster
 * array when its studentID field is not already in the array or
 * displays a message indicating that the student ID # has already
 * been assigned
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 * @param newStudent the new student's record
 */
void addStudent(Student roster[], int& numStuds, Student newStudent)
{
   int pos = linearSearch(roster,numStuds,newStudent.studentID);
   if (pos == -1)
      roster[numStuds++] = newStudent;
   else   
      cout<<newStudent.studentID<<" has already been assigned. "<<endl;
} 

/**
 * removes a student record from the roster array when the specified 
 * studentID field is in the array, moves all succeeding student
 * records up by one position (index) and decrement the number of 
 * students by 1; display a message indicating that the student ID 
 * has not been assigned if studentID field is not in the roster array
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 * @param sID the student's ID #
 */
void deleteStudent(Student roster[], int& numStuds, string sID)
{
   /** 3. implement this function **/
}   

/**
 * edits a Student record given the specified student ID when
 * the roster array contains the ID; display a message indicating
 * that the student ID has not been assigned if studentID field is 
 * not in the roster array
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 * @param sID the student's ID #
 */
void editStudent(Student roster[], int numStuds, string sID)
{
   /** 4. implement this function **/
} 

/**
 * display a Student record given the specified student ID when
 * the roster array contains the ID; display a message indicating
 * that the student ID has not been assigned if studentID field is 
 * not in the roster array
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 * @param sID the student's ID #
 */
void studentInquiry(const Student roster[], int numStuds, string sID)
{
   /** 5. implement this function **/
}

/**
 * display the class roster when there is at least one student
 * or prints a message indicating that there are currently no
 * students enrolled.
 * @param roster an array of student records
 * @param numStuds the number of students (class size)
 */
void listStudents(const Student roster[], int numStuds)
{
   /** 6. implement this function **/
}	  

int main()
{
   Student roster[MAX_SIZE];
   fstream inFile;
   fstream outFile;
   string filename, sID;
   Student newStudent;
   int numStuds = 0;
   char choice;
   int i;
   cout<<"Enter the name of the data file> ";
   cin>>filename;
   /** 7. open the data file for input **/

   
   if (inFile)
   {
      /** 8. write a while loop to read the data from the file
             into the roster array; the numStuds (number of Students)
             must be updated as the records are read from the file.
			 
            Also, close the file after its contents are read into the 
            roster array.
      **/
   }	  
   do
   {
      cout<<endl;
	  menu();
	  cout<<endl;
	  cout<<"Select an option-> ";
	  cin>>choice;
	  switch(toupper(choice))
	  {
	     case 'A': cout<<"Enter the student ID #> ";
                   cin>>newStudent.studentID;
                   cout<<"Enter the student's first name> ";
                   cin>>newStudent.firstName;
                   cout<<"Enter the student's middle initial> ";
                   cin>>newStudent.midInitial;
                   cout<<"Enter the student's last name> ";
                   cin>>newStudent.lastName;
                   addStudent(roster,numStuds,newStudent);
                   break;
         case 'D': /** 9. write code here to remove a student from the roster **/
                   break;
         case 'E': /** 10. write code to edit the record for a student with a specified ID # **/                  		 
                   break;
         case 'I': /** 11. write code to perform an inquiry (obtain full name) on a student with 
                           with a specified ID # 
				   **/			   
                  break;
         case 'L': /** 12. write code to sort and then generate class roster **/
				   break;
         case 'Q': break;
         default:  cout<<"Invalid menu choice...try again!"<<endl;		 
      }   
   }while(toupper(choice) != 'Q');
   /** 13. open the data file in output mode and error-check to ensure 
           that it was successfully opened.
   **/

   /** 14. overwrite the data file in the order:
           student ID, firstname, middle initial and last name, one record per line.
           make sure that you have spaces between the fields.
   **/		   
   
   /** 15. close the output file **/
   
   return 0;
}
   
closed account (j3Rz8vqX)
Edit student function:

--Prompt for student id #.

--Pass the roster to a the edit function by address.

--for loop till numStuds.

----If roster[i] == stdID

------//If student found: Create new student:
------//the below should be a function? (student data entry?)
------//Assuming roster[i] was passed and alias as newStudent by reference.
1
2
3
4
5
6
7
8
                   cout<<"Enter the student ID #> ";
                   cin>>newStudent.studentID;
                   cout<<"Enter the student's first name> ";
                   cin>>newStudent.firstName;
                   cout<<"Enter the student's middle initial> ";
                   cin>>newStudent.midInitial;
                   cout<<"Enter the student's last name> ";
                   cin>>newStudent.lastName;

------After modifying break; to exit loop early.
----Done, no else.

Student inquiry is similar, prompt for student id, search for student, and print her data.
Topic archived. No new replies allowed.