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

Перевести с Java

22.05.2016, 11:44. Показов 444. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Помогите пожалуйста перевести задание на с++(на джава все просто делается,а с ++ хз как и что)
Java
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
public class People {
    private Name name;
    private Date birthDate;
 
    public People(Name name, Date birthDate) {
        this.name = name;
        this.birthDate = birthDate;
    }
 
    public Name getName() {
        return name;
    }
 
    public Date getBirthDate() {
        return birthDate;
    }
 
    @Override
    public String toString(){
        return name.toString()+ ", дата рождения: " +birthDate.toString();
    }
 
    static void sortByName(People[] peoples){
        int min_index;
        for (int i = 0; i < peoples.length-1; i++) {
            min_index=i;
            for (int j = i+1; j < peoples.length; j++) {
                int flag=peoples[min_index].getName().getFirstName().compareToIgnoreCase(peoples[j].getName().getFirstName());
                if (flag>0){
                    min_index=j;
                }
                else if (flag==0){
                    flag=peoples[min_index].getName().getSecondName().compareToIgnoreCase(peoples[j].getName().getSecondName());
                    if (flag>0){
                        min_index=j;
                    }
                    else if (flag==0){
                        flag=peoples[min_index].getName().getLastName().compareToIgnoreCase(peoples[j].getName().getLastName());
                        if (flag>0){
                            min_index=j;
                        }
                    }
                }
            }
            People buf=peoples[i];
            peoples[i]=peoples[min_index];
            peoples[min_index]=buf;
        }
    }
 
    static void sortByDate(People[] peoples){
        int max_index;
        for (int i = 0; i < peoples.length-1; i++) {
            max_index=i;
            for (int j = i + 1; j < peoples.length; j++) {
                int dateMax=peoples[max_index].getBirthDate().getYear();
                int dateJ=peoples[j].getBirthDate().getYear();
                if (dateMax<dateJ){
                    max_index=j;
                }
                else if (dateMax==dateJ){
                    dateMax=peoples[max_index].getBirthDate().getMonth();
                    dateJ=peoples[j].getBirthDate().getMonth();
                    if (dateMax<dateJ){
                        max_index=j;
                    }
                    else if (dateMax==dateJ){
                        dateMax=peoples[max_index].getBirthDate().getDay();
                        dateJ=peoples[j].getBirthDate().getDay();
                        if (dateMax<dateJ){
                            max_index=j;
                        }
                    }
                }
            }
            People buf=peoples[i];
            peoples[i]=peoples[max_index];
            peoples[max_index]=buf;
        }
 
    }
 
    static class Name{
        private String firstName;
        private String secondName;
        private String lastName;
 
        public Name(String firstName,String secondName, String lastName){
            this.firstName=firstName;
            this.secondName=secondName;
            this.lastName=lastName;
        }
 
        public String getFirstName() {
            return firstName;
        }
 
        public String getSecondName() {
            return secondName;
        }
 
        public String getLastName() {
            return lastName;
        }
 
        @Override
        public String toString(){
            return firstName+ " " +secondName+ " " +lastName;
        }
    }
 
    static class Date{
        private int year;
        private int month;
        private int day;
 
        public Date(int year,int month,int day){
            if(year<0)throw new IllegalArgumentException("Неверно введен год!");
            if (month<1 || month>12)throw new IllegalArgumentException("Неверно введен месяц!");
            this.year=year;
            this.month=month;
            switch (month){
                case 1:
                case 3:
                case 5:
                case 7:
                case 8:
                case 10:
                case 12:
                    if (day<1 || day>31)throw new IllegalArgumentException("Неверно введен день!");
                    this.day=day;
                    break;
                case 4:
                case 6:
                case 9:
                case 11:
                    if (day<1 || day>30)throw new IllegalArgumentException("Неверно введен день!");
                    this.day=day;
                    break;
                default: if (day>=1 && day<29 ){
                    this.day=day;
                    break;
                }
                    else if (day==29 && ((year%4 == 0 && year%100 != 0) || (year%400 == 0))){
                    this.day=day;
                    break;
                }
                    else throw new IllegalArgumentException("Неверно введен день!");
            }
 
        }
 
        public int getYear() {
            return year;
        }
 
        public int getMonth() {
            return month;
        }
 
        public int getDay() {
            return day;
        }
 
        @Override
        public String toString(){
            return year+ " / " +month+ " / " +day;
        }
    }
 
    public static void main(String[] args) {
        People[] peoples = {
                new People(new Name("A","B","C"),new Date(2000,01,01)),
                new People(new Name("A","B","C"),new Date(1996,01,02)),
                new People(new Name("A","B","D"),new Date(1996,02,02)),
                new People(new Name("A","C","C"),new Date(2000,02,02)),
                new People(new Name("B","B","C"),new Date(2000,01,02)),
                new People(new Name("AA","B","C"),new Date(1996,01,01)),
                new People(new Name("AB","B","C"),new Date(2000,01,01))
        };
        for (People p:peoples
             ) {
            System.out.println(p);
        }
        System.out.println("\n AFTER SORTING BY DATE: \n");
        sortByDate(peoples);
        for (People p:peoples
                ) {
            System.out.println(p);
        }
        System.out.println("\n AFTER SORTING BY NAME: \n");
        sortByName(peoples);
        for (People p:peoples
                ) {
            System.out.println(p);
        }
        System.out.println(new Date(2016,2,1));
    }
}
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
22.05.2016, 11:44
Ответы с готовыми решениями:

перевести в Java
uses crt; const nmax=15; var a:array of integer; m,n,i,j,p,k:byte; f:boolean; begin...

Перевести на Java
Помогите пожалуста перевести код с Pascal на Java. Очень нужно на завтра: uses crt; const n=5;...

Перевести С++ на Java
Здравствуйте. Есть код, который нужно переписать на Java. Но я не совсем понимаю один момент....

Перевести в Java
program task; uses crt; var k: word; fak: longint; chis, slag, sum, x: real; t:char; begin...

0
22.05.2016, 11:44
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
22.05.2016, 11:44
Помогаю со студенческими работами здесь

Перевести на JAVA
Помогитеfunction SearchPath(ni) { if (ni&gt;40) return -1; for (cell in map_cell) { ...

Перевести из Java на C++
Всем доброй ночи! Я уже разок обращалась за помощью на этот форум, и сейчас, набравшись немножко...

Перевести с С++ на Java
Не поможыте перевести на джава?? #include &lt;limits.h&gt; #include&lt;stdio.h&gt; #include&lt;stdlib.h&gt;...

Перевести в Java
#include &lt;iostream&gt; #include &lt;algorithm&gt; using namespace std; int _tmain(int argc, _TCHAR*...


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

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