Помогите, доделать.
Класс Statist создает объект, а класс Control должен считать из этого объекта информацию и вывести на экран. Не соображу как...помогите
[HTML]
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
class Menu_abs
{
public:
void printmenu ();
}
class Control_abs
{
public:
virtual void Read_Info ()=0;
virtual void Get_Etalon ()=0;
virtual void Compare_Etalon ()=0;
};
class Statist
{
private:
int age, count;
int *age_group;
char name;
public:
Statist (char name);
};
class Control: public Control_abs: public Statist
{
public:
void Read_Info (Statist *a);
void Get_Etalon (Statist *a);
void Compare_Etalon (Statist *a, Statist *b);
};
class Menu: public Menu_abs
{
public:
void printmenu ();
};
class My
{
public:
void Run ();
};
Statist::Statist(char name);
{
FILE *f;
f=fopen(name,"r");
if(f==NULL)
{
cout<<"Error!";
getch();
exit(0);
}
fscanf (f, "d", &age);
fscanf (f, "d", &count);
age group[count];
for (int i=0;i<count;i++)
fscanf (f, "d", &age_group);
}
void menu: rintmenu()
{
cout<<"Menu: "<<endl;
printf("1) \n");
printf("2) \n");
printf("3) \n");
printf("4) \n");
printf("5) \n");
printf("6) \n");
printf("7) Exit \n");
}
void Control::Red_Info (Statist *a)
{
int *x;
x= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group==1)
x[0]++;
if(a.age_group==2)
x[1]++;
if(a.age_group==3)
x[2]++;
if(a.age_group==4)
x[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<x[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<x[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<x[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<x[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] x;
}
void Control::Get_Etalon (Statist *a)
{
int *y;
y= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group==1)
y[0]++;
if(a.age_group==2)
y[1]++;
if(a.age_group==3)
y[2]++;
if(a.age_group==4)
y[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<y[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<y[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<y[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<y[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] y;
}
void Control::Compare_Etalon (Statist *a, Statist *b)
{
int *x;
int *y;
x= new int [4];
y= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group==1)
x[0]++;
if(a.age_group[i]==2)
x[1]++;
if(a.age_group[i]==3)
x[2]++;
if(a.age_group[i]==4)
x[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<x[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<x[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<x[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<x[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
for (int i=0;i<b.count;i++)
{
if(b.age_group[i]==1)
y[0]++;
if(b.age_group[i]==2)
y[1]++;
if(b.age_group[i]==3)
y[2]++;
if(b.age_group[i]==4)
y[3]++;
}
cout<<"Dlya gruppi "<<b.age<<endl;
cout<<y[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<y[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<y[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<y[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] x;
delete [] y;
}
void My::Run ()
{
cout<<"Vvedite imya file:"<<endl;
char name;
cin>>name;
Statist *Q1;
Q1=new Statist(name);
int w;
Menu *Z1;
Z1=new Menu();
Z1 -> printmenu();
Control *A1;
A1=new Control();
cin<<w;
while (w!=283)
{
w==bioskey (0);
if (w==561)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==818)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1075)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1332)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1589)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1846)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==2103)
{
getch ();
exit (0);
}
}
}
void main ()
{
My obj;
obj.Run ();
}
[/HTML]
C++ ООП
Модераторы: Hawk, Romeo, Absurd, DeeJayC, WinMain
- Romeo
- Сообщения: 3091
- Зарегистрирован: 02 мар 2004, 17:25
- Откуда: Крым, Севастополь
- Контактная информация:
Код плохо форматирован, как следствие трудно читаем, потому разбирать его у меня нет времени. Скажи конкретно что у тебя не получается - помогу.
Entites should not be multiplied beyond necessity @ William Occam
---
Для выделения С++ кода используйте конструкцию [ code=cpp ] Код [ /code ] (без пробелов)
---
Сообщение "Спасибо" малоинформативно. Благодарность правильнее высказать, воспользовавшись кнопкой "Reputation" в виде звёздочки, расположенной в левом нижнем углу рамки сообщения.
---
Для выделения С++ кода используйте конструкцию [ code=cpp ] Код [ /code ] (без пробелов)
---
Сообщение "Спасибо" малоинформативно. Благодарность правильнее высказать, воспользовавшись кнопкой "Reputation" в виде звёздочки, расположенной в левом нижнем углу рамки сообщения.
Подскажи как правильно передать классу Б объект класса А чтобы можно было методами класса Б считать поля класса А из объекта
Вот я тут немного подделал, разбил прогу на три файла. Посмотрите плиз. Там всего две ошибки. Как их исправить?
Код: Выделить всё
//первый файл
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
class Menu_abs
{
public:
void printmenu ();
}
class Control_abs
{
public:
virtual void Read_Info ();
virtual void Get_Etalon ();
virtual void Compare_Etalon ();
};
class Statist
{
public:
int age, count;
int *age_group;
public:
Statist ();
};
class Control:: public Control_abs
{
public:
void Read_Info (Statist &a);
void Get_Etalon (Statist &a);
void Compare_Etalon (Statist &a, Statist &b);
};
class MenuT:: public Menu_abs
{
public:
void printmenu ();
};
class My
{
public:
void Run ();
};
//второй файл
void MenuT: :p rintmenu()
{
cout<<"Menu: "<<endl;
printf("1) \n");
printf("2) \n");
printf("3) \n");
printf("4) \n");
printf("5) Help \n");
printf("6) Clear screen \n");
printf("7) Exit \n");
}
void Control::Read_Info (Statist &a)
{
int *x;
x= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group[i]==1)
x[0]++;
if(a.age_group[i]==2)
x[1]++;
if(a.age_group[i]==3)
x[2]++;
if(a.age_group[i]==4)
x[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<x[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<x[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<x[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<x[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] x;
}
void Control::Get_Etalon (Statist &a)
{
int *y;
y= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group[i]==1)
y[0]++;
if(a.age_group[i]==2)
y[1]++;
if(a.age_group[i]==3)
y[2]++;
if(a.age_group[i]==4)
y[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<y[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<y[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<y[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<y[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] y;
}
void Control::Compare_Etalon (Statist &a, Statist &b)
{
int *x;
int *y;
x= new int [4];
y= new int [4];
for (int i=0;i<a.count;i++)
{
if(a.age_group[i]==1)
x[0]++;
if(a.age_group[i]==2)
x[1]++;
if(a.age_group[i]==3)
x[2]++;
if(a.age_group[i]==4)
x[3]++;
}
cout<<"Dlya gruppi "<<a.age<<endl;
cout<<x[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<x[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<x[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<x[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
for (i=0;i<b.count;i++)
{
if(b.age_group[i]==1)
y[0]++;
if(b.age_group[i]==2)
y[1]++;
if(b.age_group[i]==3)
y[2]++;
if(b.age_group[i]==4)
y[3]++;
}
cout<<"Dlya gruppi "<<b.age<<endl;
cout<<y[0]<<" chelovek otvetilo pervii variant otveta"<<endl;
cout<<y[1]<<" chelovek otvetilo vtoroi variant otveta"<<endl;
cout<<y[2]<<" chelovek otvetilo tretii variant otveta"<<endl;
cout<<y[3]<<" chelovek otvetilo chetvertii variant otveta"<<endl;
delete [] x;
delete [] y;
}
Statist::Statist()
{
FILE *f;
f=fopen("my.txt","r");
if(f==NULL)
{
cout<<"Error!";
getch();
exit(0);
}
fscanf (f, "d", &age);
fscanf (f, "d", &count);
int *age_group;
age_group=new int[count];
for (int i=0;i<count;i++)
fscanf (f, "d", &age_group[i]);
}
void My::Run ()
{
Statist *Q1;
Q1=new Statist();
int w;
MenuT *Z1;
Z1=new MenuT();
Z1 -> printmenu();
Control *A1;
A1=new Control();
cin>>w;
while (w!=283)
{
w=bioskey (0);
if (w==561)
{
clrscr ();
Z1 -> printmenu ();
A1 -> Read_Info (Q1);
}
if (w==818)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1075)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1332)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1589)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==1846)
{
clrscr ();
Z1 -> printmenu ();
}
if (w==2103)
{
getch ();
exit (0);
}
}
}
//третий файл
void main ()
{
My obj;
obj.Run ();
}