In: Computer Science
in C++
Requirements: Write a program that creates a new class called Customer. The Customer class should include the following private data: name - the customer's name, a string. phone - the customer's phone number, a string. email - the customer's email address, a string. In addition, the class should include appropriate accessor and mutator functions to set and get each of these values. Have your program create one Customer objects and assign a name, phone number, and email address to it (make this info up in your head) using the methods of the public interface. Then, have the program display the info for the customer to the screen using the accessor methods. Don't forget to mark your accessors const. You do not need to include a constructor.
Answer:
Following is the C++ code for the same
#include <iostream>
using namespace std;
class Customer{
private:
char* name;
char* phone;
char* email;
public:
//Accessor functions
char* getName() const{
return name;
}
char* getPhone() const{
return phone;
}
char* getEmail() const{
return email;
}
//Mutator Functions
void setName(char* n){
name=n;
}
void setPhone(char* p){
phone=p;
}
void setEmail(char* e){
email=e;
}
};
int main() {
Customer customer;
customer.setName("PremKumar");
customer.setPhone("1122334455");
customer.setEmail("[email protected]");
cout<<"Name= "<<customer.getName()<<"\n";
cout<<"Phone= "<<customer.getPhone()<<"\n";
cout<<"Email= "<<customer.getEmail()<<"\n";
return 0;
}
Following are screenshots from the Editor:
Output: