Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HW1 (Graded out of 100) Write a program that manages students\' information. Eac

ID: 3877089 • Letter: H

Question

HW1 (Graded out of 100) Write a program that manages students' information. Each student's information consists of a netID and a GPA, maintained in parallel arrays. The program will loop on displaying the following menu of choices: 1. List the top n students 2. Search for a student 3. Exit the program. If the user chooses 1, the user will be prompted for the value of n, and the netID and GPA of the top n students will be listed, starting with the student with highest GPA and going down. If the user chooses 2, user will be prompted to enter the student's netlD. If the netlD is found in the netlD array, the array index and the GPA of the student are displayed. If the student is not found, a "Student not found" message is displayed.

Explanation / Answer

#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main();
void show_data(int searchkey); //function used to show data to end-user.
void get_data(int i); //function used to obtain data from end-user.
void search_student(int searchkey);
void add_student(); //This function is used to add record of new student.
void edit_student(int idnumber); //function is used to edit existing record.
void fullscreen();
struct student{ //Structure of student is made to store student attributes.
int rollno;
string name;
string fname;
string cell;
string dob;
string address;
};
student rec[5]; //This is basic array of defined structure to sore data.
int main(){
system("CLS");
system("color B1");
int choice; //int variable used to determine which operation user want to do.
int idnumber; //int variable used to record ID number whih user want to edit.
int searchkey; //int variable to store student roll_no by which user can search.
cout<<" What do you want to do?"<<endl;
cout<<" ----------------------"<<endl;
cout<<" 1-Add student"<<endl;
cout<<" 2-Edit student"<<endl;
cout<<" 3-Search student"<<endl;
cout<<" 4-Quit Program"<<endl;
cout<<" ----------------------"<<endl;
cout<<"Enter your choice: ";
cin>>choice;
switch(choice){
case 1: //If user presses 1 then student adding module would be displayed.
add_student();
break;
case 2: //If there are no records in array then it will ask the user to input records first.
if(rec[0].rollno==0){
cout<<"Please Add sudents first."<<endl;
system("pause");
main();
}
else{ //If records are present in array then it will show table.
cout<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"---------------------------Student record Table---------------------------------"<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"ID "<<"Roll "<<"Name "<<"Father Cell no. "<<"DOB "<<"Address ";
cout<<"--------------------------------------------------------------------------------"<<endl;
for(int i=0;i<=4;i++){
show_data(i); //funtion is called with index value to show data.
}
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"Which ID number your want to edit: ";
cin>>idnumber; //Asking the user at which ID he wants to make change.
if(idnumber>4 || idnumber<0){ //Validating the ID number.
cout<<" Invalid ID Number."<<endl;
}
else{
edit_student(idnumber); //Passing ID number to Edit Function.
}
}
break;
case 3:
if(rec[0].rollno==0){ //If no record exist then ask the user o enter records first.
cout<<"Please Add sudents first."<<endl;
system("pause");
main(); //Return to main so user can input new record.
}
else{
cout<<"Enter roll_no of student you want to search: ";
cin>>searchkey; //roll_no as the search key can be entered by user.
search_student(searchkey);}
break;
case 4:
return 0; //Terminating the records.
break;
default: //Default value for ivalid Input.
cout<<"Invalid number."<<endl;
system("pause");
main();
}
return 0;
}

  
void get_data(int i){ //Function for receiving data from user and populatiing the variables with values.
cout<<"Enter student roll number in format(1XXX): ";
cin>>rec[i].rollno;
cout<<"Enter student name: ";
cin>>rec[i].name;
cout<<"Enter student's Father name: ";
cin>>rec[i].fname;
cout<<"Enter student's cell phone number: ";
cin>>rec[i].cell;
cout<<"Enter student's Date of Birth(dd/mm/yyyy): ";
cin>>rec[i].dob;
cout<<"Enter student's Address: ";
cin>>rec[i].address;
}
void show_data(int searchkey){ //Function for showing data on the screen.
int i=searchkey;
cout<<i<<" ";
cout<<rec[i].rollno<<" ";
cout<<rec[i].name<<" ";
cout<<rec[i].fname<<" ";
cout<<rec[i].cell<<" ";
cout<<rec[i].dob<<" ";
cout<<rec[i].address<<" ";
}
void search_student(int searchkey){
for(int i=0;i<=4;i++){ //Loop thrugh complete array.
if (rec[i].rollno==searchkey){ //If roll number matches to search term.
cout<<"ID "<<"Roll "<<"Name "<<"Father Cell no. "<<"DOB "<<"Address ";
show_data(i); //A function is used inside another function.
}
}
}

void add_student(){ //This function is used to add record of new student.
for(int i=0;i<=4;i++){
get_data(i); //Loop was processed 5 times to get input for 5 students.
}
system("CLS");
cout<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"---------------------------Student record Table---------------------------------"<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"ID "<<"Roll "<<"Name "<<"Father Cell no. "<<"DOB "<<"Address ";
cout<<"--------------------------------------------------------------------------------"<<endl;
for(int i=0;i<=4;i++){
show_data(i); //Loop was processed for 5 times to show obtained records.
}
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"---------------------------------FINISH-----------------------------------------"<<endl;
cout<<"--------------------------------------------------------------------------------"<<endl;
system("pause");
main(); //Return to main function to again show menu.
}
void edit_student(int idnumber){ //function is used to edit existing record.
for(int i=0;i<=4;i++){ //Loop is started.
if(idnumber==i){ //Through loop every value is compared with search term.
cout<<" Existed information about this record. ";
cout<<"--------------------------------------------------------------------------------"<<endl;
cout<<"ID "<<"Roll "<<"Name "<<"Father Cell no. "<<"DOB "<<"Address ";
cout<<"--------------------------------------------------------------------------------"<<endl;
show_data(i); //Load information for existing record.
cout<<" Enter new data for above shown record. ";
get_data(i); //Inputing data for that specific record.
cout<<" Record updated successfully."<<endl;
system("pause");
main(); //Return to main function.
}
}

}