Answer to Question #263402 in C++ for donya

Question #263402

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).



1
Expert's answer
2021-11-09T17:46:52-0500
#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;
}

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
APPROVED BY CLIENTS