Question

In: Computer Science

I. Create the class Item with the following members: 1. id, a protected variable of type...

I. Create the class Item with the following members:
1. id, a protected variable of type int
2. name, a protected variable of type string
3. price, a protected variable of type double
4. a public non-default constructor which accepts three parameters to initialize the variables above
5. a copy constructor
6. overload the = operator such that both operands are of type Item
7. overload the = operator such that the right operand is of type double. Assign the value of double to the price member

Solutions

Expert Solution

Thanks for the question, here is the class Item in C++

===============================================================


class Item{
   protected:
       int id; string name; double price;
   public:
       Item(int id, string name, double price);
       Item(const Item& item);
       void operator=(const Item& item);
       void operator=(double price);
};
Item::Item(int id, string name, double price): id(id),name(name),price(price){}
Item::Item(const Item& item){
   id = item.id;    name = item.name;    price = item.price;
}
void Item::operator=(const Item& item){
   id = item.id;    name = item.name;    price = item.price;
}
void Item::operator=(double price){
   this->price = price;
}


===============================================================


Related Solutions

object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java 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 Zubaida
Design a Ship class that has the following members: • A member variable for the name...
Design a Ship class that has the following members: • A member variable for the name of the ship (a string) • A member variable for the year that the ship was built (a string) • A constructor and appropriate accessors and mutators • A virtual print function that displays the ship’s name and the year it was built. Design a CruiseShip class that is derived from the Ship class. The CruiseShip class should have the following members: • A...
create a public class and a main class to deletebyStudentID number with get ID and getStudentByName...
create a public class and a main class to deletebyStudentID number with get ID and getStudentByName in public class. when the user is prompted to search for the student and delete them by their. ID has seven digits and 6 students each. Ex. Delete student by their ID         Enter students name and their ID         Vanessa,         1111-111         Vanessa is now deleted
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate,...
****in java please*** Create a class CheckingAccount with a static variable of type double called interestRate, two instance variables of type String called firstName and LastName, an instance variable of type int called ID, and an instance variable of type double called balance. The class should have an appropriate constructor to set all instance variables and get and set methods for both the static and the instance variables. The set methods should verify that no invalid data is set. Also...
Create a "Date" class that contains: three private data members: month day year (I leave it...
Create a "Date" class that contains: three private data members: month day year (I leave it to you to decide the type) "setters" and "getters" for each of the data (6 functions in total) One advantage of a "setter" is that it can provide error checking. Add assert statements to the setter to enforce reasonable conditions. For example, day might be restricted to between 1 and 31 inclusive. one default constructor (no arguments) one constructor with three arguments: month, day,...
Create a class called employee which has the following instance variables: Employee ID number Salary Years...
Create a class called employee which has the following instance variables: Employee ID number Salary Years at the company Your class should have the following methods: New employee which reads in an employee’s ID number, salary and years of service Anniversary which will up the years of service by 1 You got a raise which will read in how much the raise was (a percent) and then calculate the new salary You get a bonus which gives a yearly bonus...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data...
Write in C++ language. (Employee Record): Create a class named 'Staff' having the following members: Data members - Id – Name - Phone number – Address - AgeIt also has a function named 'printSalary' which prints the salary of the staff.Two classes 'Employee' and 'Officer' inherits the 'Staff' class. The 'Employee' and 'Officer' classes have data members 'Top Skill' and 'department' respectively. Now, assign name, age, phone number, address and salary to an employee and a officer by making an...
Create a class named Student. Student has fields for an ID number, number of credit hours...
Create a class named Student. Student has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. Student also has a field for grade point average. Include a method to compute the grade point average field by dividing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT