1) Create a class phoneUser. The class should have the following private data members. The class prototype should be stored in the header file phoneUser.h
• Name of phone user (string type)
• Surname of phone user (string type)
• Number of phone user (string type)
Write public getters and setters to modify these data members. Write the function implementation in the source file phoneUser.cpp. There should be three constructors, with no argument (default constructor), with 2 arguments (Name and Surname), with three arguments (Name, Surname, and Number).
#include<iostream>
using namespace std;
class Phoneuser{
private:
 string name;
 string surname;
 int number;
public:
 Phoneuser(string n, string s, int a) {
  setName(n);
  setNumber(a);
  setSurname(s);
 }
 void display() {
  cout << name << " "<<surname<<", " << number;
 }
 void setNumber(int a) {
  if ((a >= 0) && (a <= 120)) {
   number = a;
  }
  else {
   number = 0;
  }
 }
 void setName(string n) {
  name = n;
 }
 string getName() {
  return name;
 }
 void setSurname(string s){
 surname=s;
 }
 string getSurname(){
 return surname;
 }
 int getNumber() {
  return number;
 }
};
int main ()
{
 Phoneuser you("Bob","sc", +234712345);
 you.display();
 return 0;
}
Comments
Leave a comment