#include <iostream> #include <string> #include <iomanip> using namespace std; class house{ private: string location; int num_of_rooms; int year_built; public: house(); house(string,int,int); void set_location(string); string get_location(); void set_num_of_rooms(int); int get_num_of_rooms(); void set_year_built(int); int get_year_built(); void print_house_details(); };
时间: 2024-01-26 17:04:59 浏览: 71
This is a class declaration for a `house` class with some private member variables and public member functions. Here is an example implementation for the `house_impl.cpp` file:
```
#include "house.h"
// Default constructor
house::house() {
location = "";
num_of_rooms = 0;
year_built = 0;
}
// Parameterized constructor
house::house(string loc, int num, int year) {
location = loc;
num_of_rooms = num;
year_built = year;
}
// Setter and getter functions for location
void house::set_location(string loc) {
location = loc;
}
string house::get_location() {
return location;
}
// Setter and getter functions for number of rooms
void house::set_num_of_rooms(int num) {
num_of_rooms = num;
}
int house::get_num_of_rooms() {
return num_of_rooms;
}
// Setter and getter functions for year built
void house::set_year_built(int year) {
year_built = year;
}
int house::get_year_built() {
return year_built;
}
// Function to print house details
void house::print_house_details() {
cout << "Location: " << location << endl;
cout << "Number of rooms: " << num_of_rooms << endl;
cout << "Year built: " << year_built << endl;
}
```
Note that the implementation file should include the header file `house.h` which contains the declaration of the `house` class.
阅读全文