Knowee
Questions
Features
Study Tools

Create a class Building with data members building number, name, area (in square feet),cost/square feet, location, total cost, and year of construction. Declare the cost/square feet asthe static data member. Define a parametric constructor to initialize the data members. Makeuse of this pointer. Create an array of objects and display details of N buildings along with the total cost.

Question

Create a class Building with data members building number, name, area (in square feet),cost/square feet, location, total cost, and year of construction. Declare the cost/square feet asthe static data member. Define a parametric constructor to initialize the data members. Makeuse of this pointer. Create an array of objects and display details of N buildings along with the total cost.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a simple implementation in C++:

#include<iostream>
using namespace std;

class Building {
    int buildingNumber;
    string name;
    float area;
    static float costPerSqFt;
    string location;
    float totalCost;
    int yearOfConstruction;

public:
    Building(int bNum, string bName, float bArea, string bLocation, int yoc) {
        this->buildingNumber = bNum;
        this->name = bName;
        this->area = bArea;
        this->location = bLocation;
        this->yearOfConstruction = yoc;
        this->totalCost = this->area * costPerSqFt;
    }

    void display() {
        cout << "Building Number: " << buildingNumber << endl;
        cout << "Name: " << name << endl;
        cout << "Area: " << area << " sq ft" << endl;
        cout << "Location: " << location << endl;
        cout << "Year of Construction: " << yearOfConstruction << endl;
        cout << "Total Cost: " << totalCost << endl;
    }

    static void setCostPerSqFt(float cost) {
        costPerSqFt = cost;
    }
};

float Building::costPerSqFt = 0;

int main() {
    Building::setCostPerSqFt(100); // Set cost per square feet

    Building buildings[3] = {
        Building(1, "Building 1", 2000, "Location 1", 2000),
        Building(2, "Building 2", 3000, "Location 2", 2001),
        Building(3, "Building 3", 4000, "Location 3", 2002)
    };

    for(int i = 0; i < 3; i++) {
        buildings[i].display();
        cout << endl;
    }

    return 0;
}

In this code, we first define the Building class with the required data members and a constructor that initializes them. The display method is used to print the details of a building. The setCostPerSqFt static method is used to set the cost per square foot for all buildings. In the main function, we create an array of Building objects and display their details.

This problem has been solved

Similar Questions

Create an array of objects and display details of N buildings along with the total cost

creata a classs vehicle withe datamenbers vehicle number name cost brand and yeat. declare year as static. create objects and display the details. create array of objects

Create a structure named warehouse with details like location, name, total_stock_rooms, occupied_rooms, and price_room. Write a C program to input details for the N warehouse. Write user-defined functions for: Function 1: Reading the details of the warehouse. This function should return the structure to the main() function. Function 2: Find the available rooms in the warehouse. Calculate the total cost for available rooms and display the details. Pass the structure returned from function 1 to function 2. Read the number of warehouses, location, name, total_stock_rooms, occupied_rooms, and price_room. Sample Input 2 Chennai Wheat warehouse 100 80 5000 Mumbai Electronic warehouse 15 10 10000 Sample Output [Wheat warehouse in Chennai: Available rooms-20: Cost 100000] [Electronic warehouse in Mumbai: Available rooms-5: Cost 50000]

Write a C++ program Create a base class Mountain with protected data members: mountain name and number of trees.Define a constructor to read the data members.  Create a class Coast from Mountain with a static data member to represent the total number of dams. Define a constructor to read the dam details such as dam name, total length, and width of the dam. Define member function “Display” to print the mountain details and the surface area of a dam.surface area of a dam=length*widthCreate a class Dam_detials from Coast with a private data member: depth. Create a parametrized constructor to initialize the value of depth. Define a member function “ Display” to calculate the capacity of your dam.Member function (Display)  in Dam_details overrides the member function (Display) in the Coast classCapacity=Volume/1000Volume=Surface area*depthCreate required objects, base pointers  and access the member functions. Identify the type of inheritance given.Sample Input5 (Read the depth )Mountain1 (Read the mountain name)20 (Read number of trees)Dam1 (Read dam name)30 (Read length)50(Read width)Sample OutputMountain1 20 treesDam1 area 1500Volume 6000Capacity 6.0Total dam 1

Suppose you are tasked with designing a program to model different types of employees in a company. Define three classes: Employee, Manager, and Developer, each with specific attributes and functionalities. 1.Employee Class: •Attributes: name (string), employeeId (integer), and salary (double). •Implement a constructor to initialize the name, employeeId, and salary attributes. •Implement a member function displayDetails() to display the name, employee ID, and salary of the employee. 2.Manager Class (Derived from Employee): •Attributes: department (string). •Implement a constructor to initialize the name, employeeId, salary, and department attributes. •Implement a member function displayDetails() to display the name, employee ID, salary, and department of the manager. 3.Developer Class (Derived from Employee): •Attributes: programmingLanguage (string). •Implement a constructor to initialize the name, employeeId, salary, and programmingLanguage attributes. •Implement a member function displayDetails() to display the name, employee ID, salary, and programming language of the developer. INPUT/OUTPUT EXAMPLE: Enter employee name: JAHANGEER Enter employee ID: 1 Enter employee salary: $5000 Enter manager name: JOHN Enter manager ID: 2 Enter manager salary: $6000 Enter manager department: RANDD Enter developer name: KEATS Enter developer ID: 3 Enter developer salary: $4000 Enter developer programming language: C Employee Details: Name: JAHANGEER Employee ID: 1 Salary: $5000 Manager Details: Name: JOHN Employee ID: 2 Salary: $6000 Department: RANDD Developer Details: Name: KEATS Employee ID: 3 Salary: $4000 Programming Language: C<iostream>

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.