Create an array of objects and display details of N buildings along with the total cost
Question
Create an array of objects and display details of N buildings along with the total cost
Solution
Sure, here is a step-by-step guide on how to create an array of objects and display details of N buildings along with the total cost. I'll use JavaScript for this example.
- First, let's define a Building class:
class Building {
constructor(name, cost) {
this.name = name;
this.cost = cost;
}
}
- Now, let's create an array of Building objects:
let buildings = [
new Building('Building 1', 1000),
new Building('Building 2', 2000),
new Building('Building 3', 3000),
// add more buildings as needed
];
- To display the details of each building, we can use a loop:
for (let building of buildings) {
console.log(`Name: ${building.name}, Cost: ${building.cost}`);
}
- To calculate the total cost of all buildings, we can use the
reducemethod:
let totalCost = buildings.reduce((sum, building) => sum + building.cost, 0);
console.log(`Total cost: ${
Similar Questions
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 as the static data member. Define a parametric constructor to initialize the data members. Make use of this pointer. Create an array of objects and display details of N buildings along with the total cost
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]
Draw a flowchart that will calculate the price of building a house. The price of the house is based on three things:The quality of the interiorThe lot sizeThe size of the houseThe realtor enters the number for each item, not the name. The clerk will not enter the numbers that they can’t control such as the prices. For example: everyone who buys a custom home pays $1000 for each 500 square feet of lot and $500 for each 100 square feet of house.Output the cost for one person buying a house. People may only buy one house.Trace the program 3 times: once for each type of home, make up your own data.Data Related to Quality and Size of HouseQuality of house Type of house Price per 500 sq. ft of lot Price per 100 sq. ft of house1 Custom Home $1000 $5002 Mid-quality $700 $4003 Economy $500 $300
Declare a structure named “Furniture” to store details like furniture name, furniture type, cost per unit, length, breadth, height, and color. You must read the details of N Furniture. Pass this structure to a user-defined function that will print the details of furniture for the given furniture type.Sample Input2 (N- number of furniture)Chair (furniture name)P (furniture type . W – wood, P-plastic)500 (cost per unit)100.5( float value for length)56.3( float value for breadth)60.2( float value for heigth)red (color)TableW300060.546.380.4WhiteP (Enter the furniture type to search) Sample OutputChair500100.556.360.2red
.Given an array whose index represents houses and value at that index represents the size of that house.you have to find minimum cost for repairing . if the adjacent house size id smaller then the cost of repairing will always be higher than adjacent smaller house.
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.