hapter 4: Selection Problem 3: The Write a C++program that prompts the user to e
ID: 3889710 • Letter: H
Question
hapter 4: Selection Problem 3: The Write a C++program that prompts the user to enter 3 integers. The program works under the assumption that no number is repeated: a. b. c. Print the numbers in ascending order, i.e. from smallest to largest. Print the number is descending order, i.e. from largest to smallest. Print the sum of smallest and largest numbers nter three nunbers-4 6-20 umbers in ascending order 204 6 umbers in descending order 6 4 -20 um of Min andMax-14 Problem 4 Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute Premium service: $25.00 plus a. For calls made from 6:00 a.m. to 6:00 p.m., the first 75 minutes are free; charges for more than 75 minutes are $0.10 per minute b. For calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for more than 100 minutes are $0.05 per minute Your program should prompt the user to enter an account number (int), a service code (char), and the number of minutes the service was used (int). A service code of ‘r' or ‘R' means regular service: a service code of ‘p' or 'P' means premium service. Treat any other character as an error. Your program should output the account number, type of service, number of minutes the telephone service was used, and the amount due from the user. For the premium service, the customer may be using the service during the day and the night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service was used during the night. nter your account nunber: 9854 ter service code: a nter your account nunber: 2345 ter service code: P nter ninutes fron 6an to 6pn: 128 ter ninutes froa 6pm to 6an: 288 nter your account nunber: 4532 nter service code: r nter ninutes: 189 ccount nunber: 2345 reniun Service otal cost: 34.58 ccount nunber: 4532 Regular Service otal cost: 28.00 valnd codeExplanation / Answer
//maximum minimun
#include <iostream>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
int main ()
{
int first, second, third;
int lo, hi;
cout<<" Enter 3 Numbers: ";
cin>>first;
cin>>second;
cin>>third;
lo = min(min(first, second), third);
hi = max(max(first, second), third);
int mid =(first+second+third)-(lo+hi);
cout<<" Numbers in ascceding order: "<<lo<<" "<<mid<<" "<<hi;;
cout<<" Numbers in descending order: "<<hi<<" "<<mid<<" "<<lo;
cout<<" Sum of Min and Max: "<<hi+lo<<endl;
return 0;
}
// mobile bill
//runs fine in gcc 4.8.5
#include <iostream>
#include <ctype.h>
int op(int ac, char cod);
using namespace std;
int main ()
{
int Acc, totmin ;
char sercode;
cout<<" Enter your account Number: ";
cin>>Acc;
cout<<" Enter service code: ";
cin>>sercode;
sercode = tolower(sercode);
if (! (sercode == 'p') || (sercode == 'r'))
{
cout<<" Invalid code enter P or R: ";
return 0;
}
op (Acc,sercode);
}
int op (int ac, char co)
{
int regminutes, daymin, n8min, pcahrge=0, regcharge=0;
char reg[] = "Regular Service", per[] = "Premium Service";
if (co == 'p')
{
cout<<"Enter minutes from 6Am to 6 Pm: ";
cin>>daymin;
cout<<" Enter minutes from 6Pm to 6Am: ";
cin>>n8min;
if (daymin > 75)
{
daymin = daymin-75;
pcahrge = daymin * 0.10;
}
if (n8min >100)
{
n8min = n8min-100;
pcahrge = pcahrge + (n8min * 0.05);
}
cout<<" Account number: "<<ac;
cout<<endl<<per;
cout<<" Total cost: "<<pcahrge<<endl;
}
else if (co == 'r')
{
cout<<" Enter minutes: ";
cin>>regminutes;
if (regminutes > 50)
{
regminutes = regminutes-50;
regcharge = regminutes * 0.20;
}
cout<<" Account number: "<<ac;
cout<<endl<<reg;
cout<<" Total cost: "<<regcharge<<endl;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.