friends please do me a help, please solve this:
All class must have encapsulation, constructor, destructor and in any one solution you must have to use operator overloading

1) Define a class name DVD_DB. Include the following members.
DATA MEMBERS:
Name of DVD – private character array, size 10
Price – private double variable
Quantity – private int variable
A private static int variable to keep track of how many DVD have been created so far.
MEMBER FUNCTIONS:
To assign initial values
To set price and quantity
To get price and quantity
To Print DVD
To display how many DVD has been created so far.

In main function use a DVD array and demonstrate a DVD shop. i.e. User can choose a DVD & buy it, when a DVD is sold the Quantity goes down.

ahh! i think its simple here what i have tried, but cant understand what to do:

#include<iostream>
 #include<string>
using namespace std;
class DVD_DB{
private:
    string dvdName;
    double dvdPrice;
    int dvdQuantity;
    static int TotalDVD;
public:
    DVD_DB(){}
    DVD_DB(){

    }
    void set_Name(string n){
        string dvdName=n;
    }
    void show_name(){
        cout << dvdName << "\n";
    }
    void set_price(int p){
        dvdPrice = p;
    }
    void show_price(){
        cout << dvdPrice << "\n";
    }
    int get_price(){
        return dvdPrice;
    }
    void set_pricedvdQuantity(int q){
        dvdQuantity = q;
    }
    void show_dvdQuantity(){
        cout << dvdQuantity << "\n";
    }
    int get_quantity(){
        return dvdQuantity;
    }
};

any one pls help

In your code there is an error:

 void set_Name(string n){
        string dvdName=n;
    }

Since you re-clare dvdName as a string. This is not correct. First re-design your class into a structure that is more Encapsulation:

Let's call this class "dvd.h"

class DVD_DB {
static int TotalDVD;
public:

    DVD_DB();
    void set_Name(string n);
    string showName();

    void set_price(int p);
    int show_price();

    void set_pricedDvdQuantity(int q);
    void get_quaintity();

protected:

    string dvdName;
    double dvdPrice;
    int dvdQuantity;

};

We do not need to have functions that are: void show_name(){ for example because placing cout commands inside the methods is very bad. You should use these in your main to output the desired result.

We can now make the actual implementation of this class, and, let's call this file: DVD.cpp:

DVD_DB::DVD_DB(){};

void DVD_DB::set_Name(string n)
{

}

string DVD_DB::showName() {
    return dvdName;
}

//....

//.....

And then in your main you can initialise an array of objects like so:

    DVD_DB *d = new DVD_DB[10];

    d[0].set_Name("foo");
    d[1].set_Name("boo");

    cout << d[0].showName();
    cout << endl;
    cout << d[1].showName();

I hope this gives you an idea. Get your main class structure working before you worry about operator overloading and other things.

I would suggest splitting the dvd portions into another class, then make an array of dvd's a property in the DVD_DB class. Now all your methods to manage the dvd's remain inside your class and simplify the store interface the instructor wants. If the instructions you've showed us are complete that should still fit.
Here's a simple way to do that:

#include<iostream>
#include<string>
#include <sstream>
using namespace std;
class DVD
{
private:
    string dvdName;
    double dvdPrice;
    int dvdQuantity;
public:
    //Here's 2 simple constructors
    DVD()
    {
        dvdName = "";
        dvdPrice = 0;
        dvdQuantity = 0;
    }
    DVD(string Name,double Price, int Quantity)
    {
        dvdName = Name;
        dvdPrice = Price;
        dvdQuantity = Quantity;
    }
    string getdvdName()
    {
        return dvdName;
    }
    void setdvdName(string value)
    {
        dvdName = value;
    }
    double getdvdPrice()
    {
        return dvdPrice;
    }
    void setdvdPrice(double value)
    {
        dvdPrice = value;
    }
    int getdvdQuantity()
    {
        return dvdQuantity;
    }
    void setdvdQuantity(int value)
    {
        dvdQuantity = value;
    }
    string printDVD()
    {
        stringstream ss;
        ss << "Name: " << dvdName << " - Price: " << dvdPrice <<" - Quantity: " << dvdQuantity;
        return ss.str();
    }
};
class DVD_DB
{
private:
    static int TotalDVD;
    DVD *AllDVDs;
public:
    DVD_DB()
    {
        TotalDVD = 10;
        AllDVDs = new DVD[10];
    }
    //In here the methods you use will depend on the store front you want.  Since there are only 10 items you could
    //display them all and have the user choose one.  You could also have the user type a name and search for the right
    //one.
    //You can also have methods for keeping track of the order, with the name quantity and total price of each item.

};

Edited 3 Years Ago by tinstaafl

This article has been dead for over six months. Start a new discussion instead.