Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/5: Рейтинг темы: голосов - 5, средняя оценка - 5.00
-12 / 0 / 0
Регистрация: 23.11.2016
Сообщений: 19
1

Разработать класс "Очередь"

14.06.2019, 06:06. Показов 983. Ответов 2
Метки c# (Все метки)

Author24 — интернет-сервис помощи студентам
Перепишите мой код с C# на C++, пожалуйста
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System;
using System.Collections.Generic;
namespace Queue
{
    class MyQueue
    {
        Element[] arr;
        public MyQueue(Element[] arr) { this.arr = arr; this.Lenght = arr.Length; }
        int lenght;
        public int Lenght { get { return lenght; } set { lenght = value; } }
        public void Enqueue(Element elementToAdd)
        {
            Lenght++;
            Element[] newArr = new Element[arr.Length + 1];
            for (int c = 0; c < newArr.Length - 1; c++) { newArr[c] = arr[c]; }
            newArr[Lenght - 1] = elementToAdd;
            arr = newArr;
        }
        public void Dequeue()
        {
            Element[] newArr = new Element[arr.Length - 1];
            for (int c = 0; c < arr.Length - 1; c++) { newArr[c] = arr[c + 1]; }
            this.lenght--;
            arr = newArr;
        }
        public string GetElementForIndex(int index)
        {
            try { return arr[index].ID.ToString(); } catch (NullReferenceException) { return "Doesn't exist"; }
 
        }
    }
    class Element
    {
        string id;
        public string ID
        {
            get { return id; }
            set { id = value; }
        }
        public Element(string elementId) { id = elementId; }
        public Element(long elementId) { id = Convert.ToString(elementId); }
        public Element(float elementId) { id = Convert.ToString(elementId); }
        public Element(bool elementId) { id = Convert.ToString(elementId); }
        public Element(double elementId) { id = Convert.ToString(elementId); }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Element[] arr = { new Element("5"), new Element(true), new Element(2.34), new Element(1.3f), new Element(2.34) };
            MyQueue queue = new MyQueue(arr);
            queue.Enqueue(new Element("4"));
            Console.WriteLine(queue.GetElementForIndex(2));
            for (int a = 0; a < queue.Lenght; a++) { Console.Write(queue.GetElementForIndex(a) + " "); }
            Console.WriteLine();
            queue.Dequeue();
            Console.WriteLine(queue.GetElementForIndex(0));
            Console.WriteLine(queue.GetElementForIndex(1));
            for (int a = 0; a < queue.Lenght; a++) { Console.Write(queue.GetElementForIndex(a) + " "); }
            Console.WriteLine();
            Console.WriteLine("Queue lenght = " + queue.Lenght);
        }
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
14.06.2019, 06:06
Ответы с готовыми решениями:

Класс: Разработать абстрактный класс класс Point для задания координаты...
Всем привет, помогите пожалуйста решить задачу, я уже всю голову сломал, не знаю как решить... ...

Создайте класс, в котором есть ostream& operator<<. Класс должен содержать очередь с приоритетом
Создайте класс, в котором есть ostream&amp; operator&lt;&lt;. Класс должен содержать очередь с приоритетом....

Разработать тип данных очередь
Разработать тип данных очередь (struct Queue) динамически растущий для хранения символьных...

Создать класс СПИСОК целых чисел. Разработать класс СТЕК
&quot;Создать класс СПИСОК целых чисел. Разработать класс СТЕК, который вмещает объект класса СПИСОК....

2
-12 / 0 / 0
Регистрация: 23.11.2016
Сообщений: 19
14.06.2019, 06:18  [ТС] 2
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//List<T>. Что-то вроде того.
 
using System;
namespace Queue
{
    class MyQueue
    {
        Element[] arr;
        public MyQueue(Element[] arr) { this.arr = arr; this.Lenght = arr.Length; }
        int lenght;
        public int Lenght { get { return lenght; } set { lenght = value; } }
        public void Enqueue(Element elementToAdd)
        {
            Lenght++;
            Element[] newArr = new Element[arr.Length + 1];
            for (int c = 0; c < newArr.Length - 1; c++) { newArr[c] = arr[c]; }
            newArr[Lenght - 1] = elementToAdd;
            arr = newArr;
        }
        public void Dequeue()
        {
            Element[] newArr = new Element[arr.Length - 1];
            for (int c = 0; c < arr.Length - 1; c++) { newArr[c] = arr[c + 1]; }
            this.lenght--;
            arr = newArr;
        }
        public string GetElementForIndex(int index)
        {
            try { return arr[index].ID.ToString(); } catch (NullReferenceException) { return "Doesn't exist"; }
 
        }
    }
    class Element
    {
        string id;
        public string ID
        {
            get { return id; }
            set { id = value; }
        }
        public Element(string elementId) { id = elementId; }
        public Element(long elementId) { id = Convert.ToString(elementId); }
        public Element(float elementId) { id = Convert.ToString(elementId); }
        public Element(bool elementId) { id = Convert.ToString(elementId); }
        public Element(double elementId) { id = Convert.ToString(elementId); }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Element[] arr = { new Element("5"), new Element(true), new Element(2.34), new Element(1.3f), new Element(2.34) };
            MyQueue queue = new MyQueue(arr);
            queue.Enqueue(new Element("4"));
            Console.WriteLine(queue.GetElementForIndex(2));
            for (int a = 0; a < queue.Lenght; a++) { Console.Write(queue.GetElementForIndex(a) + " "); }
            Console.WriteLine();
            queue.Dequeue();
            Console.WriteLine(queue.GetElementForIndex(0));
            Console.WriteLine(queue.GetElementForIndex(1));
            for (int a = 0; a < queue.Lenght; a++) { Console.Write(queue.GetElementForIndex(a) + " "); }
            Console.WriteLine();
            Console.WriteLine("Queue lenght = " + queue.Lenght);
        }
    }
}
0
Модератор
Эксперт С++
13507 / 10757 / 6412
Регистрация: 18.12.2011
Сообщений: 28,712
14.06.2019, 07:37 3
Я в 100500 раз хочу сказать: зачем переводить, если на форуме уже все есть.
Например
Разработать тип данных очередь на односвязном списке
0
14.06.2019, 07:37
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
14.06.2019, 07:37
Помогаю со студенческими работами здесь

Разработать класс Man (человек) и производный класс Student (студент). Описать атрибуты.
Разработать класс Man (человек) и производный класс Student (студент). Описать атрибуты.

Разработать класс Tableware (посуда) и производный класс Dish (тарелка). Описать атрибуты
Разработать класс Tableware (посуда) и производный класс Dish (тарелка). Описать атрибуты.

Разработать приложение, имитирующее очередь печати принтера
Разработать приложение, имитирующее очередь печати принтера. Должны быть клиенты, посылающие...

Разработать программу, результатом которой является очередь
Разработать программу, результатом которой является очередь, сформирована на основе...

Разработать тип данных очередь на односвязном списке
Разработать тип данных очередь на односвязном списке (struct List) для хранения вещественных...

Класс-очередь
Вечер добрый! Собственно задание: Определить и реализовать класс. Определить и реализовать...

класс очередь
реализовать класс очередь, написать прототипы необходимых функций-членов к нему, 2 из них...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru