Answer to Question #201093 in C++ for hammad

Question #201093

Define a class named Customer that holds private fields for a customer ID number, last name, first name, and credit limit. Include four public functions that each set one of the four fields. Do not allow any credit limit over $10,000. Include a public function that displays a Customer’s data. Write a main()function in which you declare a Customer, set the Customer’s fields, and display the results.


1
Expert's answer
2021-05-31T07:33:51-0400
#include <iostream>
#include <string>
using namespace std;


class Customer
{
public:
	void set_id_number() {
		cout << "Enter customer ID number: ";
		cin>> id_number;
	}
	void set_first_name() {
		cout << "Enter the client's first name: ";
		cin >> first_name;
	}
	void set_last_name() {
		cout << "Enter the client's last name: ";
		cin >> last_name;
	}
	void set_credit_limit() {
		cout << "Enter credit limit: ";
		cin >> credit_limit;
		if (credit_limit > 10000)
		{
			credit_limit = 10000;
			cout << "The credit limit cannot exceed USD 10,000, the maximum possible credit limit is set" << endl;
		}
	}
		void get_info() {
			cout << "Client's ID number: " <<id_number << endl;
			cout << "Client's first name: " << first_name << endl;
			cout << "Client's last name: " << last_name << endl;
			cout << "Credit limit: " << "$"<<credit_limit << endl;
		}
	
private:
	int id_number{ 0 };
	string  last_name;
	string  first_name;
	double credit_limit{ 0 };
};


int main()
{
	Customer client;
	client.set_id_number();
	client.set_first_name();
	client.set_last_name();
	client.set_credit_limit();
	client.get_info();
    return 0;
}

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