In: Computer Science
C++
1.0: Customer Module
Create a customer account module to hold the residents details. Use a structure to store the following data about the customer account:
| 
 Field  | 
 Description  | 
| 
 Account No  | 
 Start with character C and followed by 5 digits (e.g. C10212)  | 
| 
 Name  | 
 Resident name  | 
| 
 Address  | 
 Current housing address  | 
| 
 Plot Number  | 
 Special identifier of the house (3 digits value)  | 
| 
 Contact No  | 
 Resident HP number (e.g. 0125354123)  | 
| 
 Date of Last Payment  | 
 Date in (dd-mm-yyyy) format. (e.g 15-12-2019)  | 
| 
 Monthly Payment Amount  | 
 Example $130.00  | 
| 
 Account Balance  | 
 Advance payment in the account  | 
The structure should be used to store customer account records in a file. In this module, you should provide a menu (refer to figure 1.0) that lets the user perform the following operations:
| 
 <> 
 Enter Option: Enter Option:  | 
| 
 <> 
 Enter Option:  | 
#include <iostream>
#include <string>
#include <vector>
class Date{
public:
Date(){}
Date(int d, int m, int y){
    day = d;
    month = m;
    year = y;
}
int getDay() const{ return day; }
int getMonth() const{ return month; }
int getYear() const{ return year; }
void setDay(int d){ day = d; }
void setMonth(int m){ month = m; }
void setYear(int y){ year = y; }
friend std::ostream& operator<<(std::ostream&, const
Date&);
friend std::istream& operator>>(std::istream&,
Date&);
private:
int day, month, year;
};
std::ostream& operator<<(std::ostream& o, const
Date& dt)
{
o<<dt.getDay()<<"-"<<dt.getMonth()<<"-"<<dt.getYear();
return o;
}
std::istream& operator>>(std::istream& i,
Date& dt)
{
int d, m, y;
i>>d;
i>>m;
i>>y;
dt.setDay(d);
dt.setMonth(m);
dt.setYear(y);
return i;
}
struct Customer{
std::string accountNo;
std::string name;
std::string address;
int plotNo;
int contactNo;
Date lastPayment;
double monthlyPayment;
double accountBalance;
};
class CustomerModule{
public:
CustomerModule(){}
void addNewCustomer(){
    Customer c;
    std::cout<<"Enter AccountNo: ";
    std::cin>>c.accountNo;
    std::cout<<"Enter Name: ";
    std::cin>>c.name;
    std::cout<<"Enter Address: ";
    std::cin>>c.address;
    std::cout<<"Enter PlotNo: ";
    std::cin>>c.plotNo;
    std::cout<<"Enter ContactNo: ";
    std::cin>>c.contactNo;
    std::cout<<"Enter Date of last
payment(dd-mm-yyyy): ";
    std::cin>>c.lastPayment;
    std::cout<<"Enter Monthly payment:
";
    std::cin>>c.monthlyPayment;
    std::cout<<"Enter Account balance:
";
    std::cin>>c.accountBalance;
    customers.push_back(c);
}
void searchAndDisplay(){
    std::string name;
    std::cout<<"Enter Customer name: ";
    std::cin>>name;
    std::vector<Customer>::iterator it =
customers.begin();
    while(it != customers.end()){
      if((*it).name == name){
       
displayCustomer(*it);
        return;
      }
      it++;
    }
    std::cout<<"Customer
"<<name<<" cannot found!"<<std::endl;
}
void searchAndDelete(){
    std::string name;
    std::cout<<"Enter Customer name: ";
    std::cin>>name;
    std::vector<Customer>::iterator it =
customers.begin();
    while(it != customers.end()){
      if((*it).name == name){
       
customers.erase(it);
        return;
      }
      it++;
    }
    std::cout<<"Customer
"<<name<<" cannot found!"<<std::endl;
}
void searchAndEdit(){
    std::string name;
    std::cout<<"Enter Customer name: ";
    std::cin>>name;
    std::vector<Customer>::iterator it =
customers.begin();
    while(it != customers.end()){
      if((*it).name == name){
        std::cout<<"Edit
"<<name<<"'s record: "<<std::endl;
        std::cout<<"Enter
AccountNo: ";
       
std::cin>>(*it).accountNo;
        std::cout<<"Enter
Name: ";
       
std::cin>>(*it).name;
        std::cout<<"Enter
Address: ";
       
std::cin>>(*it).address;
        std::cout<<"Enter
PlotNo: ";
       
std::cin>>(*it).plotNo;
        std::cout<<"Enter
ContactNo: ";
       
std::cin>>(*it).contactNo;
        std::cout<<"Enter
Date of last payment(dd-mm-yyyy): ";
       
std::cin>>(*it).lastPayment;
        std::cout<<"Enter
Monthly payment: ";
       
std::cin>>(*it).monthlyPayment;
        std::cout<<"Enter
Account balance: ";
       
std::cin>>(*it).accountBalance;
        return;
      }
      it++;
    }
    std::cout<<"Customer
"<<name<<" cannot found!"<<std::endl;
}
void display(){
    std::vector<Customer>::iterator it =
customers.begin();
    std::cout<<"Customers:
"<<std::endl;
    while(it != customers.end()){
      displayCustomer(*it);
     
std::cout<<"-----------------------------"<<std::endl;
      it++;
    }
}
void outstandingRecords(){
    std::vector<Customer>::iterator it =
customers.begin();
    std::cout<<"Outstanding records:
"<<std::endl;
    while(it != customers.end()){
      if((*it).monthlyPayment >=
200){
        std::cout<<"
AccountNo: "<<(*it).accountNo<<" Name:
"<<(*it).name
        <<" Balance will
be: "<<(*it).monthlyPayment * 2<<std::endl;
      }
      it++;
    }
}
private:
void displayCustomer(const Customer& c){
    std::cout<<" AccountNo:
"<<c.accountNo<<std::endl;
    std::cout<<" Name:
"<<c.name<<std::endl;
    std::cout<<" Address:
"<<c.address<<std::endl;
    std::cout<<" PlotNo:
"<<c.plotNo<<std::endl;
    std::cout<<" ContactNo:
"<<c.contactNo<<std::endl;
    std::cout<<" Date of Last payment:
"<<c.lastPayment<<std::endl;
    std::cout<<" Monthly payment:
"<<c.monthlyPayment<<std::endl;
    std::cout<<" Account Balance:
"<<c.accountBalance<<std::endl;
}
private:
std::vector<Customer> customers;
};
int main()
{
int choice;
CustomerModule customer;
while(true){
    std::cout<<"*** Customer Module
***"<<std::endl;
    std::cout<<"1 New
Record"<<std::endl;
    std::cout<<"2 Search
Record"<<std::endl;
    std::cout<<"3 Delete
Record"<<std::endl;
    std::cout<<"4 Edit
Record"<<std::endl;
    std::cout<<"5 List
Records"<<std::endl;
    std::cout<<"6 Outstanding
records"<<std::endl;
    std::cout<<"7
Exit"<<std::endl;
    std::cout<<"Enter option: ";
    std::cin>>choice;
    switch(choice){
      case 1:
       
customer.addNewCustomer();
        break;
      case 2:
       
customer.searchAndDisplay();
        break;
      case 3:
       
customer.searchAndDelete();
        break;
      case 4:
       
customer.searchAndEdit();
        break;
      case 5:
       
customer.display();
        break;
      case 6:
       
customer.outstandingRecords();
        break;
      case 7:
        return 0;
      default:
       
std::cout<<"Invalid choice!"<<std::endl;
        break;
    }
}
return 0;
}