Concept explainers
A harder version of
■ Default constructor, List();
■ double List::front();f which returns the first item in the list
■ double List::back();, which returns the last item in the list
■ double List::current();t which returns the “current" item
■ void List::advance();t which advances the item that current() returns
■ void List::reset(); to make current() return the first item in the list
■ void List::insert(double afterMe, double insertMe);, which inserts insertMe into the list after afterMe and increments the private: variable count.
■ int size();which returns the number of items in the list
■ friend istream& operator <<(istream& ins, double writeMe);
The private data members should include the following:
node* head;
node* current;
int count;
and possibly one more pointer.
You will need the following struct (outside the list class) for the linked list nodes:
struct node
{
double item;
node *next;
};
Incremental development is essential to all projects of any size, and this is no exception. Write the definition for the List class, but do not implement any members yet. Place this class definition in a file list.h. Then #include “list.h” in a file that contains int main(){}.Compile your file. This will find syntax errors and many typographical errors that would cause untold difficulty if you attempted to implement members without this check. Then you should implement and compile one member at a time, until you have enough to write test code in your main function.
Want to see the full answer?
Check out a sample textbook solutionChapter 13 Solutions
Problem Solving with C++, Student Value Edition Plus MyLab Programming with Pearson eText - Access Card Package (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Python (3rd Edition)
C Programming Language
C How to Program (8th Edition)
Modern Database Management (12th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
- The base class Pet has attributes name and age. The derived class Dog inherits attributes from the base class Pet class and includes a breed attribute. Complete the program to: Create a generic pet, and print the pet's information using print_info(). Create a Dog pet, use print_info() to print the dog's information, and add a statement to print the dog's breed attribute. Ex: If the input is: Dobby 2 Kreacher 3 German Schnauzer the output is: Pet Information: Name: Dobby Age: 2 Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer The code to be added is #TODO python class Pet: def __init__(self): self.name = '' self.age = 0 def print_info(self): print('Pet Information:') print(' Name:', self.name) print(' Age:', self.age) class Dog(Pet): def __init__(self): Pet.__init__(self) self.breed = '' my_pet = Pet()my_dog = Dog() pet_name = input()pet_age = int(input())dog_name =…arrow_forwardWrite a program in Java for the university consisting of the following categories: A mere Person classification contains the following variables:String name The person's name. 1int id id number. 2Write a constructor that receives the variables and a function (ID int , name String(add) whereYou receive the person's name and ID number and assign them. Write the Students class that inherits from the Person class containing the variablesnext:String Specialization The student's specialization. 1double gpa student average. 2Write a constructor that accepts the variables. (Two and a half degrees). Write the Employee class that inherits from the Person class containing the variablesnext:String jop The job name. 1int salary 2Write a constructor that accepts the variables. Create an interface for the program as shown in the following imagearrow_forwardcreat a c++ project that Consider the following definition of a class. class displayClass { public: void print(); ... private: int listLength; int *list; double salary; string name; } parta. Write the function prototype to overload the assignment operator for the class displayClass. part b. Write the definition of the function to overload the assignment operator for the class displayClass. partc. Write the function prototype to include the copy constructor for the class displayClass. partd. Write the definition of the copy constructor for the class displayClassarrow_forward
- Python Programming 3. Write an Employee class that keeps data attributes for the following pieces of information:(a). Employee name(b). Employee numberNext, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information:(c). Shift number (an integer,such as1 for morning shift, 2 for evening shift)(d). Hourly payrateWrite the appropriate accessor and mutator methods for each class.arrow_forwardPlease with interface Write a program in Java for the university consisting of the following categories: A mere Person classification contains the following variables:String name The person's name. 1int id id number. 2Write a constructor that receives the variables and a function (ID int , name String(add) whereYou receive the person's name and ID number and assign them. Write the Students class that inherits from the Person class containing the variablesnext:String Specialization The student's specialization. 1double gpa student average. 2Write a constructor that accepts the variables. (Two and a half degrees). Write the Employee class that inherits from the Person class containing the variablesnext:String jop The job name. 1int salary 2Write a constructor that accepts the variables. Create an interface for the program as shown in the following imagearrow_forwardC++ Language Please Write a program that implements four classes: NPC, Flying, Walking, and Generic for a fantasy roleplaying game. Each class should have the following attributes and methods: NPC -a parent class that defines methods and an attribute common to all non-player characters (npc) in the game. a private string variable named name, for storing the name of the npc. a default constructor for setting name to "placeholder". an overloaded constructor that sets name to a string argument passed to it. setName - a mutator for updating the name attribute getName - an accessor for returning the npc name printStats - a pure virtual function that will be overridden by each NPC subclass. Flying - a subclass of NPC that defines a flying npc in the game a private int variable named flightSpeed for tracking the speed of the npc. a default constructor for setting flightSpeed to 0 and name to "Flying" using setName. setFlightSpeed - a mutator that accepts an integer as it's only argument…arrow_forward
- Write a java program in which Animal:Create a class Animal and Add a protected data member named id of integer type.• Add get/set methods for id data member in Animal class with public access. Also provide default constructor this should initialize id to 0.• Also provide parameterized constructor and toString method.• Add an abstract method tellAboutSelf method to Animal class with public access• Add another abstract method speak method to Animal class.Reptile, Bird, MammalNext create the three child classes which extends form Animal class.• Add a default constructor to each of the above created class. The constructor should initialize the id data member id, Reptile, Bird and Mammal, to 1, 2 and 3 respectively also it display a message “(class Name)’s default constructor”. E.g. for Bird it says “Bird’s default constructor”.• Add a parameterized constructor to each of the above created class. The constructor should initialize the id data member, Reptile, Bird and Mammal, to the…arrow_forwardFollowing the instructions presented in the Lecture 4.5 and 4.6, complete the class Bag we discussed in the lectures. It should include all the data members, constructors, as well as all the member functions we have discussed. To be more specific, the class should have an interface shown as following: class Bag { private: int items[100]; int itemCount; public: Bag(); int getItemCount(); bool add(int newItem); void display(); bool contains(); bool remove(int a); int getSum(); }; Please complete all the member functions listed above including the default constructor. Then add following member function to the class: getMax() This function returns the largest integer stored in the Bag without changing the position of each integer stored in the Bag. Write a C++ program in a .cpp file (source file) that include above class Bag and perform following tasks: Use function rand() to randomly generate 80 integers between 0 and 99 and put them into an object of the class Bag. Use…arrow_forwardWrite a program in the C++ language to create a class Rectangle with two member integer variables length and breadth. Write the parameterized constructor for the class and also add a member function that displays the area of the rectangle in the output.arrow_forward
- Write a Program in java to define a Student class, with member variables String name; int cms String DegreeProg Make a default constructor, Make a parameterized constructor. Overload the above Constructor. Provide getters and setters for data members. Inside main, create 2 students objects. Take data from user and set the values for the 2 students. At the end Print daTa.arrow_forwardWrite a java program that declares two classes. The parent class is called Simple that has two data members num1 and num2 to store two numbers. It also has four member functions. • The add() function adds two numbers and displays the result. • The sub() function subtracts two numbers and displays the result. • The mul() function multiplies two numbers and displays the result. • The div() function divides two numbers and displays the result. The child class is called VerifiedSimple that overrides all four functions. Each function in the child class checks the value of data members. It calls the corresponding member function in the parent class if the values are greater than 0. Otherwise it displays error messagearrow_forwardThis assignment requires one project with two classes. Class Employee Class Employee- I will attach the code for this: //Import the required packages. import java.text.DecimalFormat; import java.text.NumberFormat; //Define the employee class. class Employee { //Define the data members. private String id, lastName, firstName; private int salary; //Create the constructor. public Employee(String id, String lastName, String firstName, int salary) { this.id = id; this.lastName = lastName; this.firstName = firstName; this.salary = salary; } //Define the getter methods. public String getId() { return id; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public int getSalary() { return salary; } //Define the method to return the employee details. @Override public String toString() { //Use number format and decimal format //to format the salary…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning