In: Computer Science
A local zoo offers three different memberships:
an individual membership for $99 per year, a dual membership for $175 per year,
and a family membership for $225 per year. The membership director wants a program
that displays the total membership revenue for the year,
as well as the amount of the total revenue contributed by each membership type.
a. enter the input, processing, and output items, as well as the algorithm, in the first column.
b.Desk-check the algorithm twice. For the first desk-check, use 50, 75, and 150
as the numbers of individual, dual, and family memberships sold during the year.
For the second desk-check, use 35, 150, and 265.
Hi, Thank you for asking the question. This code is written in C++ but the same approach can be used in any programming language.
Here we create 3 global variables for storing the membership price for each type for a year. Having global variables gives you an advantage that later when you want to change the prices for each type, then you don't have to make changes to the complete program. Just changing these variables can work. We take "long long" as the datatype instead of "interger" because the revenue can be very large and integer might not be able to store it.
After that we take input from the user and store them in 3 seperate variables (num_individual_sold, num_dual_sold, num_family_sold).
Then the revenue generated from a particular type, let's say, individual will be (price for each individual membership) * (total individual memberships sold).
Adding the renevue from each memberships will give us the total revenue generated.
Below is the complete code along with the screenshot of output. Hope you like it.
#include<bits/stdc++.h>
using namespace std;
long long MEM_FEE_INDIVIDUAL = 99; //stores the individual membership fee per year
long long MEM_FEE_DUAL = 175; //stores dual membership fee per year
long long MEM_FEE_FAMILY = 225; //stores family membership fee per year
int main() {
long long num_individual_sold, num_dual_sold, num_family_sold;
cin >> num_individual_sold >> num_dual_sold >> num_family_sold; //taking input for number of memberships sold in each type
long long total_revenue_individual, total_revenue_dual, total_revenue_family;
total_revenue_individual = MEM_FEE_INDIVIDUAL * num_individual_sold; //calculating total revenue made by selling individual memberships
total_revenue_dual = MEM_FEE_DUAL * num_dual_sold;
total_revenue_family = MEM_FEE_FAMILY * num_family_sold;
cout << "Total Revenue: $" << total_revenue_individual + total_revenue_dual + total_revenue_family << endl;
cout << "Total Revenue by individual memberships: $" << total_revenue_individual << endl;
cout << "Total Revenue by dual memberships: $" << total_revenue_dual << endl;
cout << "Total Revenue by family memberships: $" << total_revenue_family << endl;
}