Concept explainers
Cumulatively modify the example from Display 8.7 as follows.
- In Display 8.7, replace the private char members first and second with an array of char of size 100 and a private data member named size. Provide a default constructor that initializes Size to 10 and sets the first 10 of the char positions to • . (This only uses 10 of the possible 100 slots.) Provide an accessor function that returns the value of the private member size.
- Add an operator member that returns a char& that allows the user to access or to set any member of the private data array using a non-negative index that is less than size.
- Add a constructor that takes an int argument, sz, that sets the first sz members of the char array to ' # '.
- Add a constructor that takes an int argument, sz, and an array of char of size sz. The constructor should set the first sz members of the private data array to the sz members of the argument array of char.
Test.
Test.
Test.
Test.
NOTES: When you test, you should test with known good values, with data on boundaries and with deliberately bad values. You are not required to put checks for index out of bounds errors in your code, but that would be a nice touch. Error handling alternatives: Issue an error message then die (that is, call exit (1)) or give the user another chance to make a correct entry.
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
ABSOLUTE C++ -TEXT
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
SURVEY OF OPERATING SYSTEMS
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out With Visual Basic (8th Edition)
- This is the question I am stuck on - A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer argument and returns the CollegeCourse in that position (0 through 4). Next, create a set method that sets the value of one of the Student’s CollegeCourse objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4). B. Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for…arrow_forwardThis is the question I am stuck on - A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer argument and returns the CollegeCourse in that position (0 through 4). Next, create a set method that sets the value of one of the Student’s CollegeCourse objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4). B. Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for…arrow_forwardThis is the question I am stuck on - A. Create a CollegeCourse class. The class contains fields for the course ID (for example, CIS 210), credit hours (for example, 3), and a letter grade (for example, A). Include get and set methods for each field. Create a Student class containing an ID number and an array of five CollegeCourse objects. Create a get and set method for the Student ID number. Also create a get method that returns one of the Student’s CollegeCourses; the method takes an integer argument and returns the CollegeCourse in that position (0 through 4). Next, create a set method that sets the value of one of the Student’s CollegeCourse objects; the method takes two arguments—a CollegeCourse and an integer representing the CollegeCourse’s position (0 through 4). B. Write an application that prompts a professor to enter grades for five different courses each for 10 students. Prompt the professor to enter data for one student at a time, including student ID and course data for…arrow_forward
- Create a Student class, where attributes associated with each student are name, registration number, father name, degree and department. All attributes should not be accessed directly. One can view the details of all students. Note student attributes can not be changed by any means after initialization.In student class maintaining student count means your program could be able to tell the count of student objects created. (User static counter variable)arrow_forward//3. toggleCommentSection//a. Receives a postId as the parameter//b. Selects the section element with the data-post-id attribute equal to the postId//received as a parameter//c. Use code to verify the section exists before attempting to access the classList//property//d. At this point in your code, the section will not exist. You can create one to test if//desired.//e. Toggles the class 'hide' on the section element//f. Return the section element function code so far passes a.b,c fails rest function toggleCommentSection(postId) { // If Post Id Is Passed, Return Undefined if (!postId) { return undefined; } else { // Else, Get All Comment Sections const commentSections = document.querySelectorAll('[data-post-id]'); // Loop Through Each Comment Section for (let i = 0; i < commentSections.length; i++) { const commentSection = commentSections[i]; // If Post Id Attribut Of Comment Section Is Equal To Post Id Passed Arg…arrow_forwardRules: Corner cases. By convention, the row and column indices are integers between 0 and n − 1, where (0, 0) is the upper-left site. Throw an IllegalArgumentException if any argument to open(), isOpen(), or isFull() is outside its prescribed range. Throw an IllegalArgumentException in the constructor if n ≤ 0. Unit testing. Your main() method must call each public constructor and method directly and help verify that they work as prescribed (e.g., by printing results to standard output). Performance requirements. The constructor must take Θ(n^2) time; all instance methods must take Θ(1)Θ(1) time plus Θ(1)Θ(1) calls to union() and find().arrow_forward
- Create a class called Student that includes a data member that holds a name for each object created from the class and a data member that represents the number of students. That is, the first object created will be 1, the second 2, and so on.To do this, you’ll need another data member that records a count of how many objects have been created so far. (What keyword specifies this?) Then, as each object is created, its constructor increase the count member variable by one.Then write a main() program that creates three objects and queries each one about their names and the count.arrow_forwardWrite code for a test class with the following details:1. Create an object of each class mentioned in Question 3, assuming the values for the data members of each class. Create an array that takes the objects of ALL the classes as its elements. Write an enhanced for loop to display the object details. 2. the dealer in Question 4 decides to offer 2% percent discount on the commission at runtime. Write codewith explanation. 3. Add code to the test class that writes the invoice details of Question 6 to a txt document Syntax of the q3 code is given below: import java.util.*; class Car{ //class car String[] name; int reg_number,eng_number, chassis_num,status; String[] city, model, color, date_reg,date_arr,type; float price; float abstract calculate (float price); } class Dealer extends Car{ //inherits from Car String[] deal_name, deal_id, deal_add, deal_pno; float dealer_com ; float abstract calculate (float price) { dealer_com= 0.01*price +…arrow_forward: Create a class for invoice item having attributes invoice id (it’ll be unique for every invoice item), item description (name of product and details), quantity (number of items), and price (sail price). There is behavior to set all values. There is a display method that will show invoice id, item description, quantity, price of single item and total amount of the invoice item. Create objects to show following details. ID Name Quantity Price Total Amount 1 Chips 50 mg small pack 12 10 120 2 Chocolate Biscuit small pack 15 5 75 Note.... this is a Java program questionarrow_forward
- Write a program that uses a structure to store the information about the Items in a retail store. It has Items with name, manufacturer (Final) and price. 1. Provide default & Parameterized constructors. 2. Provide getters & setters for data members. 3. Provide A toString() method to print values. We can add several items to Store. Now create another class store which has name, city and array of Items. 1. Provide default & Parameterized constructors. 2. Provide getters & setters for data members. 3. Provide necessary validation checks ( null pointer exception, index out of bounds,etc). where possible. 4. Provide a method AddItem (Item i) which is used to add items into the store, but number of items should be less than the size of array (check for exception). 5. A print function which shows all items in the store. 6. Create Test Application and test the functionality of above classes. Use exception also Programming language : Javaarrow_forward1. Declare an array to save 4 Dog objects. The Dog class is provided below. Look into the Dog class and find what attributes are needed for a dog object. Then initialize five dogs with the following information: Lily, 5 years old Jacob, 2 years old Sugar, 8 years old Bush, 3 years old 2. Print out every dog using a for loop (use either regular for loop or for-each loop, your choice). But you may find when you print out, the name and age are not displayed. Why? 3. Fix this problem by implementing the toString method in the Dog class. Dog Class: public class Dog { private String name; private int age; public Dog(String name, int age) { this.name = name; this.age = age; } public void setName(String name) { this.name = name; } }arrow_forwardIn GO language. Create a struct that has student name, id, and GPA. Write functions to create a student, modify the student’s id, and modify the student's GPA, and print the student’s information. (This is like creating a class and methods). Now create an array of three students and test your functions. You may hardcode your values if using a web conpiler. (Please hardcode the values!)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education