Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
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
For this assignment you will be working with arrays and File I/O.
Open a new Java file called Nums.java
Prompt a user to enter the name of a text file containing a series of numbers.
Important Note: the user should be able to type the name any file that is contained inside their own personal Assignment 18 Java project in Eclipse.
Open the file for reading.
The first line of the text file will contain the number of numbers in the file.
Declare an array of the length specified on this first line of the text file.
The subsequent line in the text file will contain a sequence of double numbers - the exact number indicated in the first line of the file.
Read this sequence of numbers into the array using a for loop.
Using the same, or a second, for loop, sum the numbers and report their sum to the user.
Also, multiply the numbers together and report their product to the user.
Then, print this information in a text file named results.txt.
The sum and the product should be printed to one…
In Java please.
Add comments too!
thank you!
In this project you will generate a poker hand containing five cards randomly selected from a deck of cards. The names of the cards are stored in a text string will be converted into an array. The array will be randomly sorted to "shuffle" the deck. Each time the user clicks a Deal button, the last five cards of the array will be removed, reducing the size of the deck size. When the size of the deck drops to zero, a new randomly sorted deck will be generated. A preview of the completed project with a randomly generated hand is shown in Figure 7-50.
Chapter 16 Solutions
Problem Solving with C++ (10th 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
- The local Driver’s License Office has asked you to write a program that grades the written portion of the driver’s license exam. The exam has 20 multiple choice questions. Here are the correct answers: B D A A C A B A C D B C D A D C C B D A A student must correctly answer 15 of the 20 questions to pass the exam. Write a class named DriverExam that holds the correct answers to the exam in an array field. The class should also have an array field that holds the student’s answers. The class should have the following methods: • passed. Returns true if the student passed the exam, or false if the student failed • totalCorrect. Returns the total number of correctly answered questions • totalIncorrect. Returns the total number of incorrectly answered questions • questionsMissed. An int array containing the question numbers of the questions that the student missed Demonstrate the class in a complete program that asks the user to enter a student’s answers, and then displays the…arrow_forwardChallenge 3: Scores.java and TestScores.java Implement a Scores class. The class constructor should accept an array of scores as its argument. The class should have a method that returns the average of the scores. If any score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Implement a TestScores class that creates an array and fills it with numbers given by the user. It should catch the exception thrown when the user enters an illegal value.arrow_forwardWrite a python or C# program that creates an integer array of size 10 and fills the array with positive numbers set by the programmer (not entered by the user). The range of values in the array should be between 1 and 100. Then, the program will remove the duplicate values found in the array (i.e. each value should be found only once in the array). After removing the duplicate values, the size of the new array should be equal to the number of unique values found in the original array.arrow_forward
- 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…arrow_forwardWrite 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.arrow_forwardWrite a C++ program that can delete an element from an array. The user nominates the values to save in the array (as in Assignment 1). The element that has to be removed from the array (nth element) is also provided by the user. The program must ensure that the value for n is valid. After the value has been deleted, the array must be displayed to the user again. Tip: To erase an element, the elements are moved to overwrite the nth element. Note that the array can now save one more position than there are elements. The number of "active" elements in the array must be updated every time.arrow_forward
- Problem: Develop a program which allows the user to enter numbers into an array. Input will be as follows:The user will enter the total number of integersto be entered into the array.The user will then enter that number of unique integers (negative or positive). Do not allow the number of values entered to exceed the array size.DO NOT USE THE JAVA API CLASSES, i.e., Array, Arrays, ArrayList, etc. . That’san immediate 20 points off on your score.Develop methods(SIX)to:‘main’ methodPrint the arraySort the array(YOU MUST DEVELOP YOUR OWN SORT METHOD –don’t use the API classes)Determine and return the highest valueDetermine and return thelowest valueCalculate and return the average value (double)arrow_forwardFor an array of size 3, what exception will be thrown if the user tried to access element 4?arrow_forwardExercise1: Write a program that stores data for 5 students in two different arrays as follows: Name: take student’s names from the console (using Scanner object) then store their names in an array of a String data type GPA: : take student’s GPA from the console (using the same Scanner object) then store their GPAs in an array of a double data type. Exercise 5: Write a program the calculates the maximum number in an array of 10 integers. The input should be taken from the console (using a Scanner object).arrow_forward
- Write a program called final.cpp that takes numbers from the user and places corresponding numbers into an array, one by one. After each new entry from the user, the program prints out the current array of numbers. Several rules must be followed: • Each new number is checked and added to the array ONLY if it is larger than the number in the previous position in the array. This condition is not checked for the first number. In other words, the new number is rejected and nothing is added to the array if the entry is too-small. • The new number is added to the array EXCEPT: • If the user enters a number greater than 60, the number O is added to the array instead. • If the user enters a multiple of 5 (and less than or equal to 60), the number 5 is added to the array instead. The program exits after 7 numbers have been placed into the array. Programming requirements: • You must define and call at least one function. I recommend printArray(.) • You must use at least one arrayarrow_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_forwardWrite a C++ Program Create 4 arrays of type integer having the size of 11 and assign values to only 2 arrays using forloop.• Once values are assigned to 2 arrays then you have to copy the values/elementfrom both arrays and assign/paste those values to the third and fourth array.• After assigning values to the third and fourth array from the first and second array. Displayelements/values of array3 and array4. • Array2 elements/values will be copied to array4.In the end the array 3 and array4 will have the same elements/values as array1 and array2.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