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.
#include <iostream>
using namespace std;
class Customer
{
private:
int ID;
string lastname;
string firstname;
double creditLimit;
public:
void setID(int ID)
{
this->ID = ID;
}
void setLastname(string lastname)
{
this->lastname = lastname;
}
void setFirstname(string firstname)
{
this->firstname = firstname;
}
void setCreditLimit(double creditLimit)
{
this->creditLimit = creditLimit;
}
void displayInfo()
{
cout << "ID: " << ID << endl;
cout << "last name: " << lastname << endl;
cout << "first name: " << firstname << endl;
cout << "credit limit: " << creditLimit << "$" << endl;
}
};
int main()
{
Customer customer;
cout << "ID = ";
int ID;
cin >> ID;
customer.setID(ID);
cin.get();
cout << "Enter first name: ";
string firstname;
getline(cin, firstname);
customer.setFirstname(firstname);
cout << "Enter last name: ";
string lastname;
getline(cin, lastname);
customer.setLastname(lastname);
double credit_limit;
do
{
cout << "Enter credit limit: ";
cin >> credit_limit;
if(credit_limit > 10000)
cout << "credit limit over 10000$ not allowed" << endl << endl;
}while(credit_limit > 10000);
cout << endl;
customer.setCreditLimit(credit_limit);
customer.displayInfo();
return 0;
}
Comments
Leave a comment