Home > Back-end >  The Room class Room
The Room class Room

Time:09-27

1. The class Room Room and the design of the full program (20 points)
Public data members: a single room long Length, single room Wide, Wide Area of Area, the number of room Num,
A member function: virtual function calc () the house area, set () is used to set/modify information, virtual function print () is responsible for displaying the value of the data members; The constructor for the data member is initialized (values are 0),
Main function: to create the object of the class x, initialization is five meters long and four meters wide, the object set () sets the room number 20, and call the calc object x () calculate the total area of 400 square meters, 20 house object x calling print () display room (in the main function does not allow to use cout statement, but with # comment lines exception),
2. The derived class House (buildings) design (40)
House is the Room type (base class) of the derived class, adds data members and member functions,
Data members: Nmen storage building in number; Parameterless constructor for data member is initialized (values are 0), with parameters also pass values to the base class constructor to initialize the data members;
A member function: goin () used to increase the floor number, goout () is used to reduce the number of students who are in the floor; A member function calc () house area (polymorphism); The member function print () show room number, floor number,
Main function: to create a class object y, initialize each room 8 meters long and 5 meters wide, room number 25; Object to invoke goin add 6 people, the () floor object call goout in the () floor reduce 3 people;
Then call calc function calculating the area of the house, and print (note that to use polymorphism), finally, the object calling print () function display room number 25, in the floor number 3 people (in the main function does not allow to use cout statement, but with # comment lines exception),
3. The "sun" derived class Building (high-rise) design (40)
Building classes is House class derived classes; (high-rise has 2 units, personnel only on the elevator in and out of)
Data members: deposit Nelevator elevator number; The constructor for the data member is initialized (a value of 0);
Member function: set () is used to set/modify Nelevator value, print () to indicate the number (Nmen value),
Elevator running normal function elerun () () is used to increase or decrease in the floor number, and print the display information: how many people into the apartment, how many people leave the building;
Main function: to create a class object za (there are 2 units of elevators, the initial 13) and the zb (there is 1 unit of elevators, the initial 7 people), elerun () implementation object za unit 2 elevators carry upstairs (8), the four people elerun () implementation object zb unit 1 elevators are transported down 3 people; Then the object calling print () function is shown in the building 2 unit net number 21 and four people respectively (in the main function does not allow to use cout statement, but with # comment lines exception),

CodePudding user response:

Class room only length and width, should is not enough, there are at least highly what of,

CodePudding user response:

reference 1st floor Chen_jiajie1234 response:
class room only length and width, should is not enough, there are at least highly what of,

This is a subject, we need to calculate area, only the CPP

CodePudding user response:

The class Room {
Public int calc () {
Return the Length * Wide;
};
Public String print () {
Return "Length=" + (String) Length + "Wide=" + (String) Wide, "Area=" + (String) Area + "Num=" + Num (String);
}
Public int Length, Wide, Area, Num;
Room () {
Length=0;
Wide=0;
Area=0;
Num=0;
}
Public void set (String NameOfDataMember, int ValueOfDataMember) {
If (NameOfDataMember=="Length") Length=ValueOfDataMember;
Else if (NameOfDataMember=="Wide") Wide=ValueOfDataMember;
Else if (NameOfDataMember=="Num" Num=ValueOfDataMember;
The else throw new Exception (" invalid data members ");
return;
}
}
Public static class TestRoom {
Public static void main (String [] arg c) {
The String
Room x=new Room (5, 4);
"Num" x.s et (20);
X.c alc ();

return;
}
}

CodePudding user response:

The call Room the main function of a class complete:
Public static void main (String [] arg c) {
String RoomInfo;
Room x=new Room (5, 4);
"Num" x.s et (20);
X.c alc ();
RoomInfo=x.p rint ();
return;
}
  • Related