1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

C++ Program ***1

Discussion in 'C++' started by siddhu, May 12, 2008.

Thread Status:
Not open for further replies.
  1. siddhu

    siddhu New Member

    Joined:
    May 12, 2008
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Can some please help me by giving full code of Visuall C++ of program description below..


    Introduction

    In this assignment you are required to develop a program that simulates fishing. You must model the following situation: There are 4 fish species in the river, which you may catch:

    Australian Bass (Macquaria novemaculeata) - commonly less than 4 Kg; excellent eating, when less than 2.5 Kg.
    Short Finned Eel (Anguilla australis)- commonly less than 3 Kg; a good eating fish.

    Eel Tailed Catfish (Tandanus tandanus) - Up to 6.8 Kg; excellent eating, when less than 4 Kg.
    Gippsland Perch (Macquaria colonorum)- commonly less then 10 Kg; excellent eating when up to 6 Kg.

    You should assume that:
    • The chances to catch a fish of each of these four species are equal.
    • Weights of fishes of the same species are distributed evenly and range from 0 to the Maximal Weight. The value of Maximal Weight for each of the species is given above.

    You start fishing with an empty basket. If you catch a fish with weight less than 500 g or greater than the recommended excellent eating maximum, you release it. Otherwise put it in the basket.
    Stop fishing immediately as soon as the total weight of all the fishes in the basket exceeds 15 Kg.

    To model the situation, you are supposed to use the rand() function from <cstdlib>.
    Fishes of different species must be implemented as objects of different classes, each extending an abstract class Fish.
    Whenever the branching logic is required to handle fish objects of different species, you must do it polymorphically.
    All weights appearing in the program are given in grams, e.g. instead of 3 Kg we will use 3000g. Therefore use int variables to represent them.
    Task 1. Abstract class Fish.
    The file “Fish.h” should contain the following class definition.

    class Fish
    {
    public:
    virtual bool acceptable()= 0;
    void setWeight(int);
    int getWeight();
    virtual string getName()= 0;
    virtual string getScientificName()= 0;
    virtual void printMe() = 0;
    private:
    int weight;
    };

    Include all necessary header files into “Fish.h”. Write the implementation file “Fish.cpp”.



    Task 2. Classes AustralianBass, ShortFinnedEel, EelTailedCatfish, GippslandPerch.
    The file “AustralianBass.h” should contain the following class definition.

    class AustralianBass: public Fish
    {
    public:
    AustralianBass();
    bool acceptable();
    string getName();
    string getScientificName();
    void printMe();
    const static int MAX_WEIGHT;
    };

    Include all necessary header files into “AustralianBass.h”. Write the implementation file “AustralianBass.cpp”.

    The default constructor AustralianBass() should create an instance of the class with weight taking its value randomly from 0 to MAX_WEIGHT.

    Meanings of the rest of the functions in the class should be clear from their names and their implementations are straightforward.

    Classes ShortFinnedEel, EelTailedCatfish, GippslandPerch should have header files and implementations similar to that of AustralianBass.

    Task 3. File “Fishing.cpp”.
    The file must contain the following three functions:
    • void fishing(vector<Fish*> &basket);
    • void printBasket(vector<Fish*> &basket);
    • int main();

    The first function imitates the fishing process. It randomly creates fishes of different species with random weights, and if a fish is acceptable (i.e. is heavier than 500 g and still eatable) adds the fish in the basket (implemented as a vector<Fish*> object). The process continues while the total weight of the fishes in the basket is less than 15000 g. (15 Kg).

    The second function simply prints content of its argument (i.e. basket) in a nice format.
    In the main function you create a vector basket, then call consecutively fishing(basket) and printBasket(basket).

    The output of the program may look as follows:

    Fishing started:
    Caught: Eel Tailed Catfish
    Weight: 5665 grams
    Was released.

    Caught: Gippsland Perch
    Weight: 6881 grams
    Was released.

    Caught: Eel Tailed Catfish
    Weight: 5908 grams
    Was released.

    Caught: Gippsland Perch
    Weight: 9365 grams
    Was released.

    Caught: Eel Tailed Catfish
    Weight: 3110 grams
    Has been put in the basket.

    Caught: Gippsland Perch
    Weight: 135 grams
    Was released.

    Caught: Australian Bass
    Weight: 1378 grams
    Has been put in the basket.

    Caught: Short Finned Eel
    Weight: 2691 grams
    Has been put in the basket.

    Caught: Gippsland Perch
    Weight: 6089 grams
    Was released.

    Caught: Short Finned Eel
    Weight: 1165 grams
    Has been put in the basket.

    Caught: Short Finned Eel
    Weight: 383 grams
    Was released.

    Caught: Short Finned Eel
    Weight: 837 grams
    Has been put in the basket.

    Caught: Australian Bass
    Weight: 1717 grams
    Has been put in the basket.

    Caught: Australian Bass
    Weight: 2651 grams
    Was released.

    Caught: Eel Tailed Catfish
    Weight: 864 grams
    Has been put in the basket.

    Caught: Short Finned Eel
    Weight: 341 grams
    Was released.

    Caught: Short Finned Eel
    Weight: 1393 grams
    Has been put in the basket.

    Caught: Short Finned Eel
    Weight: 2023 grams
    Has been put in the basket.


    Content of the basket:
    1) Eel Tailed Catfish (Tandanus tandanus), weight 3110 grams
    2) Australian Bass (Macquaria novemaculeata), weight 1378 grams
    3) Short Finned Eel (Anguilla australis), weight 2691 grams
    4) Short Finned Eel (Anguilla australis), weight 1165 grams
    5) Short Finned Eel (Anguilla australis), weight 837 grams
    6) Australian Bass (Macquaria novemaculeata), weight 1717 grams
    7) Eel Tailed Catfish (Tandanus tandanus), weight 864 grams
    8) Short Finned Eel (Anguilla australis), weight 1393 grams
    9) Short Finned Eel (Anguilla australis), weight 2023 grams
    The total weight is: 15178 grams.

    Press any key to continue . . .
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Duplicate of C++ Assign. Thread closed. Please do not post the same thread over and over again.
     
Thread Status:
Not open for further replies.

Share This Page