Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   C++ Assign (http://www.go4expert.com/forums/cpp-assign-t10545/)

siddhu 12May2008 11:06

C++ Assign
 
I am new to this forum and to C++. i really dont know how to start with this assignment. Can some one please help me by giving me full code of this program description.

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”.

[2 marks]

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.
[2.5 + 2.5 + 2.5 + 2.5 = 10 marks]
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 . . .

bughunter2 13May2008 12:20

Re: C++ Assign
 
Quote:

Originally Posted by siddhu
I am new to this forum and to C++. i really dont know how to start with this assignment. Can some one please help me by giving me full code of this program description.

<assignment description here>

Actually, what makes you think somebody here will make your assignments?

A better way would be to give it a try yourself first and tell us the problems you stumble upon.
I'm sure that you can at least make a start ;)


All times are GMT +5.5. The time now is 02:05.