Thread: crate class and depot class

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    1

    crate class and depot class

    write c++ program to simulate tomato crates arriving to a depot.

    For this purpose, create class Crate with the following members:
    data members: city where it came from, arrival day (1≤arrival_day≤30), purchase price, status flag to describe the status of a crate (e.g. -1:not available, 1:available, and 0:sold).

    Default constructor is used to initialize arrival day and purchase price to zero and also status to -1.

    Set member function is used to assign city, arrival day and purchase price from input parameters and then it updates the status by 1.

    Other member functions should be defined when required.


    Create class Depot with:

    data members: A pointer to Crate objects with an array size 100. There are two static members that are publicly accessible. One of them is to hold total profit that can be calculated from where sell price is 10 percent of purchase price. Other static data member is to represent total number of entry (entry≤100).

    Constructor dynamically creates an array of Crate objects (array size is assumed to be 100 so that there can be at most 100 sales per each month.
    arrival(entry) is a member function to set arrival day, price and city information for maximum number of entry (entry<=100) that represent the number of crates.

    sell() is member function
    to find the oldest crate arrived to the depot ;
    to sell it by setting its status to 0;
    to update the total profit for sales with a sell price (sell price is calculated as 10% purchase price for that crate)
    display() member function is used to display the total amount of sell profit for that month.

    Program will display a menu to process arrivals/sales of crates as shown in the sample run.

    Sample Run:
    <1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit
    Enter your choice: 2
    No crates to sell
    <1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit
    Enter your choice: 1
    Number of entry: 2
    Enter arrival day: 10
    purchase price: 100
    city: New York
    Enter arrival day: 15
    purchase price: 200
    city: Detroit
    <1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit
    Enter your choice: 2
    Crate from Adana with arrival day 15 was sold with a price: 220
    <1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit
    Enter your choice: 3
    Total profit: 20
    <1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit
    Enter your choice: 4
    Bye


    I can try to do but program can not work .Can you help me#include <iostream>
    #include <cstdlib>
    using namespace std;


    class crate
    {

    string city;
    int arrival_day;
    double price;
    int flag; //status

    public:

    crate()
    {
    arrival_day=0;
    price=0;
    flag=-1;
    }


    void set(string a,int b,double c)
    {
    city=a;
    arrival_day=b;
    price=c;
    flag=1;
    }
    string geta(){ return city; }
    int getb() { return arrival_day; }
    double getc() {return price; }
    int getd() {return flag;}

    };


    class depot
    {
    crate *obj[100];
    public:
    static double total_profit;
    static int number_entry;

    depot()
    {
    *obj=new crate[100];
    }
    void arrival(int);
    void sell();
    void display();

    };
    int depot::number_entry=100;
    double depot ::total_profit=crate.price*0.1;


    void depot::arrival(int entry)
    {

    int a,b,i;
    string c;
    for(i=0;i<entry;i++)
    {
    do
    {
    cout<<"Enter arrival day:";
    cin>>a;
    }while(a<1 ||a>30);

    cout<<" purchase price:";
    cin>>b;
    cout<<" city:";
    cin>>c;

    obj[i]->set(c,a,b);
    }
    }

    void depot::sell()
    {

    int i,j;
    if(*obj.getd()!=1)
    {
    cout<<"No crate to sell";
    }
    else
    {
    for(i=0;i<number_entry;i++)
    {
    for(j=i+1;j<number_entry;j++)
    {
    if(obj[i]<obj[j])
    {
    obj[i].getb()=obj[j].getb();
    obj[i].geta()=obj[j].geta();
    obj[i].getc()=obj[j].getc();
    }
    obj[i].getd();
    total_profit=(obj[i].getc())*0.1;
    obj[i].getc()=obj[i].getc()+total_profit;
    }
    }
    }
    cout<<"Crate from "<<obj[0].geta()<<" with arrival day "<<obj[0].getb()<<" was sold with a price "<<obj[0].getc();

    }

    void depot::display()
    {
    cout<<"Total profit:"<<total_profit;
    }

    int main()
    {
    depot depot;
    int choice,number_entry;
    do{
    cout<<"<1>: Arrival, <2>: Selling, <3>: Displaying, <4>: Quit"<<endl;
    cout<<"Enter your choice:";
    cin>>choice;
    switch(choice)
    {
    case 1: cout<<"Number of entry:";
    cin>>number_entry;
    depot.arrival(number_entry);
    break;
    case 2: depot.sell();
    break;
    case 3: depot.display(); break;


    }

    }while(choice!=4);

    system("pause");
    return(0);
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    I didnt read your long copy/paste assignment description or any of your code.
    I can try to do but program can not work .Can you help me
    Without you telling us what the problem is, we cant do anything to help. "program can not work" means absolutely nothing.

    Also, for the code you post, use the "[code ]" tags so it keeps the whitespace and formatting.

    Again, we are here to help but cannot do anything if you dont tell us the problem.

Popular pages Recent additions subscribe to a feed