Answer to Question #195318 in C++ for VASANTH V

Question #195318


1. Create private int variable CustomerID to store the customer id.

2. Create private string variable CustomerName to store the customer name.

3. Create private float variable CustomerBalance to store the customer account balance.

4. Create private string variable BranchName to store the customer account holding branch name.

5. Create a public member function void read() to read the input from user such CustomerID, CustomerName, CustomerBalance and BranchName.

6. Create a public member function void display(string dbranch) which display the details of customer those are having account at the given branch(i.e.dbranch). IF there is no customer(even one customer) then print "Nil".

main method implementation:



1
Expert's answer
2021-05-19T05:05:09-0400
#include <iostream>
#include <string>


using namespace std;


class Customer
{
private:
	//1. Create private int variable CustomerID to store the customer id.
	int CustomerID;
	//2. Create private string variable CustomerName to store the customer name.
	string CustomerName;
	//3. Create private float variable CustomerBalance to store the customer account balance.
	float CustomerBalance;
	//4. Create private string variable BranchName to store the customer account holding branch name.
	string BranchName;


public:


	Customer(){}
	//Destructor
	~Customer(){}
	// 5. Create a public member function void read() to read the input from user such CustomerID, CustomerName, CustomerBalance and BranchName.
	void read()
	{
		cout << "Enter Customer ID: ";
		cin >> CustomerID;
		cin.ignore();
		cout << "Enter Customer Name: ";
		getline(cin,CustomerName);
		cout << "Enter Customer Balance: ";
		cin >> CustomerBalance;
		cin.ignore();
		cout << "Enter Branch Name: ";
		getline(cin,BranchName);


	}
	//6. Create a public member function void display(string dbranch) which display the details of customer 
	//those are having account at the given branch(i.e.dbranch). IF there is no customer(even one customer) then print "Nil".
	void display(string dbranch)
	{
		if(BranchName.compare(dbranch)==0){
			cout << "The Customer ID: " << CustomerID << endl;
			cout << "The Customer name: " << CustomerName << endl;
			cout << "The Customer Balance: " << CustomerBalance << endl;
			cout << "The Branch Name: " << BranchName << endl;
		}else{
			cout << "Nil"<< endl;
		}
	}
};




int main(void){
	Customer customers[100];
	int n;
	cout<<"Enter the number of customers: ";
	cin>>n;
	for(int i=0;i<n;i++){
		customers[i].read();
	}
	string dbranch;
	cout << "Enter Branch Name to display: ";
	getline(cin,dbranch);
	for(int i=0;i<n;i++){
		customers[i].display(dbranch);
		cout<<"\n";
	}
	system("pause");
	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