Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
Рейтинг 5.00/4: Рейтинг темы: голосов - 4, средняя оценка - 5.00
2 / 2 / 2
Регистрация: 05.07.2012
Сообщений: 99

Не работают функции удаления и добавления данных в класс

27.10.2012, 22:48. Показов 754. Ответов 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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
 
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<dos.h>
#include<string.h>
#include <iostream>
 
# define one 49
# define two 50
# define three 51
# define four 52
 
#define Col_Count 5
#define Col_Cont 3
 
using namespace std;
 
int n=Col_Count;
int m=Col_Cont;
 
class Country
{
private:
    char Name_Country [30];
    float Naselenije;
    float Ploshad;
    char Forma_Pravl[30];
    
public:
    Country();
    ~Country();
    
    char *GetName_Country();
    float GetNaselenije();
    float GetPloshad();
    char *GetForma_Pravl();
        
    void SetName_Country(char *newVal);
    void SetNaselenije(float newVal);
    void SetPloshad(float newVal);
    void SetForma_Pravl(char *newVal);
    
    void Print();
 
};
 
Country::Country()
{
//  printf("Country Constructor without params used\n");
 
    strcpy(Name_Country,"");
    Naselenije = 0;
    Ploshad = 0;
    strcpy(Forma_Pravl,"");
}
 
Country::~Country()
{
//  printf("Country Destructor used\n");
    if(Name_Country != NULL)
   strcpy(Name_Country,"");
    
    if(Forma_Pravl != NULL)
   strcpy(Forma_Pravl,"");
}
 
void Country::Print()
{
    printf("%s | %10.2f | %9.2f | %s\n",Name_Country,Naselenije,Ploshad,Forma_Pravl);
}
 
char*Country::GetName_Country()
{   return this->Name_Country ;       }
 
float Country::GetNaselenije()
{   return Naselenije;     }
 
float Country::GetPloshad()
{   return Ploshad;        }
 
char* Country::GetForma_Pravl()
{   return this->Forma_Pravl;   }
 
void Country::SetName_Country(char *newVal)
{       strcpy(Name_Country,newVal);         }
 
void Country::SetNaselenije(float newVal)
{   this->Naselenije = newVal;          }
 
void Country::SetPloshad(float newVal)
{   this->Ploshad = newVal;          }
 
void Country::SetForma_Pravl(char *newVal)
{   strcpy(Forma_Pravl,newVal);     }
 
//_______________________________________________________________________
 
class Continent
{
 
private:
    char Name_Continent [30];
    Country ListCountries [Col_Count];
 
public:
    Country *m_Country;
 
    Continent();
    ~Continent();
    
    char *GetName_Continent ();
    void SetName_Continent (char newVal[]);
 
    Country GetListCountries (int i);
    void SetListCountries (char Name_Country[],float Naselenije, char Forma_Pravl[], float Ploshad,int i);
 
    void Create_Country(char* Name, float Plosh, float Nas, char *Form);
    void Delete_Country(char Name_Country[]);
 
    void Print_Cont();
};
 
void Continent::Print_Cont()
{
  printf("___________________________________________________________\n");
  printf("%35s\n",Name_Continent);
  printf("___________________________________________________________\n");
  printf("  Name_Country | Naselenije |  Ploshad  | Form_Pravlenija\n");
  printf("___________________________________________________________\n");
  
  for(int i=0;i<n;i++)
  {
  ListCountries[i].Print();
  }
}     
 
Continent::Continent()
{
 //    printf("\n \n Continent Constructor without params used\n\n");
    strcpy(this->Name_Continent,"");
}
 
Continent::~Continent()
{
//printf("\nContinent Destructor used\n\n");
    if(this->Name_Continent != NULL)
    strcpy(this->Name_Continent,"");
}
 
char *Continent::GetName_Continent ()
{    return this->Name_Continent;   }
 
void Continent::SetName_Continent (char newVal[])
{    strcpy(this->Name_Continent,newVal); }
 
 
Country Continent::GetListCountries (int i)
{   return ListCountries[i]; }
 
void Continent::SetListCountries (char *Name_Country,float Naselenije, char* Forma_Pravl, float Ploshad,int i)
{   
    ListCountries[i].SetName_Country(Name_Country);
    ListCountries[i].SetNaselenije(Naselenije);
    ListCountries[i].SetPloshad(Ploshad);
    ListCountries[i].SetForma_Pravl(Forma_Pravl);         
}
 
void Continent::Create_Country(char *Name, float Plosh, float Nas, char *Form)
{
printf("\n\n %s %f %f %s\n\n", Name,Plosh,Nas,Form);
 
  ListCountries[n].SetName_Country(Name);
  ListCountries[n].SetPloshad(Plosh);
  ListCountries[n].SetNaselenije(Nas);
  ListCountries[n].SetForma_Pravl(Form);
  
  printf("%s\n", ListCountries[n].GetName_Country());
    printf("%f\n", ListCountries[n].GetNaselenije());
      printf("%f\n", ListCountries[n].GetPloshad());
        printf("%s\n", ListCountries[n].GetForma_Pravl());
   n+=1;
   printf("\n\n");
   Print_Cont();
   
      printf("\n\n");
   
}
 
void Continent::Delete_Country(char Name_Country[])
{
int k,k1;
 
for(k=0;k<n;k++)
{
if(strcmp(ListCountries[k].GetName_Country(), (char*)Name_Country)==0)
 {
     for(k1=k+1;k<n;k++,k1++)
     {
       if(k1<n){
                ListCountries[k].SetName_Country(ListCountries[k1].GetName_Country());
                ListCountries[k].SetNaselenije(ListCountries[k1].GetNaselenije());
                ListCountries[k].SetPloshad(ListCountries[k1].GetPloshad());
                ListCountries[k].SetForma_Pravl(ListCountries[k1].GetForma_Pravl());
               }     
       else {break;}
     }
     // n-=1;
    
 }
}
Print_Cont();
}
//_______________________________________________________________________
 
class Obrabotchik
{
private:
    Continent List_Continents[Col_Cont];
 
public:
    Obrabotchik();
    ~Obrabotchik();
 
    Continent GetListContinents (int i);
    void CreateListContinents();
      
    void Sort_po_plosh(int i);
    void Sort_po_nasel(int i);  
 
};
     
Obrabotchik::Obrabotchik()
{
// printf("\n \n Obr Constructor without params used\n\n");
}
 
Obrabotchik::~Obrabotchik()
{
//printf("\nObr Destructor used\n\n");
}
 
 
Continent Obrabotchik::GetListContinents (int i)
{   return List_Continents[i];   }
 
void Obrabotchik::CreateListContinents()
{
 int i,j;
char c[20]={"Name_Continent_"},name[15]={"Name_Country_"},form[15]={"Form_Country_"},str[30],str1[30];
float x1,x2;
 
     for( i=0;i<Col_Cont;i++)
     {
     sprintf(str, "%s %d",c, i+1);
     List_Continents[i].SetName_Continent(str);
     
        for(j=0;j<Col_Count;j++)
       {
          sprintf(str, "%s %d",name, j+1);
          sprintf(str1, "%s %d",form, j+1);  
          x1=200.0+rand()/300.0;                                                 
          x2=200.0+rand()/300.0;                                                 
          List_Continents[i].SetListCountries(str,x1,str1,x2,j);
       }
       List_Continents[i].Print_Cont();
     }
}
 
void Obrabotchik::Sort_po_plosh(int k)
{
int i,j,imin=0;
 
float min_el=99000;
 
Country temp;
 
for(i=0;i<Col_Count;i++)
{
  imin=i;
  min_el=List_Continents[k].GetListCountries(i).GetPloshad();
  
  for(j=i+1;j<Col_Count;j++)
  {
    if(List_Continents[k].GetListCountries(j).GetPloshad()<min_el){
              imin=j;
              min_el=List_Continents[k].GetListCountries(j).GetPloshad();
            } 
  }
  
  temp.SetName_Country(List_Continents[k].GetListCountries(i).GetName_Country());
  temp.SetForma_Pravl(List_Continents[k].GetListCountries(i).GetForma_Pravl());
  temp.SetNaselenije(List_Continents[k].GetListCountries(i).GetNaselenije());
  temp.SetPloshad(List_Continents[k].GetListCountries(i).GetPloshad());
  
  List_Continents[k].SetListCountries(List_Continents[k].GetListCountries(imin).GetName_Country(),List_Continents[k].GetListCountries(imin).GetNaselenije(),List_Continents[k].GetListCountries(imin).GetForma_Pravl(),List_Continents[k].GetListCountries(imin).GetPloshad(),i);
 
  List_Continents[k].SetListCountries(temp.GetName_Country(),temp.GetNaselenije(),temp.GetForma_Pravl(),temp.GetPloshad(),imin);
   
}
}
     
void Obrabotchik::Sort_po_nasel(int k)
{
int i,j,imin=0;
 
float min_el=99000;
 
Country temp;
 
for(i=0;i<Col_Count-1;i++)
{
  imin=i;
  min_el=List_Continents[k].GetListCountries(i).GetNaselenije();
  
  for(j=i+1;j<Col_Count;j++)
  {
    if(List_Continents[k].GetListCountries(j).GetNaselenije()<min_el){
                                                                      imin=j;
                                                                      min_el=List_Continents[k].GetListCountries(j).GetNaselenije();
                                                                     } 
  }
  
  temp.SetName_Country(List_Continents[k].GetListCountries(i).GetName_Country());
  temp.SetForma_Pravl(List_Continents[k].GetListCountries(i).GetForma_Pravl());
  temp.SetNaselenije(List_Continents[k].GetListCountries(i).GetNaselenije());
  temp.SetPloshad(List_Continents[k].GetListCountries(i).GetPloshad());
  
  List_Continents[k].SetListCountries(List_Continents[k].GetListCountries(imin).GetName_Country(),List_Continents[k].GetListCountries(imin).GetNaselenije(),List_Continents[k].GetListCountries(imin).GetForma_Pravl(),List_Continents[k].GetListCountries(imin).GetPloshad(),i);
 
  List_Continents[k].SetListCountries(temp.GetName_Country(),temp.GetNaselenije(),temp.GetForma_Pravl(),temp.GetPloshad(),imin);
   
}
}
 
 
int main()
{
    {
    
     int i,key,cont;
     char *a,*f;
     float s=12,p=32;
 
 a=new char [200];
 f=new char [200];
 char b[30]={"Name_Country_ 2"};
 strcpy(a,"Name_Country_ 1");
 strcpy(f,"Form");
 
     Obrabotchik A;
     A.CreateListContinents();
/*
for(i=0;i<n;i++)
A.GetListContinents(i).Print_Cont();
 */
A.GetListContinents(0).Delete_Country(a);
 
//A.GetListContinents(0).Create_Country(a,s,p,f);
 
A.GetListContinents(0).Print_Cont();
 
    }
    system("pause");
    return 0;
}
0
Programming
Эксперт
39485 / 9562 / 3019
Регистрация: 12.04.2006
Сообщений: 41,671
Блог
27.10.2012, 22:48
Ответы с готовыми решениями:

Не корректно работают функции добавления абитуриента, редактирования, удаления
Еще меня интересует как написать запрос к базе чтоб редактировать строку, например когда я написал имя фамилию и сделал ошибку в фамилии то...

Класс содержащий массив структур и функции добавления, удаления и поиска
Помогите пожалуйста нужно создать два класса один базовый в котором будут три приватных поля а второй будет содержать массив из этих трёх...

Функции добавления, удаления данных в массиве.
Есть код в котором создается новый массив, помогите написать функции добавления, удаления и вывода инфы. void Add(Array *arr, double...

2
2393 / 1913 / 763
Регистрация: 27.07.2012
Сообщений: 5,557
27.10.2012, 23:40
Какие именно функции за это отвечают?
0
2 / 2 / 2
Регистрация: 05.07.2012
Сообщений: 99
28.10.2012, 17:32  [ТС]
John Prick, Delete_Country и Create_Country
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
inter-admin
Эксперт
29715 / 6470 / 2152
Регистрация: 06.03.2009
Сообщений: 28,500
Блог
28.10.2012, 17:32
Помогаю со студенческими работами здесь

Определить структуру данных, поддерживающую функции добавления, удаления и вывода элементов
Помогите написать код: Определить динамическую структуру данных – отсортированный однонаправленный список, поддерживающую функции...

Создать класс для удаления и добавления записей в БД
Привет дорогие форумчане помогите разбираться с одну задачу : Написать класс пользователей в vb.net для добавление, удаление в бд У...

Описать класс, реализующий бинарное дерево c возможностью добавления и удаления элементов
Описать класс, реализующий бинарное дерево, обладающее возможностью добав- ления новых элементов, удаления существующих, поиска элемента...

Стеки, функции добавления и удаления элементов
Программа на стеки выводит на экран 9876543210 ..помогите сделать так, чтобы можно было вводить вручную, удалять элементы из стека,...

Написать функции для добавления/удаления элемента в очередь
Помогите пожалуйста написать написать программу, реализующую работу очереди использую простые функции . Нужно написать функции для...


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

Или воспользуйтесь поиском по форуму:
3
Ответ Создать тему
Новые блоги и статьи
Thinkpad X220 Tablet — это лучший бюджетный ноутбук для учёбы, точка.
Programma_Boinc 23.12.2025
Thinkpad X220 Tablet — это лучший бюджетный ноутбук для учёбы, точка. Рецензия / Мнение/ Перевод https:/ / **********/ gallery/ thinkpad-x220-tablet-porn-gzoEAjs . . .
PhpStorm 2025.3: WSL Terminal всегда стартует в ~
and_y87 14.12.2025
PhpStorm 2025. 3: WSL Terminal всегда стартует в ~ (home), игнорируя директорию проекта Симптом: После обновления до PhpStorm 2025. 3 встроенный терминал WSL открывается в домашней директории. . .
Как объединить две одинаковые БД Access с разными данными
VikBal 11.12.2025
Помогите пожалуйста !! Как объединить 2 одинаковые БД Access с разными данными.
Новый ноутбук
volvo 07.12.2025
Всем привет. По скидке в "черную пятницу" взял себе новый ноутбук Lenovo ThinkBook 16 G7 на Амазоне: Ryzen 5 7533HS 64 Gb DDR5 1Tb NVMe 16" Full HD Display Win11 Pro
Музыка, написанная Искусственным Интеллектом
volvo 04.12.2025
Всем привет. Некоторое время назад меня заинтересовало, что уже умеет ИИ в плане написания музыки для песен, и, собственно, исполнения этих самых песен. Стихов у нас много, уже вышли 4 книги, еще 3. . .
От async/await к виртуальным потокам в Python
IndentationError 23.11.2025
Армин Ронахер поставил под сомнение async/ await. Создатель Flask заявляет: цветные функции - провал, виртуальные потоки - решение. Не threading-динозавры, а новое поколение лёгких потоков. Откат?. . .
Поиск "дружественных имён" СОМ портов
Argus19 22.11.2025
Поиск "дружественных имён" СОМ портов На странице: https:/ / norseev. ru/ 2018/ 01/ 04/ comportlist_windows/ нашёл схожую тему. Там приведён код на С++, который показывает только имена СОМ портов, типа,. . .
Сколько Государство потратило денег на меня, обеспечивая инсулином.
Programma_Boinc 20.11.2025
Сколько Государство потратило денег на меня, обеспечивая инсулином. Вот решила сделать интересный приблизительный подсчет, сколько государство потратило на меня денег на покупку инсулинов. . . .
Ломающие изменения в C#.NStar Alpha
Etyuhibosecyu 20.11.2025
Уже можно не только тестировать, но и пользоваться C#. NStar - писать оконные приложения, содержащие надписи, кнопки, текстовые поля и даже изображения, например, моя игра "Три в ряд" написана на этом. . .
Мысли в слух
kumehtar 18.11.2025
Кстати, совсем недавно имел разговор на тему медитаций с людьми. И обнаружил, что они вообще не понимают что такое медитация и зачем она нужна. Самые базовые вещи. Для них это - когда просто люди. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2025, CyberForum.ru