Программа должна выводить всех Forward которые играют в основном составе Main.
Kак записать условие ?
Код:
void find_fav()
{
List *node = head->next;
List *current_node = head;
while(node != NULL)
{
if (node->sport.Sostav == current_node && node->sport.MestoVkomande=="Forward")
current_node = node;
node = node->next;
}
printf("%20s!%2d.%2d.%4d \n",current_node->sport.fio,current_node->sport.d_birth.day,current_node->sport.d_birth.month,current_node->sport.d_birth.year);
Программа целиком
Код:
#include"stdafx.h"
#include"iostream"
#include"conio.h"
using namespace std;
struct Data
{
unsigned day;
unsigned month;
unsigned year;
};
struct T_sport
{
char fio[40];
Data d_birth;
unsigned v_CSKA ;
char MestoVkomande [20];
char Sostav [20];
};
struct List
{
T_sport sport;
List *next;
};
class main_n
{
private:
List *head;
public:
main_n()
{
head = NULL;
List *node1 = new List;
T_sport a ={"Ivanov I. I.",3,1,1984,2000,"Defender","Reserve"};
node1->sport = a;
node1->next = head;
head = node1;
List *node2 = new List;
T_sport b ={"Petrov A.A.",8,12,1987,2002, "Forward","Main"};
node2->sport = b;
node2->next = head;
head = node2;
}
void insert_before()
{
T_sport a;
char c;
cout<<endl<<"Enter data person\n";
cout<<" fio ";
cin.getline(a.fio,40);
cout<<endl<<"Enter date of birthday: \n";
cout<<" day (1-31) ";
cin>>a.d_birth.day;
cin.get(c);
cout<<" month (1-12)";
cin>>a.d_birth.month;
cin.get(c);
cout<<" year ";
cin>>a.d_birth.year;
cin.get(c);
cout<<" v_CSKA ";
cin>>a.v_CSKA;
cin.get(c);
cout<<" MestoVkomande ";
cin.getline(a.MestoVkomande,20);
cout<<" Sostav ";
cin.getline(a.Sostav,20);
List *node = new List;
node->sport = a;
node->next = head;
head = node;
}
void print_list()
{
printf("[ ");
List *node = head;
while(node != NULL)
{
printf("%20s ! %2d.%2d.%4d ! %4d ! %15s ! %15s\n",node->sport.fio,node->sport.d_birth.day,node->sport.d_birth.month,node->sport.d_birth.year,node->sport.v_CSKA,node->sport.MestoVkomande,node->sport.Sostav);
node = node->next;
}
printf("]\n");
}
void find_fav()
{
List *node = head->next;
List *current_node = head;
while(node != NULL)
{
if (node->sport.Sostav == current_node && node->sport.MestoVkomande=="Forward")
current_node = node;
node = node->next;
}
printf("%20s!%2d.%2d.%4d \n",current_node->sport.fio,current_node->sport.d_birth.day,current_node->sport.d_birth.month,current_node->sport.d_birth.year);
}
};
int main()
{
main_n f;
for(int i = 2; i < 5; i++)
{
f.insert_before();
};
cout <<"\nlist of structs\n! fio ! facul\'tet ! kurs !\n";
f.print_list();
f.find_fav();
_getch();
return 0;
}