Answer to Question #318030 in C++ for Nobody

Question #318030

seconds.

 

As a junior programmer, you are required to design and write a complete C++ program that asked the user to enter subscriber’s name and phone number, the phone number called, the distance from Shah Alam of the number called (in kilometers) and duration of the call-in seconds. The user also needs to enter types of call either Local or International call.

 

The cost of each call is calculated based on Table 1.

 

Distance from Shah Alam

Cost(RM)/minute

 

Local

International

Less than 25 km

0.35

0.55

25 <= km < 75

0.65

0.85

75 <= km < 300

1.00

1.20

300 <= km <=1000

2.00

2.20

Greater than 1000 km

3.00

3.20

 

Your program should use the following:

 

1. Appropriate Control Structure

2. User Defined Function

3. Sets the decimal precision to be used to format floating-point values on output operations. (2 decimal places)

4. Set background and text colour for output


1
Expert's answer
2022-03-25T15:11:30-0400
#include <iostream>
#include <string>


using namespace std;


struct Subscriber
{
	string name;
	int phoneNum;
	int phoneNumCall;
	float distance;
	int duration;
	char call;
	void SetData()
	{
		cout << "Please, enter a subscriber`s name: ";
		cin >> name;
		cout << "Please, enter a phone number: ";
		cin >> phoneNum;
		cout << "Please, enter a phone number called: ";
		cin >> phoneNumCall;
		cout << "Please, enter the distance from Shah Alam of the number called (in kilometers): ";
		cin >> distance;
		cout << "Please, enter the duration of the call-in seconds: ";
		cin >> duration;
		do
		{
			cout << "Please, enter a type of call (L - local or I - internal): ";
			cin >> call;
		} while (call != 'L' && call != 'I');
	}


	void CountCost()
	{
		if (distance < 25)
		{
			if (call == 'L')
				cout << 0.35*duration;
			else  if(call == 'I')
				cout << 0.55*duration;
		}
		else if (distance>=25&&distance < 75)
		{
			if (call == 'L')
				cout << 0.65*duration;
			else  if (call == 'I')
				cout << 0.85*duration;
		}
		else if (distance >= 75 && distance < 300)
		{
			if (call == 'L')
				cout << duration;
			else  if (call == 'I')
				cout << 1.2*duration;
		}
		else if (distance >= 300 && distance <= 1000)
		{
			if (call == 'L')
				cout << 2* duration;
			else  if (call == 'I')
				cout << 2.2*duration;
		}
		else if (distance >1000)
		{
			if (call == 'L')
				cout << 3* duration;
			else  if (call == 'I')
				cout << 3.2*duration;
		}
	}
	void Display()
	{
		cout << "\nSubscriber`s name is " << name
			<< "\nPhone number is " << phoneNum
			<< "\nPhone number call is " << phoneNum
			<< "\ndistance from Shah Alam of the number called is " << phoneNumCall
			<< "\nThe duration of the call-in seconds is " << duration;
	}
};

int main()
{
	Subscriber s;
	s.SetData();
	s.Display();
	cout << "\nResul count is ";
	s.CountCost();


}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog