Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 16, Problem 7PP
Program Plan Intro
- Include required library files.
- Define a class named “ArrOutOfRangeErr”.
- Declare the required variables, constructors and function inside the access specifier “public” and “private”.
- Define a “testExcep()” function to test the exception.
- Using exception, set and get the values.
- Define a “create2DArr()” function to create an two-dimensional array.
- Define a “check_args()” function to check the validity and return the message if something is wrong.
- Define a “set()” function to store values.
- Define a “get()” function to retrieve the values.
- Define a default constructor for no messages.
- Define a parameterized constructor for row and column data.
- Define a “getMsg()” function to return the exception message string.
- Define a “getRows()” function to return the number of rows.
- Define a “getCols()” function to return the number of columns.
- Define a “getDesiredRow()” function to return the requested row number.
- Define a “getDesiredColumn()” function to return the requested column number.
- Define a “writeErr()” function to write the error message.
- Define a “main()” function.
- Declare the required variables.
- Create a 2D array for rows and columns.
- Populate the rows and columns.
- Print the array contents using “for” loop.
- Then test the some boundary cases.
- Using exception, set and get the values.
- Declare the required variables.
- Create a 2D array for rows and columns.
- Populate the rows and columns.
- Print the array contents using “for” loop.
- Then test the some boundary cases.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Language: Java
Rewrite the ADA source code in Java.Within the Java version of the code, change the second half of the first loop so that all assignments to the counting array 'Freq()' are updated in the EXCEPTION portion of the code. There should be no valid updates to 'Freq()' anywhere else in the loop.ADA source code:with Ada.Text_IO , Ada.Integer_Text_IO ;use Ada.Text_IO, Ada.Integer_Text_IO;procedure Grade_Distribution isFreq: array (1..10) of Integer := (others => 0);New_Grade : Natural;Index,Limit_1,Limit_2 : Integer;beginGrade_Loop:loopbeginGet(New_Grade);exceptionwhen Constraint_Error =>exit Grade_Loop;end;Index := New_Grade/10 + 1;beginFreq(Index) := Freq(Index) +1 ;exceptionwhen Constraint_Error =>if New_Grade = 100 thenFreq(10) := Freq(10) + 1;elsePut("Error -- new grade: ");Put(New_Grade);Put(" is out of range");New_Line;end if;end;end loop Grade_Loop;Put("Limits Frequency");New_Line; New_Line;for Index in 0..8 loopLimit_1 := 10 * Index;Limit_2 := Limit_1 + 9;if…
Create a Java program with a method that searches an integer array for a specified integer value (see help with starting the method header below). If the array contains the specified integer, the method should return its index in the array. If not, the method should throw an Exception stating "Element not found in array" and end gracefully. Test the method in main with an array that you make and with user input for the "needle".public static int returnIndex(int[ ] haystack, int needle) {
Write a program that takes an integer array and perform following operations sum, average, percentage,. The user must non zero integers. If they were not an integer, the program would throw a NumberFormatException if user try to input string instead of integer value. If denominator were Zero, the program would throw an ArithmeticException and Display the exception.
Chapter 16 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Ch. 16.1 - Prob. 1STECh. 16.1 - What would be the output produced by the code in...Ch. 16.1 - Prob. 3STECh. 16.1 - What happens when a throw statement is executed?...Ch. 16.1 - In the code given in Self-Test Exercise 1, what is...Ch. 16.1 - Prob. 6STECh. 16.1 - Prob. 7STECh. 16.1 - What is the output produced by the following...Ch. 16.1 - What is the output produced by the program in...Ch. 16.2 - Prob. 10STE
Knowledge Booster
Similar questions
- Solve In Python Provide Screenshots of Input and Ouput For this lab, you will modify your Lab 7 to make several improvements to the getter/settermethods. Instead of having them return True/False, modify each one to throw an exception ifinvalid data is passed.Modify these methods in the following way:• add_hours()o If the number of hours being added is less than 0, throw an exception• add_sales()o If the amount of sales being added is less than 0, throw an exception• set_employee_number()o The employee number must be an integer. If the given input is not an integer,throw an exception• set_office_number()o If the office number given is less than 100 or greater than 500, throw anexception.• set_name()o If the given name is empty, throw an exceptiono Any of the following characters should be removed from the name: ‘_’, ‘.’, ‘-‘ (Underscore, period, and dash)• set_birthdate()o If the given value for the month is less than 1 or greater than 12, throw anexceptiono If the given value for the…arrow_forwardWrite a program that allows students to schedule appointments at either 1,2,3,4,5 as days of the week; 1 for Monday, 2 for Tuesday and so on. Use an array of five strings to store the names for the time slots. Write a loop that iterates as long as the array has a free space. Within a try block, allow the user to enter a day and a name. If the day is free, put the name in the array. If the day is not free, throw an Exception. If the day is not valid, throw another exception. Use catch block for each different kind of exception. Ex: Enter Day: 1Monday is available, enter Name: Tomas[Tomas, , , , ]Enter Day: 3Wednesday is available, enter Name: Sheldon[Tomas, ,Sheldon, , ]Enter Day: 3Wednesday is not available, choose other day: 2Tuesday is available, enter Name: Raj[Tomas,Raj,Sheldon, , ]Enter Day: 4Thursday is available, enter Name: Leonard[Tomas,Raj,Sheldon,Leonard, ]Enter Day: 0Invalid DayEnter Day: AInvalid DayEnter Day: 5Friday is available, enter Name:…arrow_forwardWrite a program that allows students to schedule appointments at either 1,2,3,4,5 as days of the week; 1 for Monday, 2 for Tuesday and so on. Use an array of five strings to store the names for the time slots. Write a loop that iterates as long as the array has a free space. Within a try block, allow the user to enter a day and a name. If the day is free, put the name in the array. If the day is not free, throw an Exception. If the day is not valid, throw another exception. Use catch block for each different kind of exception.arrow_forward
- The following recursive method is causing an exception because the base case is missing. This method is suppose to display the content of an array backward. For example If the array num contains 1 2 3 4 5 6 then the call print(num, 5) should display: 6 5 4 3 2 1 public static void print(int[] a, int index){ System.out.println(a[index]); print(a, index -1);}Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 5 fill in the blank so that the exception does not happen, in order of the given numbers public static void print(int[] a, int index){if( __1___ ___2__ ___3__) <----- base case __4____ System.out.println(a[index]); print(a, index -1); <---- recursive case}arrow_forwardWrite a program that accepts two integer values, called "arraySize" and "multiplier", as user input. Create an array of integers with arraySize elements. Set each array element to the value i*multiplier, where i is the element's index. Next create two functions, called PrintForward() and PrintBackward(), that each accept two parameters: (a) the array to print, (b) the size of the array. The PrintForward() function should print each integer in the array, beginning with index 0. The PrintBackward() function should print the array in reverse order, beginning with the last element in the array and concluding with the element at index 0. As output, print the array once forward and once backward.arrow_forwardObjective: To write a program to remove duplicates from an array entered via the command line. Please write a program to remove duplicates from the series of numbers specified on the command line. So your program should output just the distinct numbers that were on the command line. Sample output is below: MUST BE ABLE TO INPUT NUMBERS VIA COMMAND LINE > java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main usage: java Main 5 4 2 4 8 To remove duplicates from the numbers 5, 4, 2, 4 and 8 > java Main 5 4 2 4 8 Here are the distinct numbers: 5, 4, 2, 8 > java Main 1 3 5 2 3 5 3 3 5 7 9 3 Here are the distinct numbers: 1, 3, 5, 2, 7, 9arrow_forward
- Write a program in C++ language that reads an array of 20 elements from the keyboard after the required alert message appears, then finds the sum and number of elements that are divisible by 5 and then prints *: the result on the screen as follows Numbers of element in array accept dividing by 5 = Sum of element in array accept dividing by 5 =arrow_forwardWrite a program, Passwords , that contains an array of five names and another array of five passwords. Your program should ask the user to enter a name and a password. If the user enters the correct name with its related password, grant access (e.g. display “Access granted!”). IF the user enters the wrong name/password (can be either or both), allow the user to re-try only once. If the user still cannot enter the correct name/password, display the following: “Sorry, your username/password does not match our database. Contact the administrator.”arrow_forwardTest the Baby class below by writing a client program which uses an array to storeinformation about 4 babies. That is, each of the four elements of the arraymust store a Baby object.If you have an array for baby names and another array for baby ages,then you have missed the point of the exercise and therefore not metthe requirement of this exercise.A Baby class object stores the required information about a Baby. Soeach Baby object will have its own relevant information, and thus eachobject must be stored in one element of the array.The client program should:a. Enter details for each baby (name and age) and thus populate theBaby arrayb. Output the details of each baby from the array (name and age)c. Calculate and display the average age of all babies in the arrayd. Determine whether any two babies in the array are the sameAs the required information for these tasks is stored in the Baby array, youwill need to use a loop to access each array element (and use the dot notationto access…arrow_forward
- Write a java array program that will Read six integer vaules from the user into an array named intArr in main. From within main, print the contents of this unsorted array on one line Pass the unsorted array to a method named sortArray, which will use the swapping technique from class to sort the contents from largest to smallest Send the sorted array back to main and then print it on another linearrow_forwardWrite a program that does the following Declare and create an array named numbers that will hold 6 doublesManually fill the array by assigning values to each indexDeclare an integer array numbers2 that creates and assigns values to indexes in one statementWrite two loops that print each arrayNow, instead of having to write two separate loops that print the arrays create a method and an overloaded method printArray that does the followingAccepts a single parameter of an arrayUses a loop to print the array Sample Output: 23.93 9.4 14.02 1.0 33.333 19.91 47 64 5 100 8 92arrow_forwardPlease Solve the Question in C++ as quickly as you can in 40 minutes. And do the same as asked in the question. Don't use extra things, please. Augment the safearay class in the ARROVER3 program in this chapter so that the user can specify both the upper and lower bound of the array (indexes running from 100 to 200, for example). Have the overloaded subscript operator check the index each time the array is accessed to ensure that it is not out of bounds. You'll need to add a twoargument constructor that specifies the upper and lower bounds. Since we have not yet learned how to allocate memory dynamically, the member data will still be an array that starts at 0 and runs up to 99, but perhaps you can map the indexes for the safearay into different indexes in the real int array. For example, if the client selects a range from 100 to 175, you could map this into the range from arr[0] to arr[75]. Note: Make this class into a template, so the safe array can store any kind of data.…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT