How do you create a student management system in C++ with 4 basic features: (a)
ID: 3700194 • Letter: H
Question
How do you create a student management system in C++ with 4 basic features: (a) Add a student; (b) Delete a student; (c) List all students; (d) Quit and a class named “Student” which has “ID”, “name” and "grade level"?All properties should be declared as private members, all methods should be defined as public members. It should have getters and setters, default constructor and overloaded constructor How do you create a student management system in C++ with 4 basic features: (a) Add a student; (b) Delete a student; (c) List all students; (d) Quit and a class named “Student” which has “ID”, “name” and "grade level"?
All properties should be declared as private members, all methods should be defined as public members. It should have getters and setters, default constructor and overloaded constructor
All properties should be declared as private members, all methods should be defined as public members. It should have getters and setters, default constructor and overloaded constructor
Explanation / Answer
#include<iostream>
using namespace std;
class student
{
int roll_num;
char name[50];
int physics, chemistry, mathematics, english;
double marks;
char grade;
void calculate();
public:
void getdata();
void show() const;
void display_all() const;
void AddStudent(int);
void deleteStudent(int);
int getRoll_num() const;
}
void student::calculate()
{
marks=(physics+chemistry+mathematics+english)/4.0;
if(marks>=90)
grade='A+';
else if(marks>=80)
grade='A';
else if(marks>=75)
grade='A-';
else if(marks>=70)
grade='B+';
else if(marks>=65)
grade='B';
else if(marks>=60)
grade='B-';
else if(marks>=55)
grade='C+';
else if(marks>=50)
grade='C';
else
grade='F';
}
void student::getdata()
{
cout<<" Enter The ID number of the student ";
cin>>roll_num;
cout<<" Enter student's Name: ";
cin.ignore();
cin.getline(name,50);
cout<<" Enter student's physics grade: ";
cin>>physics;
cout<<" Enter student's chemistry grade: ";
cin>>chemistry;
cout<<" Enter student's mathematics grade: ";
cin>>mathematics;
cout<<" Enter student's english grade: ";
cin>>english;
calculate();
}
void AddStudent(int n)
{
bool found=false;
student st;
fstream File;
File.open("student.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&st), sizeof(student));
if(st.getRoll_num()==n)
[
st.showdata();
cout<<" Please Enter The New Details of student"<<endl;
st.getdata();
int pos=(-1)*static_cast<int>(sizeof(st));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&st), sizeof(student));
cout<<" Record Updated";
found=true;
}
}
File.close();
if(found==false)
cout<<" Record Not Found ";
cin.ignore();
cin.get();
}
void delete_student(int n)
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
cin.ignore();
cin.get();
return;
}
ofstream outFile;
outFile.open("Temp.dat",ios::out);
inFile.seekg(0,ios::beg);
while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
{
if(st.getRoll_num()!=n)
{
outFile.write(reinterpret_cast<char *> (&st), sizeof(student));
}
}
outFile.close();
inFile.close();
remove("student.dat");
rename("Temp.dat","student.dat");
cout<<" Record Deleted ..";
cin.ignore();
cin.get();
}
void display_all()
{
student st;
ifstream inFile;
inFile.open("student.dat",ios::binary);
if(!inFile){
cin.ignore();
cin.get();
return;
}
cout<<" DISPLAY ALL RECORD !!! ";
while(inFile.read(reinterpret_cast<char *> (&st), sizeof(student)))
{
st.showdata();
inFile.close();
cin.ignore();
cin.get();
}
int main()
{
char ch;
int num;
cout.setf(ios::fixed|ios::showpoint);
cout<<setprecision(2);
do
{
system("cls");
cout<<" 1.ADDSTUDENT S";
cout<<" 2.DELETE STUDENTS";
cout<<" 3. List all students";
cout<<" 4. EXIT";
cout<<" Please Enter Your Choice (1-4): ";
cin>>ch;
system("cls");
switch(ch)
{
case '1': cout<<" Please Enter Student's ID number: "; cin>>num;
AddStudent(num);break;
case '2': cout<<" Please Enter Student's ID number: "; cin>>num;
deleteSttudent(num);break;
case '3' : display_All(); break;
case '4: exit(0);;
default: cout<<"";
}}while(ch!='4');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.