[Solved] Best Mobile Plan with C++

Best Mobile Plan: St. Patrick Convent organizes a project exhibition “Innovative Minds” every year with an objective to provide the platform and unleash the potential of the students by showcasing their innovative projects.
Albert is a science expert and is a topper at his high school. He became interested about the project exhibition and enrolled his name for the same.

Albert’s Dad has a cell phone but often seemed to worry about the price plans for his phone that best fits for his usage pattern and monthly expenses. There are two options, each plan has different costs for daytime minutes, evening minutes and weekend minutes.

PlanCosts
daytimeeveningweekend
A100 free minutes then
25 paise per minute
15 paise per minute20 paise per minute
B250 free minutes then
45 paise per minute
35 paise per minute25 paise per minute

Having this as a spark for his project, Albert decided to design a handy application that will input the number of each type of minutes and output the cheapest plan for this usage pattern,using the format shown below. In the case that the two plans are the same price, output both plans.

He needs your help to evaluate his project and suggest corrections.

Hence create a class named BestMobilePlan with the following method.

Method NameDescription
void printPlanDetails(int,int,int)                                                                                This method should display the cheapest plan for this usage pattern.

Create a driver class called Main. In the Main method, obtain input from the user in the console and call the printPlanDetails method present in BestMobilePlan class.

[Note: Strictly adhere to the Object Oriented Specifications given in the problem statement. Convert paise to rupees.

All class names, attribute names and method names should be the same as specified in the problem statement. Create separate classes in separate files.]
Input Format:
First line of the input is an integer that gives the usage during the daytime in minutes.
Second line of the input is an integer that gives usage during the evening in minutes.
Third line of the input is an integer that gives usage during the night in minutes.

Output Format:
Output should print the cheapest plan for this usage pattern. In the case that the two plans are the same price, output both plans. Print the cost value with two decimal places.
Refer sample input and output for formatting specifications.

Sample Input 1:
251
10
60

Sample Output 1:
Plan A costs 51.25
Plan B costs 18.95
Plan B is cheapest

Sample Input 2:
162
61
66

Sample Output 2:
Plan A costs 37.85
Plan B costs 37.85
Plan A and B are the same price

Solution

#include <iostream>
using namespace std;

int main() {
    int daytime, evening, weekend;
    cin >> daytime >> evening >> weekend;
    float planA = PlanA(daytime, evening, weekend);
    float planB = PlanB(daytime, evening, weekend);
    if (planA < planB) {
        cout << "Plan A costs " << planA << endl;
        cout << "Plan B costs " << planB << endl;
        cout << "Plan A is cheapest" << endl;
    } else if (planB < planA) {
      //sauravhathi
        cout << "Plan A costs " << planA << endl;
        cout << "Plan B costs " << planB << endl;
        cout << "Plan B is cheapest" << endl;
    } else {
        cout << "Plan A costs " << planA << endl;
        cout << "Plan B costs " << planB << endl;
        cout << "Plan A and B are the same price" << endl;
    }
    return 0;
}

float PlanA(int daytime, int evening, int weekend) {
    if (daytime > 100) {
        float total = (float) ((daytime - 100) * 0.25 + evening * 0.15 + weekend * 0.20);
        return total;
        //sauravhathi
    } else {
        float total = (float) (evening * 0.15 + weekend * 0.20);
        return total;
    }
}

float PlanB(int daytime, int evening, int weekend) {
    if (daytime > 250) {
        float total = (float) ((daytime - 250) * 0.45 + evening * 0.35 + weekend * 0.25);
        return total;
    } else {
        float total = (float) (evening * 0.35 + weekend * 0.25);
        return total;
    }
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *