hello everyone :)
My proffesor gave me this exercise to build a class called Team which represent a soccer team in some Soccer Championship :P with attributes like TeamName (20 letters max), GoalsScored, GoalsTaken, GamesPlayed, GamePoints and methods like NewGame(which should set GoalsScored and GolasTaken to some values), Points(for every goal a team gets 3 points,for every tie 1 point), TeamName (which should return a pointer on the first letter in the name of the team) etc..
You will see the rest int the code below(its not complicated:) )..
I'm having troubles with the team name. I dont know should it be a pointer on a char attribute or a char set. Because it can be 20 letters max long, i probably should write a method which determines the name length?! And what about the TeamName method, how to implement that? I tried compiling this, but i get an error message for the line 42 saying "passing `const Tim' as `this' argument of `int Tim::DuzinaImena(char*)' discards qualifiers ".
Help! This isn't some homework assignment or something like that, take your time :)
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
|
#include <iostream>
#include <conio.h>
using namespace std;
class Team{
char *name; // I tried using a pointer but it doesnt work
int games_played, wins, ties, goals_scored, goals_taken, loses,total_points;
public:
Team(){
games_played=0; wins=0; ties=0;
goals_scored=0; goals_taken=0; loses=0; total_points=0;
};
void NewGame(int goals_scored, int goals_taken);
int NameLength(char *name);
const char *TeamName() const;
int Points() const {return total_points;}
int GoalDifference() const {return goals_scored-goals_taken;}
void PrintData() const ;
};
int Team::NameLength(char *name){ // Is this right ?
int counter(0);
while(name[counter]!=0 && counter<20) counter++;
return counter;
};
void Team::NewGame(int goals_scored, int goals_taken){
games_played++;
if(goals_scored>goals_taken){ wins++; total_points+=3;}
if(goals_scored<goals_taken) loses++;
if(goals_scored==goals_taken) ties++;
};
void Team::PrintData() const{
cout<<"Info on the team: ";
for(int i = 0 ; i < NameLength(name) ; i++) cout<<name[i];
cout<< "\n--------------------------------\n";
cout<< "Games played: " << games_played << " \n ";
cout<< "Goals scored: " << goals_scored << "\n" ;
cout<< "Goals taken: " << goals_taken << "\n";
cout<< "Wins: " << wins << "\n" ;
cout<< "Loses: " << loses << "\n" ;
cout<< "--------------------------------\n";
cout<< "Points: " << total_points << "\n" ;
};
int main(){
getch();
return 0;
}
|
This would have been a lot easier if I could use strings, but no, my proffesor wants me to do it the hard way :D I implemented some methods in the class interface..I dont speak english very well,so sorry if made some mistakes..I'm using BloodShed Dev-C++ builder which uses MinGw compiler..