#include<iostream>
#include<string>
using namespace std;
class student
{
private:
int final, m;
string name;
char grade;
public:
student();
void read();
void display();
void processing();
void copy(student);
string getname();
};
class ArrStudent
{
private:
int number;
student s[100];
public:
ArrStudent();
void read();
void display();
void processing();
bool insert(student);
bool Delete(string);
bool search(string,int&);
};
student::student()
{
name = " ";
final = 0;
m = 0;
grade = ' ';
}
void student::read()
{
cout<<"enter name : ";
cin>>ws;
getline(cin,name);
cout<<"enter m :";
cin>>m;
cout<<"enter final:";
cin>>final;
}
void student::processing()
{
int sum = final + m;
if(sum >= 60)
grade = 'p';
else
grade = 'f';
}
void student::display()
{
cout<<"name : "<<name<<endl;
cout<<"final = "<<final<<endl;
cout<<"m = "<<m<<endl;
cout<<"grade : "<<grade<<endl;
}
void student::copy(student s)
{
name = s.name;
final = s.final;
m = s.m;
grade = s.grade;
}
string student::getname()
{
return name;
}
ArrStudent::ArrStudent()
{
number = 0;
}
void ArrStudent::read()
{
cout<<"enter number:";
cin>>number;
for(int i=0;i<number;i++)
s.read();
}
void ArrStudent::display()
{
for(int i=0;i<number;i++)
s.display();
}
void ArrStudent::processing()
{
for(int i=0;i<number;i++)
s.processing();
}
bool ArrStudent::search(string name,int &index)
{
index = -1;
for(int i=0;i<number;i++)
if(s.getname() == name)
{
index = i;
return true;
}
return false;
}
bool ArrStudent::insert(student st)
{
if(number == 100)
return false;
s[number].copy(st);
number++;
return true;
}
bool ArrStudent::Delete(string name)
{
int pos;
search(name,pos);
if(pos == -1)
return false;
s[pos].copy(s[number-1]);
number--;
return true;
}
int main()
{
student st;
ArrStudent A;
int choo;
string name;
do
{
cout<<"MENU :"<<endl;
cout<<"1=>Insert students(one time)"<<endl;
cout<<"2=>Insert 1 student"<<endl;
cout<<"3=>Display students"<<endl;
cout<<"4=>Delete one student"<<endl;
cout<<"5=>process syudents"<<endl;
cout<<"6=>Exit"<<endl;
cout<<"enter your choice:";
cin>>choo;
switch(choo)
{
case 1 : A.read();
break;
case 2 : st.read();
if(! A.insert(st))
cout<<"the array is full\n";
else
cout<<"student inserted\n";
break;
case 3 : A.display();
break;
case 4 : cout<<"enter name:";
cin>>name;
if(!A.Delete(name))
cout<<"the student was not found\n";
else
cout<<"student deleted\n";
break;
case 5 : A.processing();
break;
case 6 : break;
default : cout<<"WRONG CHOICE\n";
}
}
while(choo != 6);
return 0;
}
