Call Method
May 6, 2014 at 3:22pm UTC
This my current program.. Mind check where the option gone? its should display the option and enter the optoin.. but it terminate the program...
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
#include<iostream>
#include<stdlib.h>
#include<string>
using namespace std;
class Building
{
public :
string category;
int capacity, option;
double cost;
void getBuilding()
{
cin>>option;
if (option==1)
{
category="villa" ;
capacity = 10;
cost = 100.00;
}
else if (option==2)
{
category = "college" ;
capacity = 10;
cost = 100.00;
}
else if (option==3)
{
category="factory" ;
capacity = 10;
cost = 100.00;
}
else if (option==4)
{
category="temple" ;
capacity = 10;
cost = 100.00;
}
else if (option==5)
{
category="city hall" ;
capacity = 10;
cost = 100.00;
}
}
void displayBuilding()
{
cout<<"category: " <<category<<endl;
cout<<"capacity: " <<capacity<<endl;
cout<<"cost: " <<cost<<endl;
}
};
class Villa : public Building
{
public :
Villa()
{
displayBuilding();
}
};
class College : public Building
{
public :
College()
{
displayBuilding();
}
};
class Factory : public Building
{
public :
Factory()
{
displayBuilding();
}
};
class Temple : public Building
{
public :
Temple()
{
displayBuilding();
}
};
class CityHall : public Building
{
public :
CityHall()
{
displayBuilding();
}
};
int main()
{
cout<<"Please choose the building you want: " <<endl;
cout<<"1. villa" <<endl;
cout<<"2. college" <<endl;
cout<<"3. factory" <<endl;
cout<<"4. Temple" <<endl;
cout<<"5. City Hall" <<endl;
void getBuilding();
void displayBuilding();
return 0;
}
May 6, 2014 at 3:30pm UTC
You have two problems in main:
1) You never instantiate building
2) Line 111-112: These are function declarations, not function calls. Therefore, they don't execute. You want to invoke the function of a Building instance.
1 2 3 4
Building building;
building.getBuilding();
building.displayBuilding();
Last edited on May 6, 2014 at 3:31pm UTC
May 6, 2014 at 4:46pm UTC
ok done :) thank
Topic archived. No new replies allowed.