Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
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
In Java please.
Add comments too!
thank you!
For this part in the assignment, you need to write a program in python that removes allinstances of a target element in a file named inputFile.txt. The user must enter the instance thatyou need to remove from that file. Once you received that instance, you need to check all thecontent in the inputFile.txt and remove that word. The result will be saved in another file calledoutputFile.txt. For example, if you received that the user wants to remove the word “and”, youneed to identify all the matches and remove them in the outputFile.txt document.Requirements: You should create the content in the inputFile.txt, please make them at leastwith ten lines or more. You could include poems, lyrics, news, etc. It is up to you. Also, youmust use functions to solve this part in the assignment
Getting the attached error when inputting the below syntax...help
ORIGINAL QUESTION:
In the Array class of the arrays.py file complete the following:
Add preconditions to the methods __getitem__ and __setitem__.
The precondition of each method is 0 <= index < size().
Be sure to raise an IndexError exception if the precondition is not satisfied.
To test your program run the main() method in the arrays.py file.
Your program's output should look like the following:
Physical size: 10 Logical size: 0 Items: [None, None, None, None, None, None, None, None, None, None] Traceback (most recent call last): File ".solution/arrays.py", line 69, in <module> main() File ".solution/arrays.py", line 66, in main print(a[0]) File ".solution/arrays.py", line 45, in __getitem__ raise IndexError("Array index out of bounds") IndexError: Array index out of bounds
SYNTAX
Adds a precondition on __getitem__ and __setitem__and raises an exception if it is not satisfied.
An Array is a…
Chapter 16 Solutions
Problem Solving with C++ (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
- answer in java languagearrow_forwardFor an array of size 3, what exception will be thrown if the user tried to access element 4?arrow_forwardTableAA.java Write a program that will store a multiplication table in a 2-D array. The user will enter how many lines (rows) it will have. The table will be printed to the screen. (Make it look nice – consider using printf.) This program will contain a static method. This method will take in an integer (the user’s number) and it will return a 2-D array. The code inside of the method will create the array, fill it with all the appropriate values that one would expect in a multiplication table, and then return that filled array. In the main method, you will ask the user how many lines they want to see and then you will use your static method to get the array. Once you have the array back from the static method, use nested for loops to print it in table form. See samples on the following pages. Program only needs to run once. Add try/catches so the user can only enter positive integers (1 and higher).arrow_forward
- IN C++ Write a method that lets you insert a number anywhere in an array that is already full. For instance, if you have an array of size 5: 3,6,1,2,0. You should be able to insert the number 9 in some desired/specified position. E.g 3,6,1,9,2,0.arrow_forwardin javaarrow_forwardNeed help with this question Write a Java program that asks the user to enter an array of integers in the main method. The program should prompt the user for the number of elements in the array and then the elements of the array. The program should then call a method named minGap that accepts the array entered by the user as a parameter and returns the minimum 'gap' between adjacent values in the array. The main method should then print the value returned by the method. The gap between two adjacent values in an array is defined as the difference in value between the first element and the second element. For example, suppose the user entered the following array of integers {1, 3, 6, 5, 12} The first gap is 2 (3 - 1), the second gap is 3 (6 - 3), the third gap is 1 (6 - 5) and the fourth gap is 5 (12 - 6). Thus, the call of minGap(array) should return 1 because that is the smallest gap in the array. If you are passed an array with fewer than 2 elements, you…arrow_forward
- 7. Compute set of number. Waiting for codearrow_forwardA bit new to methods and need a little bit of help. Swap Method Your task is to write a public static method named swap that takes a single parameter which is an array of doubles. This method should swap the first and last element in the array and then return the adjusted double array. You can assume that all arrays passed into the method are a length of 2 or more. For example, the test data provided when passed into the swap method should go from: {8.34, 7.221, 10.643, 93.2} toarrow_forwardWrite a C# program that creates an array of 50 doubles. You should then write METHODS to do the following: (a) displaythe contents of the array (void method, with a double array parameter), (b) fill the array with random double values(void method, with a double array parameter), (c) count the elements in the array greater than a passed value (returnsan integer, with a double array parameter and a value parameter) ‐‐ value to be checked should be read in from theuser, (d) return the range of values in the array by computing the difference between the largest and smallest values(returns a double, with a double array parameter) and (e) report the largest and smallest values in the array (voidmethod, with a double array parameter, and ‘out’ parameters for the largest and smallest values). You may use any ofthe built in array methods in C# in your implementation of the current methods. Challenge assignment: Write a methodthat computes the standard deviation of the elements in the array…arrow_forward
- 2. write two method called findIndex and findLastIndex that search for a number in an array. they should take an int array and an int as parameters. findIndex should return the index of the first instance of the number in the array. findLastIndex should return the index of the last instance of the number in the array. They both should return -1 if the number is not found. Do not use any library methods. Sample code int a[] int x = findIndex(a,50); Sample output {10,50,30, 40,50}; 1 System.out.println(x); int a[] int x = findLastIndex (a,50); System.out.println(x); int a[] = {10,50,30,40,50}; int x = findIndex(a,70); {10,50,30,40,50}; 4 -1 System.out.println(x);arrow_forwardWrite a java program to create prices of Shopping Cart items that provides a menu: 1: Create a new price for each item in the Cart list 2: Print the price of a particular item 0: Exit Enter your choice: Define an array: ShoppingCart which stores prices of items. Define another array: ItemsNames of the same size that stores names of such items. Assume that there are 10 items. When the user presses 1, the program call a method that creates a new price for each item in the array using random numbersbetween 1 and 1000 AED [not inclusive]. If the user presses 2, the program call a method that prints the name of the requested item and its price. Use switch case statement for choosing among the menu options. Make a method to display the menu to give the user the possibility to use the menu as much as he/she wants.arrow_forwardWrite a java program to create prices of Shopping Cart items that provides a menu: 1: Create a new price for each item in the Cart list 2: Print the price of a particular item 0: Exit Enter your choice: Define an array: ShoppingCart which stores prices of items. Define another array: ItemsNames of the same size that stores names of such items. Assume that there are 10 items. When the user presses 1, the program call a method that creates a new price for each item in the array using random numbers between 1 and 1000 AED [not inclusive]. If the user presses 2, the program call a method that prints the name of the requested item and its price. Use switch case statement for choosing among the menu options. Make a method to display the menu to give the user the possibility to use the menu as much as he/she wants.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT