Hey guys, I have to make a program and i really struggle to deal with this part of it:
I have a char from 50 symbols in which i have to CIN the names of the footballer and between each of these names should have "space" interval. I've come up with the idea to concatenate different strings[which actually are the first,the second...and the last name] and to get the whole name by them
I can use strcat to make it but if i know for exactly how many footballers... if the user has to CIN the number of the names and it is variable, i cant do it...
Can u help me? I have done it here and it works only for 3 names for each player, but not for Y, but how i do it with a variable ??? :(((
I have done only 1/10 from the real problem but i will post it anyway cause i have to do first this with the names, then the other part . And if i can do it another way tell me please...
I dont know if u have understood exactly what i struggle to do cause i am not familiar with the termins in C++ in english... and i am 16y.o.
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
|
#include<iostream>
#include<iomanip>
#include<fstream>
using namespace std;
ofstream file1("Domashna.txt",ios::out);
int n,y; //y=broi imena, n - futbolisti
struct Footballer
{
int number;
char name[10][50];
int goals;
char country[400];
char teams[200];
void Input();
void Output();
};
void Footballer::Input()
{
do
{
cout<<"Footballer number from 1 to 30";
cin>>number;
file1<<number;
}while((number>30)||(number<1));
cout<<"How many names does the player have?"; //here is the main idea for Y players...
cin>>y;
for(int i=0;i<y;i++)
{
cout<<"Bring in"<<i+1<<"-o name of the player";
cin>>name[i];
file1<<name[i];
}
do
{
cout<<"Bring in how many goals he has scored";
cin>>goals;
}while((goals>20)||(goals<0));
cout<<"Bring in country";
cin>>country;
file1<<country;
cout<<"Bring in teams, for which he has played";
cin>>teams;
file1<<teams;
file1<<"\n";
}
void Footballer::Output()
{
cout<<number;
cout<<setw(10)<<strcat(strcat(strcat(strcat(name[0]," "),name[1])," "),name[2]); //but its working for only 3... how do i concatenate for these y?? :(
cout<<setw(10)<<goals;
cout<<setw(10)<<country;
cout<<setw(10)<<teams;
}
void TopScorer(Footballer Futbolist[])
{
int max,j;
max=Futbolist[0].goals;
for(int m=0;m<n;m++)
if(max<Futbolist[m].goals) // ne sam pravil proverka za r avni golmaistori + 2-ta gola po -malko
{
max=Futbolist[m].goals;
j=m;
}
cout<<"TopScorer:"<<"\n"<<"__________________________________________________________"<<"\n";
cout<<"Number"<<setw(6)<<"Name"<<setw(10)<<"Goals"<<setw(10)<<"Country"<<setw(10)<<"Teams"<<"\n";
cout<<Futbolist[j].number<<setw(10)<<Futbolist[j].name[0]<<setw(10)<<Futbolist[j].goals<<setw(10)<<Futbolist[j].country<<setw(10)<<Futbolist[j].teams<<"\t"<<"\n";
}
int main()
{
do
{
cout<<"Number footballers from 1 to 5";
cin>>n;
}while((n>5)||(n<1));
Footballer Futbolist[n];
for(int i=0;i<n;i++)
{
Futbolist[i].Input();
}
cout<<"Number"<<setw(6)<<"Name"<<setw(10)<<"Goals"<<setw(10)<<"Country"<<setw(10)<<"Teams";
for(int i=0;i<n;i++)
{
cout<<"\n";
Futbolist[i].Output();
}
cout<<"\n";
TopScorer(Futbolist);
system("pause");
return 0;
}
|