Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 22.02.2018, 11:34   #1
levnako887
Новичок
Джуниор
 
Регистрация: 22.02.2018
Сообщений: 1
Смущение Помогите доработать поиск в класе с++

#include <iostream>
#include <bitset>
#include <string>
#include <stdexcept>
#include <exception>
#include <list>
#include <algorithm>
#include <iterator>
#include <ctime>
#include <numeric>
#include <deque>
#include <vector>
#include <set>
#include <fstream>

using namespace std;

class Exam
{
protected:
struct XXX
{
string Name_Subject;
string Last_name;
unsigned int ball;
};
XXX temp;
deque<XXX> list;
public:
Exam() {}
Exam(string sub, string name, unsigned int number)
{
temp.Name_Subject = sub;
temp.Last_name = name;
temp.ball = number;
list.push_back(temp);
}
Exam(Exam& exam)
{
this->temp = exam.temp;
this->list = exam.list;
}
~Exam() {}

void Add_to_list(string sub, string name, unsigned int number)
{
temp.Name_Subject = sub;
temp.Last_name = name;
temp.ball = number;
list.push_back(temp);
}
void Pop_Front() { list.pop_front(); }
void Pop_Back() { list.pop_back(); }
void Show_obj() { cout « "Предмет: " « temp.Name_Subject « endl « "Фамілія: " « temp.Last_name « endl « "Оцінка: " « temp.ball « endl « endl; }
friend istream& operator»(istream& is, Exam::XXX& temp)
{
is » temp.Name_Subject » temp.Last_name » temp.ball;
return is;
}
friend ostream& operator«(ostream& os, Exam::XXX& temp)
{
os « "Предмет: " « temp.Name_Subject « endl « "Фамілія: " « temp.Last_name « endl « "Оцінка: " « temp.ball « endl « endl;
return os;
}
void Sort_first_simbol_Subject()
{
for (size_t i(0); i < this->list.size(); i++)
{
for (size_t j(0); j < this->list.size() - 1; j++)
{
if (static_cast<int:angry:this->list[j].Name_Subject[0]) > static_cast<int:angry:this->list[j + 1].Name_Subject[0]))
{
swap(list[j], list[j + 1]);
}
}
}
}
void Sort_first_simbol_Last_name()
{
for (size_t i(0); i < this->list.size(); i++)
{
for (size_t j(0); j < this->list.size() - 1; j++)
{
if (static_cast<int:angry:this->list[j].Last_name[0]) > static_cast<int:angry:this->list[j + 1].Last_name[0]))
{
swap(list[j], list[j + 1]);
}
}
}
}
void Sort_ball()
{
for (size_t i(0); i < this->list.size(); i++)
{
for (size_t j(0); j < this->list.size() - 1; j++)
{
if (this->list[j].ball > this->list[j + 1].ball)
{
swap(list[j], list[j + 1]);
}
}
}
}
void Show_list()
{
for (size_t i(0); i < this->list.size(); i++)
{
cout « "Предмет: " « this->list[i].Name_Subject « endl « "Фамілія: " « this->list[i].Last_name « endl « "Оцінка: " « this->list[i].ball « endl « endl;
}
}
void Find_of_Subject(string& str)
{
bool boo(false);
for (size_t i(0); i < this->list.size(); i++)
{
if (this->list[i].Name_Subject == str) { cout « "Предмет: " « this->list[i].Name_Subject « endl « "Фамілиія: " « this->list[i].Last_name « endl « "Оцінка: " « this->list[i].ball « endl « endl; break; }
}
if (boo == false) { cout « "Елемент не найдено !!!" « endl; }
}
void Find_of_Last_name(string& str)
{
bool boo(false);
for (size_t i(0); i < this->list.size(); i++)
{
if (this->list[i].Last_name == str) { boo = true; cout « "Предмет: " « this->list[i].Name_Subject « endl « "Фамілія: " « this->list[i].Last_name « endl « "Оцінка: " « this->list[i].ball « endl « endl; break; }
}
if (boo == false) {
cout « "Елемент не найдено !!!" « endl;
}
}
};

int main()
{
int count;
setlocale(LC_ALL, "Ukrainian");

ifstream fin;
ofstream fout;



string Path("C:\\test\\Test.txt");
fin.open(Path, ios::in);
try
{
if (!fin.is_open()) { throw exception("File is not found !!!"); }
}
catch (const exception& ex) { cout « ex.what() « endl; system("pause"); return -1; }

Exam Mylist;
while (!fin.eof())
{
string Subject, Last_name;
unsigned int ball;
fin » Subject » Last_name » ball;
if (fin.fail())
{
fin.clear();
break;
}
Mylist.Add_to_list(Subject, Last_name, ball);
}
fin.close();
Mylist.Sort_first_simbol_Last_name( );
Mylist.Show_list();


cout « "Пошук за предметом 1; Пошук за прізвищем 2; Введіть будь ласка одне із запропонованих чисел: ";
cin » count;
switch (count)
{
case 1:
{
cout « Mylist.Find_of_Subject("Math") « endl;
break;
}
case 2:
{
cout « Mylist.Find_of_Last_name("Nada") « endl;
break;
}
default:
cout « "Лол" « endl;
}

system("pause");
return 0;
}


Помогите дороботать поиск так чтоб искало не первого а всех , буду очень рад и извините за ошыбки
levnako887 вне форума Ответить с цитированием
Старый 22.02.2018, 11:37   #2
p51x
Старожил
 
Регистрация: 15.02.2010
Сообщений: 15,707
По умолчанию

Ну так уберите брек после первого найденного.
p51x вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите доработать программу jipumex@cartelera. Паскаль, Turbo Pascal, PascalABC.NET 5 05.10.2016 20:49
проблема при вызова метода в одном класе другого класа rich__ Общие вопросы по Java, Java SE, Kotlin 2 12.05.2016 16:00
Помогите доработать скрипт kiril318 JavaScript, Ajax 0 22.07.2014 19:36
Проблема с типами в класе GBAXA Общие вопросы Delphi 6 08.02.2012 23:18
Ошибка в класе misher Компоненты Delphi 2 20.09.2010 23:18