Question

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

about this question 2, I don't know how to do it in C++, can anyone help me out???

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// House.h

#ifndef HOUSE_H
#define HOUSE_H

class House
{
public:
House(int age,string type,int rooms);
void setAge(int age);
int getAge();
string getType();
int getNumOfRooms();
double estimatedPrice();

private:
// Declaring variables
int age;
string type;
int rooms;
double cost;

};
#endif

____________________

// House.cpp

#include <iostream>
using namespace std;
#include "House.h"

House::House(int age,string type,int rooms)
{
this->age=age;
this->type=type;
this->rooms=rooms;
}
void House::setAge(int age)
{
this->age=age;
}
int House::getAge()
{
return age;
}
string House::getType()
{
return type;
}
int House::getNumOfRooms()
{
return rooms;
}
double House::estimatedPrice()
{
if(type.compare("Attached")==0)
{
cost=100000;
if(age<=5)
{
for(int i=1;i<=age;i++)
{
cost=cost+cost*0.01;
}
}
else
{
for(int i=1;i<=5;i++)
{
cost=cost+cost*0.01;
}
for(int i=1;i<=age-5;i++)
{
cost=cost+cost*0.02;
}
  
  
}
}
else if(type.compare("Semi-detached")==0)
{
cost=150000;
if(age<=5)
{
for(int i=1;i<=age;i++)
{
cost=cost+cost*0.02;
}
}
else
{
for(int i=1;i<=5;i++)
{
cost=cost+cost*0.02;
}
for(int i=1;i<=age-5;i++)
{
cost=cost+cost*0.03;
}
  
  
}
}
else if(type.compare("Detached")==0)
{
cost=150000;
for(int i=1;i<=age;i++)
{
cost=cost+cost*0.02;
}
}
  
return cost;
}


____________________________

// main.cpp

#include <iostream>
using namespace std;

#include "House.h"

int main()
{
int age;
string type;
int rooms;
  
cout<<":: House#1 ::"<<endl;
cout<<"Enter House Age :";
cin>>age;
cout<<"Enter House Type :";
cin>>type;
cout<<"Enter No of Rooms :";
cin>>rooms;
  
House house1(age,type,rooms);
  
  
cout<<":: House#2 ::"<<endl;
cout<<"Enter House Age :";
cin>>age;
cout<<"Enter House Type :";
cin>>type;
cout<<"Enter No of Rooms :";
cin>>rooms;
  
House house2(age,type,rooms);
  
cout<<"\nHouse Estimated Cost :$"<<house1.estimatedPrice()<<endl;
cout<<"House Estimated Cost :$"<<house2.estimatedPrice()<<endl;
  
  
return 0;
}


__________________________

Output:

1 ./House 1:: House#1 :: Enter House Age :9 Enter House Type :Attached Enter No of Rooms :5 :: House#2 :: Enter House Age :11


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
about this question 2, I don't know how to do it in C++, can anyone help...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • could you solve this in C++ please 2. (25 marks) Define a class called "House", that...

    could you solve this in C++ please 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 of the House class must perform the following operations: • Return the house age • Modify the house age • Return the house type • Return the number of rooms • A function called estimate Price() that returns...

  • Use C++ to create a class called Student, which represents the students of a university. A...

    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...

  • I am really struggling with this assignment, can anyone help? It is supposed to work with...

    I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...

  • c++ please need help with this question Consider a class Employee with data members: age(an integer),...

    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...

  • For C++ This is the information about the meal class 2-1. (24 marks) Define and implement...

    For C++ This is the information about the meal class 2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...

  • Objective: Learn how to -- read string from a file -- write multiple files Problem: Modify...

    Objective: Learn how to -- read string from a file -- write multiple files Problem: Modify the Person class in Lab #4. It has four private data members firstNam (char[20]), day, month, year (all int); and two public member functions: setPerson(char *, int, int, int) and printInfo(). The function setPerson sets the first name and birthday in the order of day, month and year. The function printInfo prints first name and birthday. But it should print the date in the...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...

    C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a class Date with the following properties: a) Data elements of the class are day, month, year. All three data elements are defined by the Type int. b) A set and a get element function are to be provided for each data element. In Within the framework of this task, it should be assumed that the values that are passed for day and year, are...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT