fork download
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. class House{
  6. private:
  7. string *nameowner;
  8. int *numroom;
  9. int *Rentingfee;
  10. Room *room;
  11. friend class Town;
  12. public:
  13. House(){
  14. setnameowner();
  15. setnumroom();
  16. Rentingfee=new int(0);}
  17.  
  18.  
  19. ~House(){
  20. cout<<"bye House"<<endl;
  21. delete []room;
  22. }
  23.  
  24.  
  25. void setnameowner(){
  26. string a;
  27. cout<<"enter the owner name of this house:";
  28. cin>>a;
  29. nameowner=new string(a);}
  30.  
  31. const string *getnameowner() const{
  32. return nameowner;}
  33.  
  34. void setnumroom(){
  35. int b;
  36. cout<<"Enter the rooms number of this house:";
  37. cin>>b;
  38. numroom=new int(b);
  39. setRoom(b);
  40. }
  41.  
  42. const int *getnumroom()const{
  43. return numroom;}
  44.  
  45.  
  46. void setRoom(int n){
  47. room=new Room[n];}
  48.  
  49. void setRentingFee(int index){
  50. int m;
  51. cout<<"Enter the monthly Renting fee of this house:";
  52. cin>>m;
  53. Rentingfee=new int(m);
  54. }
  55.  
  56. const int *getRentingFee()const{
  57. return Rentingfee;
  58. }
  59.  
  60. void DisplayHouse(){
  61. cout<<"the house name is :"<<getnameowner()<<endl;
  62. cout<<"the Renting fee is : "<<getRentingFee()<<endl;
  63. cout<<"the number of rooms in this house is :"<<getnumroom()<<endl;
  64. cout<<"and the rooms details as follows:"<<endl;
  65. for(int i=0;i<*numroom;i++)
  66. room[i].DisplayRoom();}
  67. };
  68.  
  69. class Town{
  70. private:
  71. House *homes;
  72. bool *Rented;
  73. string *NameTown;
  74. static int Num;
  75.  
  76. public:
  77. Town(string n ){
  78. setnametown(n);
  79. Rented= new bool [5];
  80. for ( int i=0;i<5;i++){
  81. Rented [i]=0;
  82. sethomes();
  83. Num++;} // end constructor
  84.  
  85. ~Town();
  86. cout<<"bye Town"<<endl;
  87. delete []homes ;
  88. homes=0;} // end destructor
  89.  
  90. void setnametown( string n ){
  91. cout<<"Enter the name of this Town ::";
  92. cin>>n;
  93. NameTown=new string(n);}
  94.  
  95.  
  96.  
  97. const string *getNameTown() const{
  98. return NameTown;}
  99.  
  100. int getNum(){
  101. return Num;}
  102.  
  103. void sethomes(){
  104. homes=new House[5];}
  105.  
  106.  
  107. void Addhouse(House a ,int index){
  108. homes[index]=a;
  109. setRented(index);
  110. if( Rented[index]=1)
  111. homes[index]. setRentingFee(index);
  112. else
  113. cout<<"No Rening fee"<<endl;}
  114.  
  115.  
  116. void setRented(int index){
  117. IsRented( index);}
  118.  
  119. void IsRented(int index){
  120. bool a;
  121. cout<<"Is this house with index"<<index<<"rented?? "<<endl;
  122. cout<<"if yes enter 1 else enter 0"<<endl;
  123. cin>>a;
  124. if(a){
  125. Rented[index]=1;
  126. cout<<"this house is rented"<<endl;}
  127. else
  128. cout<<" this house is not rented !"<<endl;
  129. }
  130.  
  131.  
  132.  
  133. void AvgRentFees(){
  134. int sum =0;
  135. for ( int i=0;i<5;i++)
  136. sum+=*(homes[i].Rentingfee);
  137. cout<<"the Average Renting fee is "<<sum/5<<endl;}
  138.  
  139.  
  140.  
  141. void Cheapest(){
  142.  
  143. int mini=*(homes[0].Rentingfee);
  144. string name=*homes[0].nameowner;
  145. for( int i=0;i<5;i++)
  146. if(mini>*(homes[i].Rentingfee)){
  147. mini=*(homes[i].Rentingfee);
  148. name=*(homes[i].nameowner);}
  149.  
  150. cout<<"the least renting fee is "<<mini<<"and the name of its owner"<<name<<endl;}
  151.  
  152.  
  153. void HomeArea(int index){
  154. int sum=0;
  155. int a=*( homes[index].numroom);
  156. for(int i=0;i<a;i++)
  157. sum+=homes[index].room[i].Area;
  158. cout<<"The Total Area of house index"<<index<<"IS;;"<<sum<<endl;}
  159.  
  160.  
  161. void DisplayTowm(){
  162. cout<<"the name of this Town is "<<&getNameTown<<endl;
  163. cout<<"the number of objects in this Town is :"<<getNum()<<endl;
  164. cout<<"this Town includes 5 homes and their info as following :";
  165. for ( int i=0;i<5;i++){
  166. cout<<"info of house "<<i<<" : :";
  167. Addhouse(homes[i],i);
  168. homes[i].DisplayHouse();}
  169. };
  170.  
  171. class Room{
  172. private:
  173. int Area;
  174. string roomname;
  175. friend class House;
  176. friend class Town;
  177. public:
  178. Room( int a, string n){
  179. setArea(a );
  180. setroomname( n);}
  181.  
  182. ~Room(){
  183. cout<<"bye room"<<endl;}
  184.  
  185. void setArea(int a){
  186. cout<<"Enter the area of this room ";
  187.  
  188. cin>>a;
  189. Area=a;}
  190.  
  191. int getArea(){
  192. return Area;}
  193.  
  194. void setroomname(string n){
  195. cout<<"Enter the name of this room ";
  196. cin>>n;
  197. roomname=n;}
  198.  
  199. string getnameroom(){
  200. return roomname;}
  201.  
  202. void DisplayRoom(){
  203. cout<<"name of room :"<<&getnameroom<<endl;
  204. cout<<"room Area:"<<&getArea<<endl;
  205. }};
  206.  
  207. void main()
  208. {
  209. Town d("bayan");
  210. }
  211.  
  212.  
  213.  
  214.  
  215.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:10: error: ISO C++ forbids declaration of ‘Room’ with no type
prog.cpp:10: error: expected ‘;’ before ‘*’ token
prog.cpp: In destructor ‘House::~House()’:
prog.cpp:21: error: ‘room’ was not declared in this scope
prog.cpp: In member function ‘void House::setRoom(int)’:
prog.cpp:47: error: ‘room’ was not declared in this scope
prog.cpp:47: error: expected type-specifier before ‘Room’
prog.cpp:47: error: expected `;' before ‘Room’
prog.cpp: In member function ‘void House::DisplayHouse()’:
prog.cpp:66: error: ‘room’ was not declared in this scope
prog.cpp: At global scope:
prog.cpp:210: error: expected `}' at end of input
prog.cpp: In constructor ‘Town::Town(std::string)’:
prog.cpp:85: error: no matching function for call to ‘Town::Town()’
prog.cpp:77: note: candidates are: Town::Town(std::string)
prog.cpp:69: note:                 Town::Town(const Town&)
prog.cpp: In member function ‘void Town::Addhouse(House, int)’:
prog.cpp:110: warning: suggest parentheses around assignment used as truth value
prog.cpp: In member function ‘void Town::HomeArea(int)’:
prog.cpp:157: error: ‘class House’ has no member named ‘room’
prog.cpp: In member function ‘void Town::DisplayTowm()’:
prog.cpp:162: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say ‘&Town::getNameTown’
prog.cpp: In member function ‘void Town::Room::DisplayRoom()’:
prog.cpp:203: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say ‘&Town::Room::getnameroom’
prog.cpp:204: error: ISO C++ forbids taking the address of an unqualified or parenthesized non-static member function to form a pointer to member function.  Say ‘&Town::Room::getArea’
prog.cpp: At global scope:
prog.cpp:210: error: expected unqualified-id at end of input
stdout
Standard output is empty