c ++
Create a class Book with the data members listed below.
title, which is a string (initialize to empty
string)
sales, which is a floating point value (as a
double, initialize to 0.0)
Include the following member functions:
Include a default constructor,
a constructor with parameters for each data
member (in the order given above),
getters and setter methods for each data member
named in camel-case. For example, if a class had a data member
named myData, the class would require methods named in camel case:
getMyData and setMyData.
int sold(double unit) This function should
calculate and return the total number of units sold, based on sales
divided by unit, the input parameter argument for cost per
unit.
You only need to write the class definition and any code that is required for that class (i.e., header and implementation).
NOTE: you must not use the implicit "private" for class data types and methods. Include public or private explicitly.
#include <iostream>
using namespace std;
class Book
{
private:
string title;
double sales;
public:
Book() // default constructor
{
title = "";
sales = 0.0;
}
Book(string title,double sales) // argument
constructor
{
this->title = title;
this->sales = sales;
}
// set and get methods
void setTitle(string title)
{
this->title = title;
}
string getTitle()
{
return title;
}
void setSales(double sales)
{
this->sales = sales;
}
int sold(double unit)
{
return (int)sales/unit;
}
};
int main() {
Book b("Hemlet",220.99);
cout<<"Number of units sold of the book with
title : "<<b.getTitle()<<" =
"<<b.sold(5.66);
return 0;
}
output:
Number of units sold of the book with title : Hemlet = 38
Do ask if any doubt. Please upvote.
c ++ Create a class Book with the data members listed below. title, which is...
Create the class Book which has the following members: 1. private members: 1. title as String 2. isbn as String 3. author as String 4. price as double 2. public members: 1. default constructor which initializes all data members to their default values. 2. non-default constructor which initializes all data members to parameters values. 3. toString which returns a representing String of the Book. 4. add all the setters and getters. Create the class EBook which is a subclass of...
C++ program Create a Student class that contains three private data members of stududentID (int), lastName (string), firstName(string) and a static data member studentCount(int). Create a constructor that will take three parameters of studentID, lastName and firstName, and assign them to the private data member. Then, increase the studentCount in the constructor. Create a static function getStudentCount() that returns the value of studentCount. studentCount is used to track the number of student object has been instantiated. Initialize it to 0...
in c++ Define and implement the class Employee with the following requirements: private data members string type name a. b. double type hourlyRate 2. public member functions a. default constructor that sets the data member name to blank"and hourlyRate to zero b. A constructor with parameters to initialize the private data members c. Set and get methods for all private data members d. A constant method weeklyPay() that receives a parameter representing the number of hours the employee worked per...
The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...
Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....
Write an entire class called Movie that stores an instance variable named title for the title of the movie as a string. Write the corresponding getter and setter methods (getTitle, setTitle), and a constructor that takes one parameter (string for the title). Include both the class definition and method definitions! Be sure to use appropriate visibility modifiers. Assume all includes and using namespace std are already in the file. Do not try to make header files.
Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’ a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth() {return month;} ‘setters’ a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...
Create an Item class, which is the abstract super class of all Items. Item class includes an attribute, description of type String for every item. [for eg. Book] A constructor to initialize its data member of Item class. Override toString() method to return details about the Item class. Create the ExtraCharge interface with the following details. Declare a constant RATE with value 0.25 Declare a method called calculateExtraCharge(), which returns a double value. Create the...
Write a class called Book that has two private member variables called page (integer) and topic (string). It also has a static private member variable called count (integer). This class has only one constructor with default argument for page and topic. Write this constructor. Also overload the addition operator for this class such that it will add an integer value to the page variable of the book. For example when in main we say: book2 = book1 + 4; then...