Design a C++ sale program by yourself, you can create any function you want it t
ID: 3859766 • Letter: D
Question
Design a C++ sale program by yourself, you can create any function you want it to have, for example, you can calculate user's product's total price or you can ask user to choose item's name and tell them the price. And please give me a brief summary about what is your sale program will do. The following are some specifications you have to meet:
1.demonstrate effective object oriented programming design and implementation ( classes, objects, functions, etc)
2.demonstrate effective use of at least TWO of the data structures ( queues, lists, vectors, etc)
3.demonstrate effective use of either inheritance or polymorphism
At last, please attach a screenshot of the output here to make sure that your code is runable.
Explanation / Answer
This sale program has one Sale class and a Bike class which inherits Sale class to make you explain you about the Inheritance and OOPs concepts. There are two data structures in code. Vector and queue.
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
class Sale // make a sale class here
{
private:
int value;// member value
public:
Sale(int value_)// constructor
{
value = value_;
}
void setValue(int value_)// set sale value
{
value = value_;
}
int getValue()// ge value
{
return value;
}
};
class Bike : Sale // Inherit Sale class
{
char* model; // Extra field model and inherit value of sale class
void setModel(char* model_)// set sale value
{
model = model_;
}
char* getModel()// ge value
{
return model;
}
};
int main(int nInputs, char* inputs[])
{
Sale sale1(1);// object of Sale class with arguement to constructor equal to 1
Sale sale2(2);// object of Sale class with arguement to constructor equal to 2
vector <Sale> v;// define vector here
v.push_back(sale1);// push sale1 to vector
v.push_back(sale2);// push sale2 to vector
cout << "Will Print vector elements ";
for (int i = 0; i != v.size(); ++i)// iterate vector
cout << v[i].getValue() << ' ';// print one by one vector elements
cout << " ";
queue <Sale> q;// define queue here
q.push(sale1);// push sale1 to queue
q.push(sale2);// push sale2 to queue
cout << "Top element in queue is: " << q.front().getValue() << " ";// print sale1
q.pop(); // pop sale1
cout << "Top element in queue is: " << q.front().getValue() << " ";// print sale2
}