Concept explainers
Define a class named PrimeNumber that stores a prime number. The default constructor should set the prime number to l. Add another constructor that allows the caller to set the prime number. Also, add a function to get the prime number. Finally, overload the prefix and postfix ++ and -- operators so they return a Prime-Number object that is the next largest prime number (for ++) and the next smallest prime number (for For example, if the object’s prime number is set to 13, then invoking ++ should return a PrimeNumber object whose prime number is set to 17. Create an appropriate test
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Absolute C++
Additional Engineering Textbook Solutions
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)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Elementary Surveying: An Introduction To Geomatics (15th Edition)
Concepts Of Programming Languages
Starting Out with Python (4th Edition)
- Write a class ‘Box’ which has three members height, width and depth; To set values and use these members, write mutator and accessor functions for these members. (Hint: there would be 3 Accessor and 3 Mutator functions).arrow_forwardIn number theory, a value can be categorized as a natural number (a whole number >0, often denoted ℕ), an integer (zero or a positive or negative whole number, including the natural numbers, often denoted ℤ), or a real number (which includes the natural numbers and integers, along with all other positive and negative numbers that are not integers, often denoted ℝ). a) write a definition for a number class that contains: (i) A single field suitable for storing either a natural number, or an integer, or a real number; (ii) Setter and getter methods for manipulating this field; (iii) A constructor that initializes new objects of number to have the value 1 (unity); (iv) a method that determines which kind of number is currently stored (returning 0 if the number is real and an integer and a natural number, 1 if the number is real and integer but not a natural number, and 2 if the number is real but neither an integer nor a natural number) Java code neededarrow_forwardThe operator that is required to access members of classes and structs is called: a. Colon operator b. Scope resolution operator c. Operator overloading d. Member access operator e. None of the answers Answer: What is the name of the program that uses and interacts with the class? Answer: By assuming that all libraries are included, replace MYFUNCTION with the proper function name to make the code correct: 001010 111101101 01010101111110 1010101010101 111010101010 0101100 vector> MyVector; int rows= 10, cols = 4; MyVector.MYFUNCTION(rows, vector(cols, 100)); cout << MyVector [0] [1] << endl; for (int i } = 0; i < MyVector.size(); i++) { for (int j 0; j < MyVector[i].size(); j++) cout << MyVector[i][j] << " "; cout << endl;arrow_forward
- Write a Rectangle class that has the following fields: Length (L): a double - Width (W): a double The class should have the following functions: Constructor: accepts the length (L) and the width (W) of a rectangle as arguments. Constructor: does not take any parameters and initializes the length(L) and width(W) to zero. - A function called getArea which returns the area of the rectangle. A function called getPerimeter which returns the perimeter of the rectangle. {note: The area of a rectangle =L*W, and its perimeter = 2*(L+W) } Then, write a program to ask the user to enter the length and width of a rectangle, and then use the above class to calculate and print the area and perimeter of the rectangle.arrow_forwarddayType Class We will be working on a project that designs a class calendarType, so that a client program can use this class to print a calendar for any month starting Jan 1. 1900. An example of the calendar for September 2019 is: September 2019 Sun Mon Tue Wed Thu Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 We will develop several classes which will work together to create a calendar. The first of these classes is called dayType which will manipulate a day of the week. The class dayType will store a day, such as Sun for Sunday. The class should be able to perform the following operations on an object of type dayType: a. Set the day. b. Print the day. c. Return the day. d. Return the next day. e.…arrow_forwardWrite a class Runner having three private data members (distance, minutes, seconds) The class has A constructor which having no parameter – for setting values to zero or null.Getters/setters for data members.Write a function show() which displays the“The player covered “+distance+ “ in “ +minutes +” minutes , and “ + seconds+” seconds”; Write test Application that demonstrates the above class by calling all the methods, creating a Create 3 Runner objects, input values and then display the record of winner.in javaarrow_forward
- JAVA-Homework Write a Java program to create Human as a class with Hpersonname and Hpersonage as members of class HUman, and can make employee and Lecturer as the subclasses of Human (a class can have any number of subclasses). In the employee class, we can define grade member and in the Lecturer class also income member will be defined. 1. The program must be able to store information about employee and Lecturer. we want to store the Hpersonname and Hpersonage with grade of employee and the Hpersonname and Hpersonage with income of lecturer.arrow_forwardWrite a code which contains a class CBookList with Private members: CBook books, int ListID. A constructor, which takes the above two arguments as input and assigns them to the class members. The constructor should also cater for default Getter and setter accessor functions for all PrintSome function which cout’s the details of the entire list of books in the particular PrintAll function which cout’s the details of the entire list of books in the entire A destructor. A function to add new nodes to the list, where each node is a CBook type object. Initial insertion should be done at the end of A sort function, that should be able to sort the entire list of books in ascending or descending order of their ID’s. Add and Delete functions to add lists and remove book DeleteAll function to remove all books starting from the head of thearrow_forwardC++ OOP use classes only..arrow_forward
- Write a class named as vehicle which has some attributes this class has three functions.i.e.fuelAmount ()loadingCapacity()applyBrakes()enginePower()Write a class named as Bus, Car and Truck which are inherited from class Vehicle. Also write the setter/getter, default and parameterized constructor in each class. Write a main which create object of derived class and call all inherited function of base class.Note: Each class should have at least two attribute of base class.arrow_forwardSOLVE IN "C#" Write a program to create a class employee, it consist of ID, name, department and address. All employees belongs to “Computer Science” department and it can never be changed by any means. Employee ID is initialized only once when Employee object is created, any further attempt to change ID should be failed. Class must have a 3 parameterized constructor to set values and two methods: print(): to display all the data of a particular employee totalObjects(): to count and print total number of objects that has been created In Main(), create atleast two objects of employee class, display their records by calling print() function and also print the total number of objects that has been created. Sample Main Method: static void Main(string[] args) { Employee obj1 = new Employee(1, "AMMAD", "Karachi"); obj1.print(); Employee obj2 = new Employee(2, "ALI", "Islamabad"); obj2.print(); Employee.totalObjects(); }arrow_forwardSuppose that a class is defined to represent a deck of cards or a player's hand in a card game. This class is implemented as below: A class, also, is defined to develop a card game in which a list of all players' names and their hand is stored. Part of the implementation of this class looks like the following code: A) Specify what should be the return type of getPlayersHand()? B) Assume that the cardGame is a composition of Deck. With this assumption, i) implemnt getPlayerHand(). ii) implement the overloaded constructor of Deck. No java methods can be used for part ii. C) Assume that cardGame is an aggregation of Deck. With this assumption, implement getPalyerHand(). D) An equals() method has been implemented for Deck class. Fill in the gaps to create a fully working equals() method.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,