Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <Windows.h>
- #include <string>
- #include <clocale>
- using namespace std;
- int iq_c = 0;
- int mid_iq = 0;
- const string names[] = { "Верос Нерети", "Трерас Дрес", "Тирер Белвайн", "Арон Андарен", "Эд Теман", "Энар Релет", "Фелен Марион", "Лларар Берелот", "Рерон Ринит", "Мавон Дреним" };
- class student{
- public:
- string FIO = names[rand() % 10];
- int iq = 0;
- student(){ iq = rand() % 100; }
- student(int i){ iq = i; }
- student(string s, int i){ FIO = s; iq = i; }
- student(string s){ FIO = s; iq = rand() % 100; }
- void show(){
- cout << "\n" << FIO << " : " << iq;
- }
- };
- struct element{
- student* data;
- element* next;
- };
- class group{
- private:
- element *list, *cur, *temp;
- int current = 0;
- public:
- void add(int n){
- for (int i = 0; i < n; i++) add();
- }
- void add(){
- temp = new element();
- temp->data = new student();
- temp->next = list->next;
- list->next = temp;
- }
- void show(){
- temp = list->next;
- while (temp){
- temp->data->show();
- temp = temp->next;
- }
- }
- void show(int n)
- {
- if (n > count()||n<=0)
- {
- cout << "\n\n >>> !!! tu ma4 h04esh !!! ERROR!!! <<< \n";
- }
- else
- {
- current = n;
- temp = list->next;
- int i = 1;
- while (i != n)
- {
- i++;
- temp = temp->next;
- }
- temp->data->show();
- }
- }
- int count()
- {
- int i = 0;
- temp = list->next;
- while (temp){
- i++;
- temp = temp->next;
- }
- return i;
- }
- void del(){
- if (list->next){
- temp = list->next;
- list->next = list->next->next;
- delete temp;
- }
- }
- void del(int n){
- for (int i = 0; i < n; i++) del();
- }
- void middle_iq(){
- float s = 0;
- float k = 0;
- temp = list->next;
- while (temp){
- s += temp->data->iq;
- k++;
- temp = temp->next->next;
- }
- show();
- cout << endl;
- cout << "Middle iq : " << s / k << endl;
- }
- void more_iq(int n){
- int c = 0;
- temp = list->next;
- while (temp){
- if (temp->data->iq > n) c++;
- temp = temp->next->next;
- }
- show();
- cout << endl;
- cout << "Количество студентов с iq выше заданного : " << c;
- }
- void next()
- {
- current++;
- show(current);
- }
- void prev()
- {
- current--;
- show(current);
- }
- void del_cert(int n)
- {
- if (n > count() || n <= 0)
- {
- cout << "\n\n >>> !!! tu ma4 h04esh !!! ERROR!!! <<< \n";
- }
- else
- {
- temp = list->next;
- int i = 1;
- while (i != n)
- {
- i++;
- temp = temp->next;
- }
- }
- del();
- }
- void add_n_element(int n){
- if (n <= 0 || n > count() + 1) {
- cout << "\n !!! tu ma4 h04esh !!! EPPOP !!! <<< \n";
- }
- else if (n == 1) {
- add();
- }
- else {
- current = n;
- int i = 1;
- cur = list->next;
- while (i < n - 1) {
- i++;
- cur = cur->next;
- }
- temp = new element();
- string FIO = names[rand() % 10];
- temp->data = new student(FIO);
- temp->next = cur->next;
- cur->next = temp;
- }
- show();
- }
- group(){
- list = new element();
- list->data = NULL;
- list->next = NULL;
- }
- group(int n){
- list = NULL;
- add(n);
- }
- void tanosing(){
- while (list) del();
- }
- ~group(){
- while (list) del();
- }
- };
- int main(){
- setlocale(LC_CTYPE, "Russian");
- group* G21 = new group();
- int choose;
- int n;
- do{
- cout << "1-add 2-add(n) 3-del 4-del(n) 5-show 6-shel4ok 7-student number 8-mid_iq 9-more_iq(n) 10-del(x) 0-exit\n";
- cout << "11 show(n) 12-prev 13-next 14-del_cert 15-add_n_element \n";
- cout << "? >> ";
- cin >> choose;
- system("CLS");
- switch (choose){
- case 1: G21->add(); G21->show(); break;
- case 2: cin >> n; G21->add(n); G21->show(); break;
- case 3: G21->del(); G21->show(); break;
- case 4: cin >> n; G21->del(n); G21->show(); break;
- case 5: G21->show(); break;
- case 6: G21->tanosing(); break;
- case 7: cout << "Количество студентов: "; cout << G21->count(); break;
- case 8: G21->middle_iq(); break;
- case 9: cin >> n; G21->more_iq(n); break;
- case 11: cin >> n; G21->show(n); break;
- case 12: G21->prev(); break;
- case 13: G21->next(); break;
- case 14: cin >> n; G21->del_cert(n); G21->show(); break;
- case 15: cin >> n; G21->add_n_element(n); break;
- }
- cout << "\n================================\n";
- } while (choose != 0);
- cout << "\n\n\n\n";
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement