Points to consider:
Code
house.h
#include<string>
using namespace std;
class House{
int age;
string type;
int rooms;
double cost;
public:
int getAge();
void setAge(int age);
string getType();
int getRooms();
void estimatePrice(int age, string
type);
void printHouse();
House(int age, string type, int
rooms){
this->age = age;
this->type =
type;
this->rooms =
rooms;
}
};
house.cpp
#include "house.h"
using namespace std;
int House :: getAge(){
return age;
}
void House :: setAge(int age){
this->age = age;
}
string House :: getType(){
return type;
}
int House :: getRooms(){
return rooms;
}
void House :: estimatePrice(int age, string type){
double cost = 0;
if(type.compare("Attached") == 0){
cost = 100000;
for(int i = 1;i<=age;i++){
if(i<=5){
cost = cost*1.01;
}else{
cost = cost*1.02;
}
}
}else if(type.compare("Semi-Attached") == 0){
cost = 150000;
for(int i =1;i<=age;i++){
if(i<=5){
cost = cost*1.02;
}else{
cost = cost*1.03;
}
}
}else{
cost = 200000;
for(int i = 0;i<=age;i++){
cost =
cost*1.02;
}
}
this->cost = cost;
}
void House::printHouse(){
cout<<"House Details: "<<"Age: " <<
this->age <<" Rooms: " << this->rooms << "
" << " Type: " << this->type
<<endl<<"estimated Cost: " <<
this->cost;
cout<<endl;
}
testhouse.cpp
#include<iostream>
#include "house.cpp"
using namespace std;
int main(){
House house1(2, "Attached", 10);
House house2(6, "Detached", 6);
house1.estimatePrice(house1.getAge(),
house1.getType());
house2.estimatePrice(house2.getAge(),
house2.getType());
house1.printHouse();
house2.printHouse();
}
Sample Output
Friend, That was
a nice question to answer
If you have any doubts in understanding do let me know in the
comment section. I will be happy to help you further.
Please like it if you think effort deserves like.
Thanks
could you solve this in C++ please 2. (25 marks) Define a class called "House", that...
about this question 2, I don't know how to do it in C++, can anyone help me out??? C 38s. A &X C Solved Get Hon (246) Th (242) A X PowerPo X X endrc Microso odle.concordia.ca/moodle/pluginfile.php/3796501/mod resource/content/1/A4 % 20- %20F2019 pdf COEN 243-Fall 2019 2. (25 marks) Define a class called "House", that represents the information of a house. A House is defined with these attributes: age (int), type (string) (Detached, Semi-Attached, Attached), rooms (int) and cost (double). Functions...
Use C++ to create a class called Student, which represents the students of a university. A student is defined with the following attributes: id number (int), first name (string), last name (string), date of birth (string), address (string). and telephone (area code (int) and 7-digit telephone number(string). The member functions of the class Student must perform the following operations: Return the id numb Return the first name of the student Modify the first name of the student. . Return the...
C++ program please provide code only for class counterType.h, counterTypeImp.cpp, and main.cpp. Separately code it. Define a class counterType to implement a counter. Your class must have a private data member counter of type int. Define a constructor that accepts a parameter of type int and initializes the counter data member. Add functions to: Set counter to the integer value specified by the user. Initialize counter to 0. Return the value of counter with a function named getCounter. Increment and...
- Classes Write a C++ program that creates a class called Date that includes three pieces of information as data members, namely: month (type int) day (type int) year (type int). Program requirements: - Provide set and a get member functions for each data member. - For the set member functions assume that the values provided for the year and day are correct, but in the setMonth member function ensure that the month value is in the...
Derive a class called Stack from the linked list described in Assignment 2 (list of Dates). This means the Stack class will inherit all the properties (data and functions) of the linked list. But, since a stack only allows pushing and popping at the front of the list only, you will need to prevent the operations at the back. To do this, derive the Stack class in such a way that the base class (LinkedList) functions become private in the...
C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Hi the programming language for this assignment is C programming. Could you also please number the answers exactly as they appear in the assignment? Thank you. (9) 1. An array of structures is needed to keep track of 50 grocery items containing the item name, item type, cost, quantity, and tax percentage for each grocery item. The following declarations have already been done: { struct grocery char name[20], type[15]: float cost, taxp: int quan: 3 Also, the following declaration has...
c++ please Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member func- tions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 compo- nents of...
c++ please need help with this question Consider a class Employee with data members: age(an integer), id (an integer) and salary (a float), and their corresponding member functions as follows: class Employee { private: int age; int id; float salary; public: Employee( ); // default constructor: age=0, id=0, and salary=0 Employee(Employee &x); // copy constructor Employee& operator = (Employee &x); // equal sign operator void setAge(int x); // let age = x...