The human characters in YTU.2635:P4 games

Source: Internet
Author: User
Tags gety time limit
the human characters in 2635:P4 gamesTime limit:1 Sec Memory limit:128 MB
submit:794 solved:536
[Submit] [Status] [Web Board] DescriptionIn a plane fight game, any character (role) has a blood volume (blood) and a positional loc (where Loc is an instance of the location Class) attribute. With a role class, you can derive different roles, such as people, Immortals, monsters, and so on. In the following procedure, you define the location class and the role class, a new name and attack data member is added to Human (Human), design member functions for the Human class, and implement the MoveTo and Addblood two member functions in the role class. Write down the required code in the middle of begin and end. You can only edit and submit the code between begin and end. #include <iostream> using namespace std;     Class Location {Private:int x, y; public:location (int a, int b): X (a), Y (b) {} int GetX () {return x;}     int GetY () {return y;}  void SetXY (int a,int b) {x=a;y=b;}; Set position coordinates};  Class Role {public:role (int rblood, int rx, int ry): Blood (Rblood), loc (rx,ry) {} void MoveTo (int rx, int ry); Move to (Rx, Ty), to change the value of loc to void Addblood (int b);     Increase the blood volume, the parameter is negative, the representative reduces protected:int blood; Location Loc; }; void Role::moveto (int rx, int ry)
{
Loc.setxy (Rx,ry);
}
void Role::addblood (int b)
{
Blood+=b;
}//************* begin ***************** class Human:public Role {public:private:string name;   name int attack; Damage};     End ***************** int main () {string name;     int att, blood, x, y;     cin>>name>>att>>blood>>x>>y; Human hum (name,att,blood,x,y);     The attack att of person name, the amount of blood blood, at (x, y) at Hum.show ();     int Incatt, Incblood, newx, Newy;     cin>>incatt;     cin>>incblood;     cin>>newx>>newy;  Hum.addattack (Incatt); Damage increased Incatt hum.addblood (Incblood);  Blood volume increased Incblood hum.moveto (newx,newy);     The man moved to the (news,newy) place Hum.show (); return 0; }

Input The first line: the name of the blood attack position, where the position is two integers, representing the plane x, y coordinate the second row: Increased damage third line: The amount of blood to increase the fourth line: the new position, with two integers to represent the input parts separated by a space

Output uses two lines to display the initial state of the game character and the state after adjusting the parameters such as "Avanda has attack and blood in (4,3)" means Avanda has 500 attack damage 1000 blood volume, in (4,3) Location

Sample Input

Avanda 4 3
-300
2 5
Sample Output
Avanda have attack and blood in (4,3) Avanda have-attack and blood in
(2,5)
Analysis: The Human class inherits the role class, inherits the base class members, and adds the members name and attack.
It can be seen through the main function that the constructor addattack (int a) and show () are also required;
AC Code:
Begin *****************
class Human:public Role
{public
:
    Human (String rname,int att , int rblood,int rx,int ry): Role (Rblood,rx,ry), name (Rname), Attack (ATT) {}
    void Addattack (int a);
    void Show ();
Private:
    string name;  Name
    int attack;   Damage
};
void Human::addattack (int a)
{
	attack+=a;
}
void Human::show ()
{
	cout<<name<< "has" <<attack<< "attack and" <<blood;
	cout<< "Blood In (" <<loc.getx () << ",";
	Cout<<loc.gety () << ")" <<endl;
}


End *****************


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.