#include <iostream> #include <string> using namespace std; struct stdRecord { st
ID: 3632222 • Letter: #
Question
#include <iostream>
#include <string>
using namespace std;
struct stdRecord
{
string studentID;
string studentName;
int courseCode;
int creditPoint;
};
int menu(void); void coursestudents(void);
void eligiblegraduates(void); void allStudents(void);void updatestudrecord(void);
void addnewrecord(void);void removerecord(void);
void displayStudent(int);void studentSearch(void);
int menu()
{
int ans;
cout << "Main Menu ";
cout << "0. Exit " ;
cout << "1. Search for a Student ";
cout << "2. List Students enrolled in a course ";
cout << "3. List Students eligible to graduate ";
cout << "4. List all Students ";
cout << "5. Update a Student record ";
cout << "6. Add a Student record ";
cout << "7. Delete a Student record ";;
cout << "Your choice -> " ;
cin >> ans;
return ans;
}
const int MAXRECORD = 500;
stdRecord studentRecords[MAXRECORD];
int courses[] = {3506, 3633, 3634, 3639}; int recordSize = 0;
int main()
{
int choice;
stdRecord s1 = {"15000000","Joshua Andrew Smith", 3506, 240};studentRecords[recordSize] = s1;recordSize++;
stdRecord s2 = {"16666666", "Jack Williams", 3506, 18};studentRecords[recordSize] = s2; recordSize++;
stdRecord s3 = {"17000010", "Lily Jones", 3639, 110}; studentRecords[recordSize] = s3; recordSize++;
do
{
choice = menu();
switch (choice)
{
case 0:
cout <<"Record System now exiting." << endl;
break;
case 1:
cout;
studentSearch();
cout;
break;
case 2:
cout;
allStudents();
cout;
break;
case 3:
cout;
eligiblegraduates();
cout;
break;
case 4:
cout;
updatestudrecord();
break;
case 5:
coursestudents();
cout;
break;
case 6:
cout;
addnewrecord();
cout;
break;
case 7:
cout;
removerecord();
cout;
break;
default:
cout << "Command not valid";
}
} while (choice!=0);
return 0;
}
void studentSearch()
{
string searchID;
char choice;
int results[recordSize];
int hits = 0;
int binary;
do
{
for(int i = 0; i < recordSize; i++)
results[i] = -1;
hits = 0;
cout << "Search a student by entering his/her Student Id:" << endl;
cin >> searchID;
for(int i = 0; i < recordSize; i++)
{
if(studentRecords[i].studentID.compare(searchID) == 0)
{
results[hits] = i;
hits++;
}
}
if(hits == 0)
{
cout << " No record available or found" << endl;
}
else
{
cout << "Results:";
for (int i = 0; i < hits; i++)
displayStudent(results[i]);
}
void eligiblegraduates()
{
int results[recordSize];
int hits = 0;
for(int i = 0; i < recordSize; i++)
results[i] = -1;
hits = 0;
for(int i = 0; i < recordSize; i++)
{
if(studentRecords[i].creditPoint >= 240 )
{
results[hits] = i;
hits++;
}
}
if(hits == 0)
{
cout << "No eligible students" << endl;
}
else
{
cout << "Results are:";
for (int i = 0; i < hits; i++)
displayStudent(results[i]);
}
void coursestudents ()
{
bool hits;
for (int i = 0; i < recordSize; i++)
displayStudent(i);
for (int i = 0; i < 4; i++)
{
hits = false;
cout << "Course: " << courses[i] << endl;
for (int j = 0; j < recordSize; j++)
{
if(studentRecords[j].courseCode == courses[i])
{
displayStudent(j);
hits = true;
}
}
if(hits == false)
cout << " No Records Found" << endl;
}
}
void displayStudent(int index)
{
cout << " " ;
cout << " Student id:" << studentRecords[index].studentID;
cout << " Student's name:" << studentRecords[index].studentName;
cout << " Course code:t" << studentRecords[index].courseCode;
cout << " Credit :" << studentRecords[index].creditPoint;
cout << " ";
}
void updatestudrecord()
{
cout << "This is implemented in stage 2" << endl;
}
void addnewrecord()
{
cout << "This is implemented in stage 2" << endl;
}
void removerecord()
{
cout << "This is implemented in stage 2" << endl;
}
Explanation / Answer
you hacked off plenty of pieces of code that wont' let it work without them. For example - leaving only the firs part of a do-while loop :) there are plenty of syntax errors here and pieces of code missing from the original.
=Here is the code as it should be with the comments removed and the functions renamed according to your new names. REMOVE ANYTHING ELSE FROM THE CODE AND IT WILL NOT WORK ok?
Just copy paste the following code as a fresh C++ file, name it whatever you want, and compile/execute.
===================================================================
#include <iostream>
#include <string>
using namespace std;
struct stdRecord
{
string studentID;
string studentName;
int courseCode;
int creditPoint;
};
int menu(void);
void studentSearch(void);
void coursestudents(void);
void eligiblegraduates(void);
void allStudents(void);
void updatestudrecord(void);
void addnewrecord(void);
void removerecord(void);
void displayStudent(int index);
const int MAXRECORD = 500;
stdRecord studentRecords[MAXRECORD];
int recordSize = 0;
int courses[] = {3506, 3633, 3634, 3639};
int main()
{
int choice;
stdRecord s1 = {"15000000","Joshua Andrew Smith", 3506, 240};
stdRecord s2 = {"16666666", "Jack Williams", 3506, 180};
stdRecord s3 = {"17000010", "Lily Jones", 3639, 110};
studentRecords[recordSize] = s1;
recordSize++;
studentRecords[recordSize] = s2;
recordSize++;
studentRecords[recordSize] = s3;
recordSize++;
do
{
choice = menu();
switch (choice)
{
case 0:
cout <<" Exiting the Students Records System..." << endl;
break;
case 1:
cout << endl;
studentSearch();
cout << endl;
break;
case 2:
cout << endl;
coursestudents();
cout << endl;
break;
case 3:
cout << endl;
eligiblegraduates();
cout << endl;
break;
case 4:
cout << endl;
allStudents();
cout << endl;
break;
case 5:
cout << endl;
updatestudrecord();
cout << endl;
break;
case 6:
cout << endl;
addnewrecord();
cout << endl;
break;
case 7:
cout << endl;
removerecord();
cout << endl;
break;
default:
cout << " Invalid Command. Please Try Again..." << endl;
}
} while (choice!=0);
return 0;
}
int menu()
{
int ans;
cout << " ---::::::: Student Records Main Menu :::::::--- " << endl;
cout << "0. Exit" << endl;
cout << "1. Search for a Student" << endl;
cout << "2. List Students enrolled in a course" << endl;
cout << "3. List Students eligible to graduate" << endl;
cout << "4. List all Students" << endl;
cout << "5. Update a Student record" << endl;
cout << "6. Add a Student record" << endl;
cout << "7. Delete a Student record" << endl;
cout << "=============================================== " << endl;
cout << "Your choice -> " ;
cin >> ans;
return ans;
}
void studentSearch()
{
string searchID;
char choice;
int results[recordSize];
int hits = 0;
do
{
for(int i = 0; i < recordSize; i++)
results[i] = -1;
hits = 0;
cout << " Search by student ID" << endl;
cout << " Enter student ID to search for: ";
cin >> searchID;
for(int i = 0; i < recordSize; i++)
{
if(studentRecords[i].studentID.compare(searchID) == 0)
{
results[hits] = i;
hits++;
}
}
if(hits == 0)
{
cout << " Record Not Found!" << endl;
}
else
{
cout << " [Search by Student ID] - Results:";
for (int i = 0; i < hits; i++)
displayStudent(results[i]);
}
do {
cout << " Launch another search? (Y/N) > ";
cin >> choice;
if(choice != 'Y' && choice !='y' && choice!='N' && choice!='n')
cout << " Invalid choice! Please enter Y/y or N/n" << endl;
}while(choice != 'Y' && choice !='y' && choice!='N' && choice!='n');
}while(choice =='Y' || choice=='y');
}
void coursestudents()
{
int searchCourse;
char choice;
int results[recordSize];
int hits = 0;
do
{
for(int i = 0; i < recordSize; i++)
results[i] = -1;
hits = 0;
cout << " List students by Course Code" << endl;
cout << "Courses available: ";
for (int i = 0; i < 4; i++)
cout << courses [i] << " ";
cout << endl;
cout << " Enter Course Code to search for: ";
cin >> searchCourse;
for(int i = 0; i < recordSize; i++)
{
if(studentRecords[i].courseCode == searchCourse)
{
results[hits] = i;
hits++;
}
}
if(hits == 0)
{
cout << " Not Found!" << endl;
}
else
{
cout << " [List by Course Code] - Results:";
for (int i = 0; i < hits; i++)
displayStudent(results[i]);
}
do {
cout << " Launch another search? (Y/N) > ";
cin >> choice;
if(choice != 'Y' && choice !='y' && choice!='N' && choice!='n')
cout << " Invalid choice! Please enter Y/y or N/n" << endl;
}while(choice != 'Y' && choice !='y' && choice!='N' && choice!='n');
}while(choice =='Y' || choice=='y');
}
void eligiblegraduates()
{
int results[recordSize];
int hits = 0;
for(int i = 0; i < recordSize; i++)
results[i] = -1;
hits = 0;
for(int i = 0; i < recordSize; i++)
{
if(studentRecords[i].creditPoint >= 240 )
{
results[hits] = i;
hits++;
}
}
if(hits == 0)
{
cout << " No Eligible Students Found!" << endl;
}
else
{
cout << " [List by Eligibility to Graduate] - Results:";
for (int i = 0; i < hits; i++)
displayStudent(results[i]);
}
}
void allStudents()
{
bool hits;
for (int i = 0; i < recordSize; i++)
displayStudent(i);
}
void displayStudent(int index)
{
cout << " " ;
cout << " Student id:" << studentRecords[index].studentID;
cout << " Student's name:" << studentRecords[index].studentName;
cout << " Course code:t" << studentRecords[index].courseCode;
cout << " Credit :" << studentRecords[index].creditPoint;
cout << " ";
}
void updatestudrecord()
{
cout << " Implemented in Part II" << endl;
}
void addnewrecord()
{
cout << " Implemented in Part II" << endl;
}
void removerecord()
{
cout << " Implemented in Part II" << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.