Explanation of Solution
Program:
File name: sale.h
//include libraries
#ifndef SALE_H
#define SALE_H
#include <iostream>
using namespace std;
//using the namespace
namespace salesavitch
{
//create a class
class Sale
{
//define access specifier
public:
//declare the constructors
Sale();
Sale(double thePrice);
//define required methods
double bill() const;
double savings(const Sale& other) const;
//define access specifier
protected:
//declare required variables
double price;
};
//define an overloaded method
bool operator <(const Sale& first, const Sale&
second);
}
#endif // SALE_H
File name: discount.h
//include libraries
#ifndef DISCOUNTSALE_H
#define DISCOUNTSALE_H
#include "sale.h"
//using the namespace
namespace salesavitch
{
//create a class
class DiscountSale : public Sale
{
//define access specifier
public:
//declare the constructors
DiscountSale();
DiscountSale(double the_price, double the_discount);
//Discount is expressed as a percent of the price.
virtual double bill() const;
//define access specifier
protected:
//declare required variable
double discount;
};
}
#endif //DISCOUNTSALE_H
File name: sale.cpp
//include libraries
#include "sale.h"
//using the namespace
namespace salesavitch
{
//define a constructor
Sale::Sale() : price(0)
{}
//define a constructor
Sale::Sale(double the_price) : price(the_price)
{}
//declare a method
double Sale::bill() const
{
//return statement
return price;
}
//declare a method
double Sale::savings(const Sale& other) const
{
//return statement
return ( bill() - other...
Trending nowThis is a popular solution!
Chapter 15 Solutions
Problem Solving with C++ (9th Edition)
- First, you need to design, code in Java, test and document a base class, Student. The Student class willhave the following information, and all of these should be defined as Private:A. Title of the student (eg Mr, Miss, Ms, Mrs etc)B. A first name (given name)C. A last name (family name/surname)D. Student number (ID) – an integer number (of type long)E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class fromJAVA)The student class will have at least the following constructors and methods:(i) two constructors - one without any parameters (the default constructor), and one withparameters to give initial values to all the instance variables.(ii) only necessary set and get methods for a valid class design.(iii) method to write the output of all the instance variables in the class to the screen (which willbe overridden in the respective child classes, as you have more instance variables thatrequired to be output).(iv) an equals method which compares two…arrow_forwardFirst, you need to design, code in Java, test and document a base class, Student. The Student class willhave the following information, and all of these should be defined as Private:A. Title of the student (eg Mr, Miss, Ms, Mrs etc)B. A first name (given name)C. A last name (family name/surname)D. Student number (ID) – an integer number (of type long)E. A date of birth (in day/month/year format – three ints) - (Do NOT use the Date class fromJAVA)The student class will have at least the following constructors and methods:(i) two constructors - one without any parameters (the default constructor), and one withparameters to give initial values to all the instance variables.(ii) only necessary set and get methods for a valid class design.(iii) method to write the output of all the instance variables in the class to the screen (which willbe overridden in the respective child classes, as you have more instance variables thatrequired to be output).(iv) an equals method which compares two…arrow_forwardSuppose you compile the class YourClass. What will be the name of thefile containing the resulting bytecode?arrow_forward
- In C++Make sure to post unique assignment. Do not copy/paste what has already being posted before. I give thumbs up and thumbs down based on what you post. Write a definition of a class that has the following properties. The name of the class is secretType. (Private) - The class secretType has four member variable: name (a string), age and weight (int), height (double) (Public) - The class secretType has the following member functions: (Make the accessor functions const) print – outputs the data in the member variables in a nice format constructor – that sets the name, age, weight and height getName – value returning function returns the name getAge – value returning function returns the height getWeight – value returning function returns the weight weightStatus – value returning function that returns a string according to the following chart. The formula for BMI (body mass index) - Body Mass Index is a simple calculation using a person’s height and weight. The formula is BMI = kg/m2…arrow_forwardCreate a class Int based on Question-5 in Assignment-2. Overload four integer arithmetic operators (+, -, *, and /) so that they operate on objects of type Int.arrow_forward1)The program should be written in JAVA. Create a "Car" class that keeps car ids and prices. And create a "Galleries" class that holds the car list for a particular gallery. In this class there should be methods for get / set and print for car name, car number and car list. Adding / Removing Cars to the List in This Class should have methods. And create another method to find and print the IDs of Cars with Car Segment equal to X. (print_id(X)). Car Prices are as follows according to the segments. 0$-19999$ -> Z20000$-29999$ -> Y30000$-44999$ -> T45000$-100000$ -> P Apply the Car list using "Singly Linked List"(Node, newNode, head).arrow_forward
- Write a class named NameAndCount for recording a String data name and an int data named count. A constructor for the class takes two values, one for the name and the other for the count, and stores the two values in the instance variables. The class must be comparable, with the declaration of implements Comparable<NameAndCount>. The class has a “getter” for the name, named getName, and a “getter” for the count, named count. For “setters”, there is a method named increment that increases the value of count by 1. There is another instance method equals, which receives a String data as its parameter, and returns a boolean value indicating whether or not the contents of the String data is equal to the contents of name. Additionally, the class must implement the compareTo method, which returns the result of comparing the values of count. please write java code for above questionarrow_forwardWrite a class named NameAndCount for recording a String data name and an int data named count. A constructor for the class takes two values, one for the name and the other for the count, and stores the two values in the instance variables. The class must be comparable, with the declaration of implements Comparable<NameAndCount>. The class has a “getter” for the name, named getName, and a “getter” for the count, named count. For “setters”, there is a method named increment that increases the value of count by 1. There is another instance method equals, which receives a String data as its parameter, and returns a boolean value indicating whether or not the contents of the String data is equal to the contents of name. Additionally, the class must implement the compareTo method, which returns the result of comparing the values of count. please write java code for above question and please send me the screenshot of the output formatarrow_forwardThis is the question: In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game. This is the code given: public class Game { private Team team1; private Team team2; private String time; public Game(Team t1, Team t2, String time) { // your code here } public Team getTeam1() { // your code here } public Team getTeam2() { // your code here } public String getTime() { // your code here } }arrow_forward
- 1. How can we write a parameter less Lambda expression? a. Need to pass curly braces to denotes that there are no parameter on left side of the arrow.b. Pass empty set of parentheses on the left side of the arrow.c. In this particular case arrow is not required at all.d. No need to pass anything on the left side of the arrow. 2. Which of the following is NOT true about functional interface in Java? a. It has multiple methods that needs to be implemented.b. Lambda expression implicitly implement the single method inside functional interface.c. If a lambda expression is provided then the method name should not be provided.d. It has only a single method that needs to be implemented.arrow_forwardThis is for my python class, so python code please. This code needs to take inputs from a outside source/program, not for specific examples. Sorry for the confusion. 9.12 LAB: Product class In main.py define the Product class that will manage product inventory. Product class has three attributes: a product code, the product's price, and the number count of product in inventory. Implement the following methods: A constructor with 3 parameters that sets all 3 attributes to the value in the 3 parameters set_code(self, code) - set the product code (i.e. SKU234) to parameter code get_code(self) - return the product code set_price(self, price) - set the price to parameter price get_price(self) - return the price set_count(self, count) - set the number of items in inventory to parameter count get_count(self) - return the count add_inventory(self, amt) - increase inventory by parameter amt sell_inventory(self, amt) - decrease inventory by parameter amtarrow_forwardThis is the question - In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game. This is the code that I have so far but can't seem to get them to compare correctly - public class Game { private Team team1; private Team team2; private String time; public Game(Team t1, Team t2, String time) { // your code here this.team1=t1; this.team2 = t2; if(team1 == team2) this.time = time; else this.time = "Game cancelled!"; } public Team getTeam1() { // your code here return team1; } public Team getTeam2()…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