Question

Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...

Here is the UML for the class

Contact

-fullName : string

-phoneNum: string

-emailAddress : string

+Contact()                     //default constructor sets all attribute strings to “unknown”; no other constructor

+setName(string name) : void

+setPhone(string pn) : void

+setEmail(string em) : void

+getName() : string

+getPhone() : string

+getEmail() : string

+printContact() : void         //print out the name, phone numbers and email address

Create New Project

Name your project: CIS247_Lab7_YourLastName. For this exercise, you may use a header file or one file for the whole project.

Coding the Class Except Setters

In coding the class, the default constructor should set all string variables to “unknown”. We will not use a constructor with parameters this time. The printContact() method should print out the name, phone numbers and email address with titles. Code the getters as usual – return the attribute value. See below for coding the setters.

Coding the setName() method

The setter will check that the name does not start with a number (digit). I know some names end with numbers so let’s just do this simple check. Use a try block. Test that the first letter of the string is not a digit (use the isdigit() function). If this first letter is a digit, throw the first letter. If not (else), go ahead and set the fullName to the parameter. The catch block will catch the character thrown and print an error message saying that names cannot start with a number. So if the error is thrown, the name will remain “unknown”.

Coding the setPhone() method

Put your error checks in a try block. We will check first that the string is 10 characters long (assume no hyphens or spaces). You can use the length function, that is, the length of a string variable named x would be x.length(). If the string is not 10 characters, throw a number such as a 10. Then use a for loop to check if all characters in the string are digits. If you find one that is not a digit, throw a number such as 0. The catch block will catch the number and check it to print the appropriate error message. If you get past the catch block, that means the phone number was OK. If the error is thrown, the phone number will remain “unknown”.

Coding the setEmail() method

In the try block, check each character in the string using the string length function with a for loop. Set up a counter as well and initialize it to zero. When you find an @ sign in the string, increment the count. After the loop, if the count is 1, all is OK. If the count is not equal to one, throw the count; else set the attribute equal to the parameter. The catch block should catch the count. If it is zero, report that email addresses need an @ sign. If it is over one, report that email addresses can only have one @ sign. Thus if an error is thrown, the email address will remain “unknown.”

The main function

In the main function, declare a Contact object. Declare some string variables for the name, phone numbers and email address.

Display prompts to the user to enter their full name, cell phone and email address. Use getline to get the strings into the local variables. Then use the setters and pass the local variables. Finally display the Contact information using printContact().

Test your program with these kinds of errors:

A name that starts with a digit.

A phone number that is too short and too long

A phone number that has some letters in it but is 10 characters.

An email address with no @ sign.

An email address with more than one @ sign.

0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Here is the UML for the class Contact -fullName : string -phoneNum: string -emailAddress : string...
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
  • USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot...

    USING THIS CODE: #include <iostream> #include <string> using namespace std; class Contact { //this class cannot be viewed from outside of the private class. //only the class functions within the class can access private members. private: string name; string email; string phone; //the public class is accessible from anywhere outside of the class //however can only be within the program. public: string getName() const { return name; } void setName(string name) { this->name = name; } string getEmail() const {...

  • I'm struggling to figure out how to do this problem in Java, any help would be...

    I'm struggling to figure out how to do this problem in Java, any help would be appreciated: Create an application that uses a class to store and display contact information. Console: Welcome to the Contact List application Enter first name: Mike Enter last name: Murach Enter email:      [email protected] Enter phone:      800-221-5528 -------------------------------------------- ---- Current Contact ----------------------- -------------------------------------------- Name:           Mike Murach Email Address: [email protected] Phone Number:   800-221-5528 -------------------------------------------- Continue? (y/n): n Specifications Use a class named Contact to store the data...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Write in C++ please: Write a class named MyVector using the following UML diagram and class...

    Write in C++ please: Write a class named MyVector using the following UML diagram and class attribute descriptions. MyVector will use a linked listed instead of an array. Each Contact is a struct that will store a name and a phone number. Demonstrate your class in a program for storing Contacts. The program should present the user with a menu for adding, removing, and retrieving Contact info. MyVector Contact name: string phone: string next: Contact -head: Contact -tail: Contact -list_size:...

  • Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty...

    Complete the Person class: For setEmail, setFirstName, and setSurname: if the method is passed an empty string, it should do nothing; but otherwise it should set the appropriate field. For setMobile: if the method is passed a valid mobile phone number, it should set the appropriate field; otherwise it should do nothing. A string is a valid mobile phone number if every character in it is a digit from 0 to 9. Hints: To convert a string so you can...

  • Requirements Create an Address Book class in Java for general use with the following behaviors: 1....

    Requirements Create an Address Book class in Java for general use with the following behaviors: 1. Constructor: public Address Book Construct a new address book object. • A contact has four fields: first name, last name, email and phone. (There could be more information for a real contact. But these are sufficient for the assignment.) . The constructor reads from the disk to retrieve previously entered contacts. If previous contacts exist, the address book will be populated with those contacts...

  • Please do this in C++. Thank you in advance. Note that you have to carefully create...

    Please do this in C++. Thank you in advance. Note that you have to carefully create your class using the names and capitalization shown below. Put comments into your program, make sure you indent your program properly, and use good naming conventions. Create a class called entry. It should have two private data members of type std::string. One represents a name and the other represents an email address. Make sure you give them ,meaningful names. Create public getters and setters...

  • I need the following written in Java please, thank you ' We want you to implement...

    I need the following written in Java please, thank you ' We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...

  • employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name;...

    employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

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