Аз също не знам как ще стане условие Г), но все пак ще постна моето решение без него...
#include <iostream.h>
#include <string.h>
struct book
{
char zaglavie[101], imeavtor[81];
int sign, brekz;
double cena, ocena;
};
typedef book tbook[5000];
void input(book &a)
{
cout<<"Vavedete sign. N: ";
cin>>a.sign;
cin.ignore();
cout<<"Vavedete zaglavie: ";
cin.getline(a.zaglavie,101);
cout<<"Vavedete avtor: ";
cin.getline(a.imeavtor,81);
do{
cout<<"Vavedete cena: ";
cin>>a.cena;
} while(a.cena<1.00 || a.cena>99.99);
do{
cout<<"Vavedete br. zakupeni ekzemplqri: ";
cin>>a.brekz;
} while (a.brekz<1 || a.brekz>50);
cin.ignore();
a.ocena=a.brekz*a.cena;
cout<<"-----------------------------------------------------"<<endl;
}
void inputall(tbook a, int n)
{
for(int i=0;i<n;i++)
input(a);
}
void print(book a)
{
cout<<"-----------------------------------------------------"<<endl;
cout<<a.sign<<" "<<a.zaglavie<<" ";
char *p1,*p2,*p3,ime[81];
strcpy(ime,a.imeavtor);
p1=strtok(ime," ");
p2=strtok(NULL," ");
p3=strtok(NULL," ");
cout<<p3<<" "<<p1[0]<<"."<<p2[0]<<" "<<a.cena<<" "<<a.brekz<<" "<<a.ocena<<endl;
}
void printall(tbook a, int n)
{
for(int i=0;i<n;i++)
print(a);
}
void sortsign(tbook a, int n)
{
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(a[j].sign<a[j-1].sign)
{
book x=a[j];
a[j]=a[j-1];
a[j-1]=x;
}
}
void sortocena(tbook a, int n)
{
for(int i=0;i<n;i++)
for(int j=n-1;j>i;j--)
if(a[j].ocena>a[j-1].ocena)
{
book x=a[j];
a[j]=a[j-1];
a[j-1]=x;
}
}
void scena(tbook a, int n)
{
double var=0,s=0;
for(int i=0;i<n;i++)
var=var+a.cena;
s=var/n;
cout<<"Sredna cena na knigite: "<<s<<endl;
cout<<"-----------------------------------------------------"<<endl;
}
int n; tbook a;
void main()
{
//do
//{
cout<<"Vavedete br. knigi: "; cin>>n;
cin.ignore();
//} while(n<3 || n>5000);
inputall(a,n);
sortsign(a,n);
printall(a,n);
cout<<"!-----------------------------------------------------!"<<endl;
sortocena(a,n);
printall(a,n);
cout<<"!-----------------------------------------------------!"<<endl;
scena(a,n);
}
Ти питаше за strtok-a:
void print(book a)
{
cout<<"-----------------------------------------------------"<<endl;
cout<<a.sign<<" "<<a.zaglavie<<" ";
char *p1,*p2,*p3,ime[81];
strcpy(ime,a.imeavtor);
p1=strtok(ime," ");
p2=strtok(NULL," ");
p3=strtok(NULL," ");
cout<<p3<<" "<<p1[0]<<"."<<p2[0]<<" "<<a.cena<<" "<<a.brekz<<" "<<a.ocena<<endl;
}