Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Вопросы по программированию на C/С++

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

Levenyatko O

Newbie
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
помогите найти ошибку в коде.
два класса страна и континент. класс-обработчик должен сортировать страны выбранного континента по населению и площади.  
не работают функции Create_Country Delete_Country
 
 
#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;
    float Naselenije;
    float Ploshad;
    char *Forma_Pravl;
    
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");
Name_Country=new char[200];
Forma_Pravl=new char[200];
    strcpy(Name_Country,"");
    Naselenije = 0;
    Ploshad = 0;
    strcpy(Forma_Pravl,"");
}
 
Country::~Country()
{
//    printf("Country Destructor used\n");
    if(Name_Country != NULL)
 //  strcpy(Name_Country,"");
 delete[]Name_Country;
     
    if(Forma_Pravl != NULL)
//   strcpy(Forma_Pravl,"");
delete []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 this->Naselenije;     }
 
float Country::GetPloshad()
{    return this->Ploshad;        }
 
char* Country::GetForma_Pravl()
{    return this->Forma_Pravl;   }
 
void Country::SetName_Country(char *newVal)
{        strcpy(this->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(this->Forma_Pravl,newVal);     }
 
//_______________________________________________________________________
 
class Continent
{
 
private:
    char *Name_Continent;
    Country ListCountries[10];
 
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");
    Name_Continent=new char[256];
    strcpy(this->Name_Continent,"");
}
 
Continent::~Continent()
{
//printf("\nContinent Destructor used\n\n");
    if(this->Name_Continent != NULL)
    //strcpy(this->Name_Continent,"");
    delete []Name_Continent;
}
 
char *Continent::GetName_Continent ()
{    return this->Name_Continent;   }
 
void Continent::SetName_Continent (char *newVal)
{     strcpy(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)
{
  ListCountries[n].SetName_Country(Name);
  ListCountries[n].SetPloshad(Plosh);
  ListCountries[n].SetNaselenije(Nas);
  ListCountries[n].SetForma_Pravl(Form);
 
   n+=1;  
}
 
void Continent::Delete_Country(char *Name_Country)
{
int k,k1;
 
for(k=0;k<n;k++)
{
if(strcmp(ListCountries[k].GetName_Country(), 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=(float)200+rand()/300;                                                  
          x2=(float)200+rand()/300;                                                  
          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;
     char *a,*f;
     float s=12,p=32;
 
 a=new char [200];
 f=new char [200];
 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);
 
for(i=0;i<m;i++)
A.GetListContinents(i).Print_Cont();
 
    }
    system("pause");
    return 0;
}
 

Всего записей: 1 | Зарегистр. 06-11-2012 | Отправлено: 15:05 06-11-2012
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Вопросы по программированию на C/С++


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru