Как реализовать поиск в базе данных?

нужно заполнить базу возможностями поиска данных по фамилии, номеру группы, диапазону среднего балла (от минимума до максимума), диапазону годов рождения, пополнения базы новой записью и удаления записи по паре «ФИО + год рождения». Если условиям поиска удовлетворяют несколько студентов, вывести информацию обо всех.

#include <iostream>
#include <clocale>
#include <string>
#include <fstream>

using namespace std;

struct Student{
int year;
string name;
string surename;
string otch;
string NomGr;
int stip;
float averageball;
}first;

void input(){
cout<<"Заполните базу данных информацией о студенте !"<<endl;
cout<<"Имя студента: "<<endl;
cin>>first.name;
cout<<"Фамилия студента: "<<endl;
cin>>first.surename;
cout<<"Отчество студента: "<<endl;
cin>>first.otch;
cout<<"Год поступления: "<<endl;
cin>>first.year;
cout<<"Номер группы студента: "<<endl;
cin>>first.NomGr;
cout<<"Размер стипендии студента: "<<endl;
cin>>first.stip;
cout<<"Средний бал студента: "<<endl;
cin>>first.averageball;

}

void filerec(){
ofstream out;
out.open("List.txt",ios::app);
if(out.is_open()){
out<<endl;
out<<" Имя студента: "<<first.name<<endl;
out<<"Фамилия студента: "<<first.surename<<endl;
out<<"Отчество студента: "<<first.otch<<endl;
out<<"Год поступления: "<<first.year<<endl;
out<<"Номер группы студента: "<<first.NomGr<<endl;
out<<"Размер стипендии студента: "<<first.stip<<endl;
out<<"Средний бал студента: "<<first.averageball<<endl ;
}else{
cout<<"eror!"<<endl;
}
}

void fileread(char* sa){
ifstream in;
in.open("List.txt",ios::in);
if(!in.is_open()){
cout<<"eror!"<<endl;
}else{
while(in>>sa){
cout<<in.rdbuf();
}
in.close();
}

}

void add_student(){
ofstream out;
out.open("List.txt",ios::app);
if(out.is_open()){
out<<endl;
out<<"Имя студента: "<<first.name<<endl;
out<<"Фамилия студента: "<<first.surename<<endl;
out<<"Отчество студента: "<<first.otch<<endl;
out<<"Год поступления: "<<first.year<<endl;
out<<"Номер группы студента: "<<first.NomGr<<endl;
out<<"Размер стипендии студента: "<<first.stip<<endl;
out<<"Средний бал студента: "<<first.averageball<<endl ;
}else{
cout<<"eror!"<<endl;
}
}

void ochistka(){
ofstream out;
out.open("List.txt", ofstream::out | ofstream::trunc);
out.close();
}

int Poisk_Family(){
ifstream out;
char s[1080];
char name[100];
out.open("List.txt",ios::app);
out>>s;
cout<<"Введите фамилию студента: ";
cin>>name;
for(int i =0 ; i<out.eof(out);i++){
if(name==s){
cout<<"Студент в базе!"<<endl;
out.close();
}else{
cout<<"Ошибка!"<<endl;
}
}
}

void choice(){
int n;
cout<<"1.Хотите добавить ещё студента \n2.Закончить работу с базой данных\n3.Очистить базу данных\n4.Поиск\n5.Показать базу данных"<<endl;
cin>>n;
switch(n){
case 1:
cout<<"Хорошо"<<endl;
cout<<endl;
input();
add_student();
cout<<endl;
choice();
break;
case 2:
cout<<"Пока"<<endl;
return ;
break;
case 3:
ochistka();
cout<<"Очищено!"<<endl;
cout<<endl;
choice();
break;
case 4:
Poisk_Family();
break;
case 5:
char sa[1080];
fileread(sa);
cout<<endl;
choice();
break;
}
}


int main(){
setlocale(LC_ALL,"Russian");
int year;
string name;
string surename;
string otch;
string NomGr;
int stip;
float averageball;
input();
char sa[1080];
filerec();
cout<<endl<<endl;
fileread(sa);
cout<<endl<<endl;
choice();

return 0;
}

Ответы (0 шт):