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

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

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

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

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

Ответ
 
Опции темы Поиск в этой теме
Старый 25.11.2017, 07:40   #1
Tim_Tanos
Новичок
Джуниор
 
Регистрация: 04.11.2017
Сообщений: 2
По умолчанию Удаление и редактирование студентов

Здравствуйте! Не получается написать редактирование(строка 324) и удаление(строка 329) студентов. Вроде пишу также как и в случае с группами,но не работает. Помогите пожалуйста.

Код:
#include <iostream>
#include <string>
#include <vector>
#include <conio.h>
#include <locale.h>
using namespace std;

enum Spec { Programmers, Designers, SysAdmins };

class Student
{
	const int id;
	string name;
	string surname;
	int age;
	string phone;
	double average;
	static int count;
public:
	Student(string name = "Untitled", string surname = "Untitled", int age = 0, string phone = "Untitled", double average = 0, int id = 0) : name(name), surname(surname), age(age), phone(phone), average(average), id(id) {}

	string getName() const
	{
		return name;
	}

	string getSurname() const
	{
		return surname;
	}

	int getAge() const
	{
		return age;
	}

	string getPhone() const
	{
		return phone;
	}

	double getAverage() const
	{
		return average;
	}

	int getId() const
	{
		return id;
	}

	void setAge(int age)
	{
		if (age > 0)
		{
			this->age = age;
		}
	}

};

class Group
{
	string name;
	const Spec spec;
	vector<Student*> group;
public:
	Group(Spec select, string name = "Untitled") : name(name), spec(select) {}


	vector<Student*>& getStudents()
	{
		return group;
	}


	string getName() const
	{
		return name;
	}

};

class Academy
{
	vector<Group*> groups;
public:

	/*void editing(int i)
	{
		if (i < groups.size() && i >= 0)
		{
			string groupname;
			cin >> groupname;
			groups.push_back(groupname);
		}
			
	}*/

	void delGroup(int i)
	{
		if (i < groups.size() && i >= 0)
			groups.erase(groups.begin() + i);
	}

	vector<Group*>& getGroups()
	{
		return groups;
	}

	Group* getGroup(int i)
	{
		return groups[i];
	}
	
	Group* search(string groupname)
	{

		if (true)
			groupname;
		else
			return nullptr;
	}
};

int Student::count = 0;

class Program
{
	Academy& academy;
public:
	Program(Academy& academy) : academy(academy) {};

	~Program()
	{
		
	}

	void mainMenu()
	{
		system("cls");
		cout << "1. Список групп\n";
		cout << "2. Добавить группу\n";
		cout << "3. Редактировать группу\n";
		cout << "4. Удалить группу\n";
		cout << "5. Перейти в группу\n";

		int select = _getche();
		cout << endl;
		system("pause");

		if (select == 49)
		{
			vector<Group*> g = academy.getGroups();
			for (int i = 0; i < g.size(); i++)
			{
				cout << g[i]->getName() << endl;
			}
			system("pause");
		}

		if (select == 50)
		{
			string groupname;
			cout << "Enter group name.\n";
			cin >> groupname;
			int select1;
			cout << "Enter spec\n";
			cout << "1.- Programmers" << endl;
			cout << "2.- Designers" << endl;
			cout << "3.- SysAdmins" << endl;
			cin >> select1;
			Spec choose;
			if (select1 == 1)
				choose = Programmers;
			else if (select1 == 2)
				choose = Designers;
			else if (select1 == 3)
				choose = SysAdmins;
			academy.getGroups().push_back(new Group(choose, groupname));
		}

		if (select == 51)
		{
			string groupname;
			cin >> groupname;
			int select1;
			cin >> select1;
			Spec choose;
			if (select1 == 1)
				choose = Programmers;
			else if (select1 == 2)
				choose = Designers;
			else if (select1 == 3)
				choose = SysAdmins;

			bool menu_group = true;
			bool index = true;
			int t = 0;
			while (index)
			{
				if (t >= academy.getGroups().size())
				{
					menu_group = false;
					index = false;
					cout << "Group not found\n";
				}
				else if (academy.getGroup(t)->getName() == groupname)
				{
					/*academy.editing(t);
					index = false;
					cout << groupname + " was editing";*/
					academy.delGroup(t);
					index = false;
					string groupname;
					cin >> groupname;
					academy.getGroups().push_back(new Group(choose, groupname));
				}
				t++;
			}
		}

		if (select==52)
		{
			string groupname;
			cin >> groupname;
			bool menu_group = true;
			bool index = true;
			int t = 0;
			while (index)
			{
				if (t >= academy.getGroups().size())
				{
					menu_group = false;
					index = false;
					cout << "Group not found\n";
				}
				else if (academy.getGroup(t)->getName() == groupname)
				{
					academy.delGroup(t);
					index = false;
					cout << groupname + " was deleting";
				}
				t++;
			}
		}

		if (select == 53)
		{
			string groupname;
			cin >> groupname;
			groupMenu(groupname);
		}
	}


	void groupMenu(string groupname)
	{
		bool menu_student = true;
		bool index = true;
		int t = -1;
		while (index)
		{
			t++;
			if (t >= academy.getGroups().size())
			{
				menu_student = false;
				index = false;
				cout << "Group not found\n";
			}
			else if (academy.getGroup(t)->getName() == groupname)
			{
				index = false;
			}
		}

		Group* group = academy.search(groupname);
		if (group != nullptr)
		{
			system("cls");
			cout << "1. Список студентов\n";
			cout << "2. Добавить студента\n";
			cout << "3. Редактировать студента\n";
			cout << "4. Удалить студента\n";
			cout << "5. Показать инфо о студенте\n";

			int select = _getche();
			cout << endl;
			system("pause");

			if (select == 49)
			{
				vector<Student*> f = academy.getGroup(t)->getStudents();
				for (int i = 0; i < f.size(); i++)
				{
					cout << f[i]->getName() << endl;
				}
				system("pause");
			}

			if (select == 50)
			{
				string name, surname;
				cout << "Enter student name.\n";
				cin >> name;
				cout << "Enter student surname.\n";
				cin >> surname;
				int age, id;
				cout << "Enter student age.\n";
				cin >> age;
				cout << "Enter student id.\n";
				cin >> id;
				string phone;
				cout << "Enter student phone.\n";
				cin >> phone;
				double average;
				cout << "Enter student average.\n";
				cin >> average;


				academy.getGroup(t)->getStudents().push_back(new Student(name, surname, age, phone, average, id));
			}

			if (select == 51)
			{

			}

			if (select==52)
			{
				/*int id;
				cin >> id;
				bool menu_student = true;
				bool index = true;
				int t = -1;
				while (index)
				{
					if (t >= academy.getGroup(t)->getStudents().size())
					{
						menu_student = false;
						index = false;
						cout << "Group not found\n";
					}
					else if (getStudents()->getName() == groupname)
					{
						academy.delGroup(t);
						index = false;
						cout << groupname + " was deleting";
					}
					t++;
				}*/
			}

			if (select==53)
			{
				system("pause");
				string name;
				cout << "Введите имя студента" << endl;
				cin >> name;
				vector<Student*> f = academy.getGroup(t)->getStudents();
				for (int i = 0; i < f.size(); i++)
				{
					if (f[i]->getName()==name)
					{
						cout << f[i]->getId() << f[i]->getName() << f[i]->getSurname() << f[i]->getAge() << f[i]->getAverage() << f[i]->getPhone() << endl;
					}
				}
			}
		}


	}
};

/*
-----МЕНЮ------
1. Список групп
2. Добавить группу
3. Редактировать группу
4. Удалить группу
5. Перейти в группу

-----PVSDM_1712_RU----
1. Список студентов
2. Добавить студента
3. Редактировать студента
4. Удалить студента
5. Показать инфо о студенте
*/

void main()
{
	setlocale(LC_ALL, "rus");

	Academy acad;
	Program program(acad);
	while (true)
	{
		program.mainMenu();
	}
}
Tim_Tanos вне форума Ответить с цитированием
Ответ


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



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
сортировка/удаление/редактирование бинарного файла anshelika Общие вопросы C/C++ 1 15.05.2014 15:32
работа с бд access через excel.(редактирование, удаление и добавление) XROMAD Microsoft Office Access 5 25.07.2012 17:58
Редактирование и удаление полей через php в базе данных darkhbz PHP 19 15.06.2011 20:53
Удаление записи и редактирование существующей Cyber Общие вопросы C/C++ 3 16.02.2011 16:15
Добавление Удаление Редактирование через SQL beginner БД в Delphi 4 29.05.2007 17:52