Make a one program in c++ with output with visual studio. 1. Make a class called
ID: 3824940 • Letter: M
Question
Make a one program in c++ with output with visual studio.
1. Make a class called Product and code for methods. It must include the three types of constructors , services ("get" and "set"), and the following operator overloading =, ==, <<, >>.
2. Private attributes are string called productName, productBarCode, integer quantity, and type double price. The == operator will only compare against the productBarCode attribute. The +, -, ++ operators are going to modify only the quantity attribute.
Remember to validate.
3. Make a class called Machine that will be a composition of the Product class. It must include the three types of constructors, services ("get" and "set"), and the following operator overloading =, ==, <<, >>. Private attributes are products [25] of type Product and totalProducts of type integer.
Explanation / Answer
Here is the Product class for you:
#include <iostream>
using namespace std;
class Product
{
// Private attributes are string called productName, productBarCode, integer quantity, and type double price.
string productName;
string barCode;
int quantity;
double price;
public:
Product(string pN, string bC, int q, double p)
{
productName = pN;
barCode = bC;
quantity = q;
price = p;
}
void setProductName(string pN) { productName = pN; }
void setBarCode(string bC) { barCode = bC; }
void setQuantity(int q) { quantity = q; }
void setPrice(double p) { price = p; }
string getProductName() { return productName; }
string getBarCode() { return barCode; }
int getQuantity() { return quantity; }
double getPrice() { return price; }
bool operator==(Product &other) { return barCode.compare(other.barCode) == 0; }
void operator+(int q) { quantity += q; }
void operator-(int q) { quantity -= q; }
void operator++() { quantity += 1; }
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.