LANGUAGE: C++ TOPIC: Files, Streams, & Classes PROBLEM: Write the interface (.h
ID: 3835226 • Letter: L
Question
LANGUAGE: C++
TOPIC: Files, Streams, & Classes
PROBLEM:
Write the interface (.h file) of a class Player containing:
*A data member name of type string .
*A data member score of type int .
*A member function called setName that accepts a parameter and assigns it to name . The function returns no value .
*A member function called setScore that accepts a parameter and assigns it to score. The function returns no value .
*A member function called getName that accepts no parameters and returns the value of name .
*A member function called getScore that accepts no parameters and returns the value of score.
-Note that I need to write the .h file I have already done the .cpp file but don't understand what the difference between the two is and dont know what I should write for the .h file
Explanation / Answer
Header File
Class declarations ibn cpp are stored in a separate file all together .
A file that contains a class declaration is called header file.
The name of the class as well file name(.h) are same.
For example, the Player class would be declared in the file Player.h
Header file will not have implementaion of function its implementaion class would have definition for function
#ifndef PLAYER_H
#define PLAYER_H
class PLAYER
{
private :
int score;
char name[50];
public :
void setScore(const int score);
void setName(char *c);
int getScore();
char* getName();
};
#endif
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.