Question

Q2.1) Write a program to calculate phone bill of the user. The rule to calculate bill is given as follows: • You should ask t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<bits/stdc++.h>
using namespace std;
#include <functional>
#include <random>

double randomNumber(double M,double N)
{
return M + ((double)rand() / (RAND_MAX / (N-M) ) ) ;
}

double billWithoutInternet(double daily_usage)
{
   return (30*daily_usage);  
}

double billWithInternet(double daily_usage)
{
   return ((30*daily_usage)+15);
}

int main()
{
   int op;
   cout<<"You have an internet connection with your land phone"<<'\n';
   cout<<"If Yes Press 1. If No Press 0"<<'\n';

   bool valid_input = false;

   do
   {
       cin>>op;
       if(op==1 || op==0)
       {
           valid_input = true;
       }
       else
       {
           cout<<"Incorrect option. Answer the question again!"<<'\n';
       }
   } while (valid_input == false);

   vector<double> monthly_bill(12,0.0);

   if(op==0)
   {
       for(int i=0;i<12;i++)
       {
           double M = 0.0;
           double N = 5.0;
           double daily_usage = randomNumber(M,N);
           monthly_bill[i] = billWithoutInternet(daily_usage);
       }
   }
   else
   {
       for(int i=0;i<12;i++)
       {
           double M = 0.0;
           double N = 5.0;
           double daily_usage = randomNumber(M,N);
           monthly_bill[i] = billWithInternet(daily_usage);
       }
   }

   double bill = 0.0;
   for(int i=0;i<12;i++)
   {
       bill = bill + monthly_bill[i];
   }

   bill = bill/12;

   cout<<"Phone bill of one year is: "<<bill<<'\n';
   cout<<"******"<<'\n';

   for(int i=0;i<12;i++)
   {
       cout<<i+1<<" month bill ==> "<<monthly_bill[i]<<'\n';
   }

   return 0;
}

"Please refer to the screenshot of the code to understand the indentation of the code"

#include<bits/stdc++.h> using namespace std; double randomNumber(double M, double N) return M + ((double)rand() 7 (RAND_MAX /You have an internet connection with your land phone If Yes Press 1. If No Press 0 Phone bill of one year is: 102.085 ******

Add a comment
Know the answer?
Add Answer to:
Q2.1) Write a program to calculate phone bill of the user. The rule to calculate bill...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 8.3: Phone Chatbot (10 pts) For this programming assignment, we write a basic chatbot program....

    Assignment 8.3: Phone Chatbot (10 pts) For this programming assignment, we write a basic chatbot program. For fun, try having a conversation with an online chatbot here or here. Some sources estimate that 25% of customer services will be handled by Chatbots in 2020, vs. 2% in 2017 (1). The chatbot we are designing must ask you the following questions: What is your name? What is your phone number? What is your phone plan? How many GB of data this...

  • Write a program that prompts the user for their quarterly water bill for the last four...

    Write a program that prompts the user for their quarterly water bill for the last four quarters. The program should find and output their average monthly water bill. If the average bill exceeds $75, the output should include a message indicating that too much water is being used. If the average bill is at least $25 but no more than $75, the output should indicate that a typical amount of water is being used. Finally, if the average bill is...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • Lab 8 python code for Cell Phone Bill

    Lab 8: Cell Phone Bill CalculatorWrite the Python code for the following programming problem definition.Use modular design according to the modules specified below.Design and write a program that calculates and displays the number of minutes over the monthly contract minutes that a cell phone user incurred. The program should askthe user how many minutes were used during the month and how many minutes they were allowed. Validate the input as follows:• The minimum minutes allowed should be at least 100,...

  • Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sale...

    Looking for some help with this Java program I am totally lost on how to go about this. You have been approached by a local grocery store to write a program that will track the progress of their sales people (SalesPerson.java) The information needed are: D Number integer Month 1 Sales Amount-Double Month 2 Sales Amount-Double Month 3 Sales Amount-Double Write a Java program that allows you to store the information of any salesperson up to 20 While the user...

  • Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate...

    Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...

  • I need to Write a test program that prompts the user to enter 10 double values...

    I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...

  • Telus sends your cell phone bill for the month of March. Your bill shows the inoice...

    Telus sends your cell phone bill for the month of March. Your bill shows the inoice date as March 31, 2020 and the payment is due April 15. 2020. You have paid the bill on April 16th, 2020. When should Telus Recognize the revenue for this invoice, assuming that Telus is following Accrual Basis of Accounting? O a Oь Oc Od April 16, 2020 April 15, 2020 Any of these three dates is fine March 31, 2020

  • Write a program for a Buffet to display the bill Sor the cashicr The buffet serves a chef's meu with two options 31 50 The total adu bill is roduced by $5.00 if there are 9 aor more ad $15....

    Write a program for a Buffet to display the bill Sor the cashicr The buffet serves a chef's meu with two options 31 50 The total adu bill is roduced by $5.00 if there are 9 aor more ad $15.00 It is free after the third child maximum of 3 childrm) The program requests the name and zip code ofthe buf1ส and converts the tru The pr- then aceepts the number of adults and children, performs the necessary calculations compues...

  • This problem will create a monthly ledger for a user to keep track of monthly bills....

    This problem will create a monthly ledger for a user to keep track of monthly bills.  The program will start by asking the user for an amount of monthly bills to pay.  Design of this solution will involve four classes, some may involve the use of previously written code: Class Design:  OurDate class – update your previously written OurDate class to include a toString() method. Be certain that you still have methods that will setDayFromUser(), setMonthFromUser() and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT