Question

C++ Question Create the ADT of the Phone class. Phone uses three integer variables that describe...

C++ Question

Create the ADT of the Phone class. Phone uses three integer variables that describe a phone number. Example: Part1: 123, Part2: 456, Part3: 0001 describes the phone number (123)456-0001.

Also, add to the Phone ADT class any constructor, any accessor and any mutator function that you may find helpful. Also, add the precondition and postcondition of each function.

If you could add comments to explain what you are doing that would be very helpful, but not necessary. Thank you! Also, please use simple C++ methods because this is only for cs 1.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

==============

#include <iostream>

using namespace std;

class Phone {

private:

string part1, part2, part3;

public:

Phone() {

part1 = "123";

part2 = "456";

part3 = "0001";

}

void setPart1(string p1) {

part1 = p1;

}

string getPart1() {

return part1;

}

void setPart2(string p2) {

part2 = p2;

}

string getPart2() {

return part2;

}

void setPart3(string p3) {

part3 = p3;

}

string getPart3() {

return part3;

}

void displayPhoneNumber() {

cout << "(" << part1 << ")" << part2 << "-" << part3;

}

};

Add a comment
Know the answer?
Add Answer to:
C++ Question Create the ADT of the Phone class. Phone uses three integer variables that describe...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • in C++: Create a class named Student that has three member variables: name - string that...

    in C++: Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100. classList - an array of strings of size 100 used to store the names of the classes that the student is enrolled in Write the appropriate constructor(s), mutator and accessor functions for the class along with...

  • In python Create a class that holds personal data: name, address, age, and phone number. Write...

    In python Create a class that holds personal data: name, address, age, and phone number. Write the necessary get (accessor) and set mutator methods. Also include a program that creates three instances of the class. This could be you and 2 friends or 2 family members.

  • 3. write a c++ program: Design and implement a class called Clock that describes the time...

    3. write a c++ program: Design and implement a class called Clock that describes the time of a clock: a) Include in the class 3 constructors with one, two, and three parameters to set the hours, the minutes, and the seconds, respectively. b) Include also a default constructor that sets the member variables of the class to 00:00:00. c) Write a member function to increment the time by a given amount, and second member function to reset the clock. The...

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • C++ programming Phone Book Create a class that can be used for a Phone Book. The...

    C++ programming Phone Book Create a class that can be used for a Phone Book. The class should have attributes for the name and phone number. The constructor should accept a name and a phone number. You should have methods that allow the name to be retrieved, the phone number to be retrieved, and one to allow the phone number to be changed. Create a toString() method to allow the name and number to be printed. Write a program that...

  • You will need to first create an object class encapsulating a Trivia Game which INHERITS from...

    You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: description - which is a string write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money - double 3. number of questions that must be answered to win - integer. 4. write the accessor, mutator, constructor,...

  • Code the following Program in C++ Define a class named Payment that contains a member variable...

    Code the following Program in C++ Define a class named Payment that contains a member variable of type float that stores the amount of the payment and appropriate accessor and mutator methods.    Also create a member function named paymentDetails that outputs an English sentence that describes the amount of the payment. Next define a class named CashPayment that is derived from Payment. This class should redefine the paymentDetails function to indicate that the payment is in cash. Include appropriate constructor(s)....

  • Design a class for python named PersonData with the following member variables: lastName firstName address city...

    Design a class for python named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be...

  • C++ Visul Studio Create a class named Vehicle. The class has the following five member variables:...

    C++ Visul Studio Create a class named Vehicle. The class has the following five member variables: • Vehicle Name • Vehicle number • Sale Tax • Unit price • Total price Include set (mutator) and get (accessor) functions for each field except the total price field. The set function prompt the user for values for each field. This class also needs a function named computePrice() to compute the total price (quantity times unit price + salesTax) and a function to...

  • C++ Programing In this exercise, you will design a class memberType. The class has the following...

    C++ Programing In this exercise, you will design a class memberType. The class has the following data members: memberName. A string that holds the name of a person memberID. A string that holds the member identification number numBooks. An int that holds the number of books bought purchaseAmt. A double that holds the amount spent on books In addition, the class should have the following constructor and other member functions. Constructor. The constructor should accept the person’s name and member...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT