Здравстуйте, помогите изменить код. Нужно заменить предложение удаления фамилии, на ввод фамилии с клавиатуры и ее удаление
Код:
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <conio.h>
#include <string.h>
using namespace std;
//Стуктура динамического однонаправленного списка
struct node{
string name;
int rate;
node *next;
};
//Отдельно функции
//Добавление записи
void add(node **head, string name, int rate){
node *_new = new node;
_new->name = name;
_new->rate = rate;
_new->next = (*head);
(*head) = _new;
}
//Вывод
void show(node **head){
cout << "Журнал:" << endl;
node *cur = (*head);
while (cur != NULL){
cout << "Имя: " << cur->name << " Оценка: " << cur->rate << endl;
cur = cur->next;
}
}
//Удаляет двоичника с фамилией - name
void del(node **head,string name){
if ((*head) == NULL)cout << "Список пуст";
else{
if ((*head)->name == name)(*head) = (*head)->next;
else{
node *cur = (*head);
node *prev = NULL;
while (cur != NULL){
if (cur->name == name){
prev->next = cur->next;
}
prev = cur;
cur = cur->next;
}
}
}
}
class journal{
private:
public:
node *head;
journal(){
head = NULL;
}
//Добавление записи в журнал
void add(string name, int rate){
node *_new = new node;
_new->name = name;
_new->rate = rate;
_new->next = head;
head = _new;
}
//Добавление массива записей в журнал
void add(int n,string names[], int rates[]){
for (int i = 0; i < n; i++)add(names[i], rates[i]);
}
//Вывод
void show(){
cout << "Журнал:" << endl;
node *cur = head;
while (cur != NULL){
cout << "Имя: " << cur->name << " Оценка: " << cur->rate << endl;
cur = cur->next;
}
}
//Поиск двоичников. возвращает список фамилий, параметр К - количество
vector<string> count_2(int *k){
vector<string>names;
node *cur = head;
while (cur != NULL){
if (cur->rate == 2)names.push_back(cur->name);
cur = cur->next;
}
*k = names.size();
return names;
}
//Удаляет двоичника с фамилией - name
void del(string name){
if (head == NULL)cout << "Список пуст";
else{
if (head->name == name)head = head->next;
else{
node *cur = head;
node *prev=NULL;
while (cur!= NULL){
if (cur->name == name){
prev->next = cur->next;
}
prev = cur;
cur = cur->next;
}
}
}
}
//Удаляет двоичников с фамилиями взятыми из списка names
void del(vector<string>names){
for (int i = 0; i < names.size(); i++)del(names[i]);
}
};
int main(){
setlocale(LC_ALL, "Russian");
cout << "Введите количество Журналов" << endl;
int n;
cin >> n;
char ch;
//Работа класса
journal *j=new journal[n];
for (int i = 0; i < n; i++){
cout << "Заполнение " << i + 1 << "-го журнала:" << endl;
do{
cout << "\n Фамилия:";
string s;
cin >> s;
cout << "\n Оценка:";
int rate;
cin >> rate;
j[i].add(s, rate);
cout << "\n Закончить? y/n " << endl;;
ch = _getch();
} while (ch != 'y');
}
vector<string>names;
int count,max = 0;
for (int i = 0; i < n; i++){
j[i].show();
int k = 0;
j[i].count_2(&k);
if (max <= k){
names = j[i].count_2(&k);
max = k;
count = i;
}
}
cout <<endl<< "Изменение журнала с наибольшим количеством двоечников" << endl;
node *cur = j[count].head;
while (cur != NULL){
cout << "Имя: " << cur->name << " Оценка: " << cur->rate << endl;
cout << "\n Удалить? y/n " << endl;;
ch = _getch();
if (ch == 'y'){
j[count].del(cur->name);
}
cur = cur->next;
}
cout << "Измененный журнал" << endl;
j[count].show();
system("PAUSE");
return 0;
}