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

CREATE THE CODE ON MICROSOFT VISUAL STUDIO.\" C+\" /* Instructions: You are to c

ID: 3776298 • Letter: C

Question

CREATE THE CODE ON MICROSOFT VISUAL STUDIO." C+"

/*
Instructions:
You are to create a program that tracks student grades.
When the program launches the user should be presented with three options;

Press 0 to exit
Press 1 for author info
Press 2 to Log in

Selecting 0 exits the program
Selecting 1 prints your name and student id
Selecting 3 prompts the user to enter a user name and password.
You should then open the file "passwords" and see if the user is authorized to use the program*
If the username + password was not valid print an error to the user and go back to the previous menu.

*The passwords file will contain a list of user names and passwords, in the format of:
user1 password1
user2 password2
user3 password3

If the username + password was valid present the user with a new menu:
Press 1 for author info
Press 2 to Enter new student
Press 3 to enter grade for existing student
Press 4 to print student records
Press 5 to save student records
Press 6 to load student records
Press 7 to logout

Selecting 0 exits the program
Selecting 1 prints your name and student id
Selecting 2 Prompts the user for a first and last name. Store this information in the system as a student record.
You should be able to handle 1000 students.
Student records have
   First name,
   Last name,
   Student ID,
   A list of grades (up to 100 classes). Grades are entered in grade point format (4.0 for an A)

Selecting 3 prompts the user for a student ID and a grade to be entered. Store this grade in that student's record.
Selecting 4 prints the names, ids, GPA and a list of all earned grades for every student. See the sample file for formatting.
Selecting 5 prompts the user for a file name and saves all stored student records to a file. (or in other words, save game)
Selecting 6 prompts the user for a file name and loads student information from a file (or in other words, load game)
Selecting 7 Log out the current user and return to the shorter menu from above.

Your program should also keep a log file of all launch, log in, failed log in, log out, save, load, student creation, grade entry attempts, as well as application exit
This file should be called students.log persist across multiple application starts.
except for exit and start entries, the current logged in username should also be entered in the log.

Note: When loading you can assume all previous student entries are being deleted, rather than detecting repeat students.
*/

Explanation / Answer

//Answer Code

#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <limits>
using namespace std;

string StudentName[10];
string StudentRollno[10];
float StudentGPA[10];
int count=0;

void enterInformation();
void deleteInformation();
void searchstudentinfo();
void sortstudentinfo();
void averageGPA();
void saveinfo();
void fileexit();

void main ()
{
int menu;
ifstream outstudentinfo("student.txt",ios::in);
if (!outstudentinfo)
{
cout << "File could not be opened" << endl;
exit(0);
}
do
{
cout<<"Press (1) to Enter Student information"<<endl
<<"Press (2) to Delete Student information"<<endl
<<"Press (3) to Sort Student information"<<endl
<<"Press (4) to Search Student information"<<endl
<<"Press (5) to Calcuate Average GPA for Students"<<endl
<<"Press (6) to Save Student information to file"<<endl
<<"Press (7) to Exit the program"<<endl
<<"Select any from above menu"<<endl;

cin>>menu;
cin.ignore(numeric_limits<streamsize>::max(), ' ');
switch (menu)
{
case 1:
{
enterInformation();
break;
}
case 2:
{
deleteInformation();
break;
}
case 3:
{
sortstudentinfo();
break;
}
case 4:
{
searchstudentinfo();
break;
}
case 5:
{
averageGPA();
break;
}
case 6:
{
saveinfo();
break;
}
case 7:
{
fileexit();
break;
}
}
}
while (1);
}
void enterInformation()
{
int i=count;
cout<<"Please enter the data of the student"<<endl;
if(count<10)
{
cout<<"Roll.no :";
getline(cin,StudentRollno[i]);
cout<<"Student Name :";
getline(cin,StudentName[i]);
cin>>StudentGPA[i];
cout<<"Student GPA :";
cin.ignore(numeric_limits<streamsize>::max(), ' ');
cout<<endl;
count++;
}
else
cout<<"Sorry, memory is already full!!!"<<endl;
}
void deleteInformation()
{
int i,del=0;
for (i=0;i<count;i++)
{
cout<<"ST.NO:"<<i+1<<' '<<StudentRollno[i]<<' '<<StudentName[i]<<' '<<StudentGPA[i]<<endl;
}
cout<<"Please enter the ST.NO of the student whoes data you want to delete "<<endl;
cin>>del;
for (i=del;i<count-1;i++)
{
StudentRollno[i]=StudentRollno[i+1];
StudentName[i]=StudentName[i+1];
StudentGPA[i]=StudentGPA[i+1];
}
StudentRollno[count]="";
StudentName[count]="";
StudentGPA[count]=0.00;
for (i=0;i<count;i++)
{
cout<<"ST.NO:"<<i<<' '<<StudentRollno[i]<<' '<<StudentName[i]<<' '<<StudentGPA[i]<<endl;
}
count--;
}
void sortstudentinfo()
{
int i,j;
float temp3;
string temp1,temp2;
for (i=0;i<count;i++)
{
for(j=i+1;j<count;j++)
{
if(strcmp(StudentName[i].c_str(),StudentName[j].c_str())==1)
{
temp1=StudentName[i];
StudentName[i]=StudentName[j];
StudentName[j]=temp1;

temp2=StudentRollno[i];
StudentRollno[i]=StudentRollno[j];
StudentRollno[j]=temp2;

temp3=StudentGPA[i];
StudentGPA[i]=StudentGPA[j];
StudentGPA[j]=temp3;
}
}
}
for (i=0;i<count;i++)
{
cout<<StudentRollno[i]<<' ';
cout<<StudentName[i]<<' ';
cout<<StudentGPA[i]<<endl;
}
}
void searchstudentinfo()
{
int i,j=0;
string search;
cout<<"Please enter the name of the student whoes record you want to search"<<endl;
getline(cin,search);
for (i=0;i<count;i++)
{
if(strcmp(StudentName[i].c_str() ,search.c_str())==0)
{
cout<<"StudentRollno:"<<StudentRollno[i];
cout<<"StudentName:"<<StudentName[i];
cout<<"StudentGPA:"<<StudentGPA[i]<<endl;
j++;
break;
}
}
if(j==0)
cout<<"The entered name was not found"<<endl;
}

void averageGPA()
{
int i;
float average,sum=0.00;
for (i=0;i<count;i++)
{
sum=sum+StudentGPA[i];
}
average=sum/count;
cout<<"The average GPA of the students is :"<<average<<endl;
}
void saveinfo()
{
int i=0;
ofstream outstudentinfo("student.txt",ios::out);
for(i=0;i<count;i++)
{
outstudentinfo<<"StudentRoll.no:"<<StudentRollno[i];
outstudentinfo<<"Student name :"<<StudentName[i];
outstudentinfo<<"Student GPA :"<<StudentGPA[i]<<endl;
}
outstudentinfo.close();

}
void fileexit()
{
char option;
cout<<"Do you want to save the current data? Press (y) for yes and (n) for no"<<endl;
cin>>option;
if (option=='y')
saveinfo();
else if (option=='n')
exit(0);
else
cout<<"Invalid Input"<<endl;
}