In: Computer Science
PLEASE DO IN C++
Create an object-oriented program that initially allows the user to save customer information in the list and to search for a customer by specifying the customer’s ID.
Sample Run
Customer Information Management System
---------------------------------------------------------------
CUSTOMER DATA ENTRY:
Full Name (First, Last): Jenny Ha
Company: Convergent Laser Technologies
Street: 1000 International Ave
City: Oakland
State: CA
Zip Code: 94506
ID: 100
Continue Your Data Entry? (y/n): y
Full Name (First, Last): Bill Martinez
Company: Cisco Systems
Street: 2000 Jackson St
City: San Jose
State: CA
Zip Code: 95112
ID: 100
This ID exists! Try again.
ID: 200
Continue Your Data Entry? (y/n): n
---------------------------------------------------------------
CUSTOMER DATA SEARCH:
Enter Customer ID: 100
Jenny Ha
Convergent Laser Technologies
1000 International Ave
Oakland, CA 94506
Continue Your Data Search? (y/n): y
Enter Customer ID: 200
Bill Martinez
Cisco Systems
2000 Jackson St
San Jose, CA 95112
Continue Your Data Search? (y/n): y
Enter Customer ID: 99
No customer with that ID.
Continue Your Data Search? (y/n): n
---------------------------------------------------------------
Thank you for using my app!
Specifications
Here is your solution if you have any doubt, then you can write in the comment section.
Please give feedback.
Solution:
#include <iostream> using namespace std; class Customer { //private variables private: string fullName; string company; string street; string city; string state; int zipCode; int id; public: //dummy constructor Customer() { } //constructor Customer(string fullName,string company,string street,string city,string state,int zipCode,int id) { this->fullName=fullName; this->company=company; this->street=street; this->city=city; this->state=state; this->zipCode=zipCode; this->id=id; } //getter methods string getFullName() { return this->fullName; } string getCompany() { return this->company; } string getStreet() { return this->street; } string getCity() { return this->city; } string getState() { return this->state; } int getZipCode() { return this->zipCode; } int getId() { return this->id; } //setter methods void setFullName(string fullName) { this->fullName=fullName; } void setCompany(string company) { this->company=company; } void setStreet(string street) { this->street=street; } void setCity(string city) { this->city=city; } void setState(string state) { this->state=state; } void setZipCode(int zipCode) { this->zipCode=zipCode; } //method to get fullAddress string getFullAddress() { string fullAddress=this->street+"\n"; fullAddress+=(this->city+","); fullAddress+=(this->state+" "); fullAddress+=(to_string(this->zipCode)); return fullAddress; } }; int main() { //creating array of object of class Customer Customer* c = new Customer[20]; //variables int size=0; string fullName; string company; string street; string city; string state; int zipCode; int id; cout<<"Customer Information Management System\n"; cout<<"---------------------------------------------------------------\n"; cout<<"CUSTOMER DATA ENTRY:\n"; char choice='y'; //loop until choice is 'y' while(choice=='y') { if(size<20) { //read data int flag=0; cout<<"Full Name (First, Last): "; getline(cin, fullName); cout<<"Company: "; getline(cin, company); cout<<"Street: "; getline(cin, street); cout<<"City: "; getline(cin, city); cout<<"State: "; getline(cin, state); cout<<"Zip Code: "; cin>>zipCode; cout<<"ID: "; cin>>id; //check if id is valid for(int i=0;i<size;i++) { if(c[i].getId()==id) { flag=1; break; } } //if not valid means already present if(flag==1) { while(1) { flag=0; cout<<"This ID exists! Try again.\n"; cout<<"ID: "; cin>>id; //check again for(int i=0;i<size;i++) { if(c[i].getId()==id) { flag=1; break; } } if(flag==0) { break; } } //if valid then insert c[size]=Customer(fullName,company,street,city,state,zipCode,id); size++; } else { //if valid then insert c[size]=Customer(fullName,company,street,city,state,zipCode,id); size++; } } //if array is full else { cout<<"Array is Full!\n"; } //input choice cout<<"Continue Your Data Entry? (y/n): "; cin>>choice; //ignore for ignoring newline character cin.ignore(); } cout<<"---------------------------------------------------------------\n"; cout<<"CUSTOMER DATA SEARCH:\n"; choice = 'y'; //loop until choice is 'y' while(choice=='y') { int flag=0; cout<<"Enter Customer ID: "; cin>>id; //loop for searching for(int i=0;i<size;i++) { if(c[i].getId()==id) { cout<<c[i].getFullName()<<"\n"; cout<<c[i].getCompany()<<"\n"; cout<<c[i].getFullAddress()<<"\n"; flag=1; break; } } //if not found if(flag!=1) { cout<<"No customer with that ID.\n"; } cout<<"Continue Your Data Search? (y/n): "; cin>>choice; } cout<<"---------------------------------------------------------------\n"; cout<<"Thank you for using my app!\n"; return 0; }
Output:
UML:
Thank You!
input Customer Information Management System CUSTOMER DATA ENTRY: Full Name (First, Last): Jenny Ha Company: Convergent Laser Technologies Street: 1000 International Ave City: Oakland State: CA Zip Code: 94506 ID: 100 Continue Your Data Entry? (y/n): Y Full Name (First, Last) : Bill Martinez Company: Cisco Systems Street: 2000 Jackson St City: San jose State: CA Zip Code: 95112 ID: 100 This ID exists! Try again. ID: 200 Continue Your Data Entry? (y/n): n CUSTOMER DATA SEARCH: Enter Customer ID: 100 Jenny Ha Convergent Laser Technologies 1000 International Ave Oakland, CA 94506 Continue Your Data Search? (y/n): Y
input State: CA Zip Code: 95112 ID: 100 This ID exists! Try again. ID: 200 Continue Your Data Entry? (y/n): n CUSTOMER DATA SEARCH: Enter Customer ID: 100 Jenny Ha Convergent Laser Technologies 1000 International Ave Oakland, CA 94506 Continue Your Data Search? (y/n): Y Enter Customer ID: 200 Bill Martinez Cisco Systems 2000 Jackson St San jose, CA 95112 Continue Your Data Search? (y/n): Y Enter Customer ID: 99 No customer with that ID. Continue Your Data Search? (y/n): n Thank you for using my app! - - Program finished with exit code 0 Press ENTER to exit console.