CIS247C Lab 7 New – Exception Handling – Visual studio code with screenshots – Perfect Solution – Instant Delivery
Week 7: Lab Overview
TABLE OF CONTENTS
Lab Overview
Scenario/Summary
The purpose of this lab is to give you experience in using some error prevention techniques of C++. You can create your own error checks and print error messages, but C++ also provides a way of capturing unforeseen errors. The try-throw-catch blocks are ways to handle errors. We put a try block around some code that might produce a foreseen or unforeseen error. For errors we know to check for, we can “throw” an exception (which basically means send an error to a “catch” block. It is also possible to set up catch blocks for unforeseen errors like dividing by zero or a user entering letters when we are trying to enter actual numbers. This Exercise looks at the first type of error.
We will create a class named Contact that contains the full name, phone numbers and email address of a person. We could make a contact list from our Contact objects. We will check that a name starts with a letter. We will check phone numbers for being 10 digits and only containing digits. We will check that the email address has at least one and only one @ sign. Input will come from the keyboard user.
Here is the UML for the class
Contact
-fullName : string
-homePhone : string
-cellPhone : string
-emailAddress : string
+Contact() //default constructor sets all attribute strings to “unknown”; no other constructor
+setName(string name) : void
+setHPhone(string hp) : void
+setCPhone(string cp) : void
+setEmail(string em) : void
+getName() : string
+getHPhone() : string
+getCPhone() : string
+getEmail() : string
+printContact() : void //print out the name, phone numbers and email address
Deliverables
The deliverable for this lab is
• a Word document that contains the project code and screenshots.
Required Software
Microsoft Office: Word
Use a personal copy, or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site..
All Steps
Visual Studio 2015
Use a personal copy, or access the software at https://lab.devry.edu (Links to an external site.)Links to an external site.. You can get a personal copy through the Student Software Store.
Steps: 1–4
Lab Steps
Step 1 – Create New Project
Name your project: CIS247_Exercise7_YourLastName. For this exercise, you may use a header file or one file for the whole project.
Step 2 – Documentation
Add this documentation to the program:
/*
Program: Contact List
Programmer: Your Name
Date:
Purpose: Demonstrate using error checking and throwing errors from your setters to prevent some types of input errors.
*/
Step 3 – 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.
Step 4 – 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”.
Step 5 – Coding the Phone Number setters
Since there are two phone numbers, we will write a special function that can be used to check phone numbers. The function could be named something like checkNum(). This function will return a bool (true if the number is OK; false if the number is “bad”), and it needs one string parameter because you need to pass the phone number to be checked. This function can be private.
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. After printing the error message, return false. If you get past the catch block, that means the phone number was OK so return a true at the bottom of the function.
In setHPhone() and setCPhone(), you can check if the call to checkNum returns true or false. If you get true, then set the phone attribute equal to the parameter; otherwise do nothing and it will remain “unknown”.
Step 6 – 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.”
Step 7 – 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, home phone, 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.
Step 8
Create a Microsoft Word document called Week 7 Lab. At the top, put your information, including your name, course, Week 7 Lab, and the date.
Run your application. Take screenshots while your application is running to demonstrate that it works properly. Remember to hold down the Alt key and the PrtScrn key at the same time (Alt + PrtScrn) to take screenshots of the active window only. Paste these screenshots into your Word document.
Put the file name for each file in the Word document below the screenshots. Bold the file name, and increase the font. Copy and paste the code for each file below its file name. You should have nine files for your project.
Submit the Word document.
* You can also use 2CO option if you want to purchase through Credit Cards/Paypal but make sure you put the correct billing information otherwise you wont be able to receive any download link.
* Your paypal has to be pre-loaded in order to complete the purchase or otherwise please discuss it with us at [email protected].
* As soon as the payment is received, download link of the solution will automatically be sent to the address used in selected payment method.
* Please check your junk mails as the download link email might go there and please be patient for the download link email. Sometimes, due to server congestion, you may receive download link with a delay.
* All the contents are compressed in one zip folder.
* In case if you get stuck at any point during the payment process, please immediately contact us at [email protected] and we will fix it with you.
* We try our best to reach back to you on immediate basis. However, please wait for atleast 8 hours for a response from our side. Afterall, we are humans.
* Comments/Feedbacks are truely welcomed and there might be some incentives for you for the next lab/quiz/assignment.
* In case of any query, please donot hesitate to contact us at [email protected].
* MOST IMPORTANT Please use the tutorials as a guide and they need NOT to be used for any submission. Just take help from the material.
******************************************** Good Luck ***************************************************
Any personal information received will only be used to fill your order. We will not sell or redistribute your information to anyone.
We will try our best to resolve the issue and if still persists we can discuss for a refund in case its required.