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++
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Starting Out with Programming Logic and Design (4th Edition)
Problem Solving with C++ (9th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
Problem Solving with C++ (10th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
- 10. Please do in java code DJ classDesign, implement and test a DJ class. A DJ object has a name - djName and an isHired attribute (boolean). Also, a DJ object has 3 musicTypes. These are references to the Music class, where the musicType is declared. In Stage 2 you will be required to declare these 3 instance variables as 1 array.A DJ object can return the value of each of its attributes, and change the value of each of its attributes. It can also display itself in the form:Kongapa, Play List: Disco, Rap, Heavy Metal is hiredImpressions, Play List: House, Hip Hop, Jazz is availablearrow_forwardCreate a class called Point that has two data members: x- and y-coordinates of the point. Provide a no-argument and a 2-argument constructor. Provide separate get and set functions for the each ofthe data members i.e. getX, getY, setX, setY. The getter functions should return the corresponding values to the calling function. Provide a display method to display the point in (x, y) format. Make appropriate functions const. Derive a class Circle from this Point class that has an additional data member: radius of the circle. The point from which this circle is derived represents the center of circle. Provide a no-argument constructor to initialize the radius and center coordinates to 0. Provide a 2-argument constructor: one argument to initialize the radius of circle and the other argument to initialize the center of circle (provide an object of point class in the second argument). Provide a 3-argument constructor that takesthree floats to initialize the radius, x-, and y-coordinates of…arrow_forwardCreate a class called Point that has two data members: x- and y-coordinates of the point. Provide a no-argument and a 2-argument constructor. Provide separate get and set functions for the each ofthe data members i.e. getX, getY, setX, setY. The getter functions should return the corresponding values to the calling function. Provide a display method to display the point in (x, y) format. Make appropriate functions const. Derive a class Circle from this Point class that has an additional data member: radius of the circle. The point from which this circle is derived represents the center of circle. Provide a no-argument constructor to initialize the radius and center coordinates to 0. Provide a 2-argument constructor: one argument to initialize the radius of circle and the other argument to initialize the center of circle (provide an object of point class in the second argument). Provide a 3-argument constructor that takesthree floats to initialize the radius, x-, and y-coordinates of…arrow_forward
- Your task is to create a class name polygon that contains 2 data members i.e. length of type float and width (a pointer of type float). Create a single object named “one” in the main and assign values to the data member of the polygon object. Then create another object named “two” that is a copy of the “one”. Create a shallow copy constructor that copies only the pointer data member of the class polygon and then demonstrate that both objects share a common memory i.e. modifying one object in fact modifies the other.Create a display function that will show the values of the polygon object.arrow_forwardCreate a class: “Palindrome” with private data members: upper_limit (int), lower_limit (int) and parameterized constructor, which initializes the values of both data members. Apart from initialization, this constructor also displays the count of palindrome numbers from upper_limit to lower_limit. [Example: upper_limit:50, lower_limit:10, count of palindrome numbers is:4(11 , 22, 33 and 44), also make sure the value of upper_limit should be greater than lower_limit]. programming language - C++arrow_forwardCreate a class: "Palindrome" with private data members: upper limit (int), lower limit (int) and parameterized constructor, which initializes the values of both data members. Apart from initialization, this constructor also displays the count of palindrome numbers from upper_limit to lower_limit. [Example: upper limit:50, lower_limit:10, count of palindrome numbers is: 4(11 , 22, 33 and 44), also make sure the value of upper_limit should be greater than lower limit].arrow_forward
- Create a class Student that contains three members: roll no, name and mark, and threefunctions. Write a first inputStudent() function to get data of student class. Write a secondgetMark() function that returns a student’s mark. Write a third display() function thatdisplays a student’s data. In a main() function, you need to declare 40 students and get dataof all students by using inputStudent() function. And also use a pointer array to keep allstudents by mark greater than 50 and display the searching data of each student in thatpointer array (Use the access operator -> to access a pointer points to member functions ofthe Student class)arrow_forwardIN C++ In your previous class, move the member variables (student name and grades) as private. Create the proper functions to fill data in them. In main, create an instance of that array and fill that instance with data. Call the DisplayInfo() function from main so it prints the content of the object. A screenshot showing the code in Visual Studio and the output (on the console screen). previous activity class code:- #include <iostream>using namespace std;class student{ public: string Name; string grade[3]; void DisplayInfo() { cout<<"Student Name:"<<Name; cout<<"\nGrade:"<<grade[1]; }};int main(){ cout << "Welcome to my world..." << endl; system("pause"); student obj; obj.Name="Rahul"; obj.grade[1]="A++"; obj.DisplayInfo(); return 0;}arrow_forward#Array question.arrow_forward
- Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaidaarrow_forward1. Create a class Employee with parameters name, id, designation, and basicSalary. Use appropriate datatypes and access specifiers. Use default constructor to create objects of employee. Write methods toset and get the values of parameters of employee. Write methods to find total salary of employee andto display the complete details of employee along with total salary. Create another class TestEmployeewhich creates array of n number of employees, uses appropriate set methods to set the values ofparameters of every employee. Display the details of each employee. (Total salary = basic salary + 80%of basic salary)arrow_forward3. Create a class: "Palindrome" with private data members: upper_limit (int), lower limit (int) and parameterized constructor, which initializes the values of both data members. Apart from initialization, this constructor also displays the count of palindrome numbers from upper_limit to lower limit. [Example: upper_limit:50, lower_limit:10, count of palindrome numbers is: 4(11, 22, 33 and 44), also make sure the value of upper_limit should be greater than lower limit].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