81.7k views
1 vote
In C++ please

A)


Ron bought several acres of farm to grow and sell vegetables. Suppose that Ron wants to grow a maximum of two types of vegetables.


Write a program that prompts Ron or the user to do the following:


Enter the total farm area in acres.

The number of vegetables (one or two) that the user wants to grow.

If the user wants to grow two types of vegetables, then prompt the user to enter the portion (as a percentage) of land used for the first vegetable.

Enter the seed cost, plantation cost, fertilizing cost, labor cost, and selling price per acre.

If the user specified 2 vegetables, prompt the user to enter the items in step 4 for the second vegetable.

The program then outputs


The total revenue.

The profit/loss.

B)


The cost of renting a room at a hotel is, say $100. 00 per night. For special occasions, such as a wedding or conference, the hotel offers a special discount as follows.


If the number of rooms booked is:


at least 10, the discount is 10%

at least 20, the discount is 20%

at least 30, the discount is 30%

Also if rooms are booked for at least three days, then there is an additional 5% discount.


Instructions


Write a program that prompts the user to enter:


The cost of renting one room

The number of rooms booked

The number of days the rooms are booked

The sales tax (as a percent).

The program outputs:


The cost of renting one room

The discount on each room as a percent

The number of rooms booked

The number of days the rooms are booked

The total cost of the rooms

The sales tax

The total billing amount.

Your program must use appropriate named constants to store special values such as various discounts.


Since your program handles currency, make sure to use a data type that can store decimals with a precision to 2 decimals

1 Answer

7 votes

Let's provide a condensed version of the programs:

Part A) For Ron's farm:

```cpp

#include <iostream>

#include <iomanip>

int main() {

double area, portion = 1.0, sc1, pc1, fc1, lc1, sp1, sc2 = 0, pc2 = 0, fc2 = 0, lc2 = 0, sp2 = 0;

int numOfVeg;

std::cout << "Enter farm area: ";

std::cin >> area;

std::cout << "Enter number of vegetables (1 or 2): ";

std::cin >> numOfVeg;

if (numOfVeg == 2) {

std::cout << "Enter portion for first vegetable: ";

std::cin >> portion;

portion /= 100;

}

std::cout << "Enter costs and price for first vegetable: ";

std::cin >> sc1 >> pc1 >> fc1 >> lc1 >> sp1;

if (numOfVeg == 2) {

std::cout << "Enter costs and price for second vegetable: ";

std::cin >> sc2 >> pc2 >> fc2 >> lc2 >> sp2;

}

double revenue = (portion * area * sp1) + ((1 - portion) * area * sp2);

double cost = (portion * area * (sc1 + pc1 + fc1 + lc1)) + ((1 - portion) * area * (sc2 + pc2 + fc2 + lc2));

std::cout << std::fixed << std::setprecision(2);

std::cout << "Total revenue: $" << revenue << "\\Profit/Loss: $" << revenue - cost << std::endl;

}

```

Part B) For hotel room bookings:

```cpp

#include <iostream>

#include <iomanip>

int main() {

const double D10 = 0.10, D20 = 0.20, D30 = 0.30, ADD_D = 0.05;

double roomCost, salesTax;

int roomsBooked, daysBooked;

std::cout << "Enter cost of one room, rooms booked, days booked, sales tax: ";

std::cin >> roomCost >> roomsBooked >> daysBooked >> salesTax;

salesTax /= 100;

double discount = 0;

if (roomsBooked >= 10) discount = D10;

if (roomsBooked >= 20) discount = D20;

if (roomsBooked >= 30) discount = D30;

if (daysBooked >= 3) discount += ADD_D;

double totalCost = roomCost * roomsBooked * daysBooked * (1 - discount);

double taxAmount = totalCost * salesTax;

std::cout << std::fixed << std::setprecision(2);

std::cout << "Room cost: $" << roomCost << "\\Discount: " << discount * 100 << "%\\Rooms booked: " << roomsBooked

<< "\\Days booked: " << daysBooked << "\\Total cost: $" << totalCost << "\\Sales tax: $" << taxAmount

<< "\\Billing amount: $" << totalCost + taxAmount << std::endl;

}

```

Step-by-step explanation:

1. Part A) gets the farm area, the number of vegetables, costs, and prices. It calculates and prints the revenue and profit/loss.

2. Part B) gets room cost, rooms booked, days booked, and sales tax. It calculates discounts,

total cost, tax amount, and prints the billing information.

This condensed version omits some detail but should be more concise for your needs. Note that these examples do not handle invalid inputs.

User Arany
by
8.7k points

No related questions found