Provide a source code file for the main function

Assignment Help Other Engineering
Reference no: EM132322852

Skills' Assessment -

Below, you find a comprehensive programming problem comprising multiple classes. For each class, you have to provide a header file and a source code file. You also need to provide a source code file for the main function. More details about file naming is provided below. You have to implement solutions to all the questions to pass the skills assessment.

We expect you to submit a zip file comprising the following results:

A report (at least ten pages) structured as follows:

A short description of your solution including one or more screen shots showing the output(s) of your program.

A short review of your code. Tell us what you think about your work.

Listings of your C++ code for the classes and the main function. Please put them into an appendix. This will keep your report more readable. We suggest that you structure your code listings according to the files which you have to program. These are:

  • plant.h, plant.cpp
  • position.h, position.cpp
  • dinosaur.h (this is also a good place for the enumeration Location), dinosaur.cpp
  • brachiosaurus.h, brachiosaurus.cpp
  • quetzalcoatlus.h, quetzalcoatlus.cpp
  • plesiosauria.h, plesiosauria.cpp
  • main.cpp

Electronic files associated with the classes and the main function. These are to be named according to the classes as follows:

  • plant.h, plant.cpp
  • position.h, position.cpp
  • dinosaur.h, dinosaur.cpp
  • brachiosaurus.h, brachiosaurus.cpp
  • quetzalcoatlus.h, quetzalcoatlus.cpp
  • plesiosauria.h, plesiosauria.cpp
  • main.cpp

A Windows executeable carrying the extension "exe.", called Dinosaurs.exe. To get it, you could, for example, set up a Visual Studio project named Dinosaurs. We will look primarily at Dinosaurs.exe to check your result. If the executable does not run, you will have failed straight away.

It is not allowed to add additional libraries beyond the C++ standard library.

For this process to work, your program has to be able to read the file input.txt provided by us. Then it has to automatically produce the output file output.txt. For fc to not find any differences, your output file has to have the correct format.

To make sure that you can test things beforehand, we will provide the two files input.txt and output.txt. Using fc to compare the output generated by your program to our ouput.txt, you can determine if your program works as expected. Of course, we will use a different input.txt than initially provided to you for the final check.

If the output generated by your program is not identical to what was expected, i.e., if fc finds any differences, then you will not have passed the skills' assessment and you cannot participate in the final exam.

1. This skills' assessment is about modelling the world of dinosaurs and the dinosaurs themselves.

(a) For a start, set up an enumeration Location comprising the six continents kAsia, kEurope, kNorthAmerica, kSouthAmerica, kAfrica, kAntarctica as potential dinosaur habitats. The enumeration is to begin with a value of 0 for kAsia counting upwards to 5 for kAntarctica.

(b) As a next step, dene the class Plant. It is to comprise two private member variables representing height and weight of the plant, a constructor declared as Plant(double height, double weight), the two accessor functions double getHeight(), double getWeight(), as well as the function void grow(double factor). If a value greater than 1 is passed, the height of the plant is to be multiplied by this value. Otherwise, the height of the plant remains the same.

(c) To keep track of a dinosaur position, the class Position has been provided. This class comprises three variables of type double. The first two are related to movements inside the x-y-Plane. There we use the variable position_x_ to store the x-position. The variable position_y_ is to keep track of the y-position. The position in z is stored using position_z_. The z-position is positive (z>=0) if the dinosaur can y, it is negative or zero (z<=0) if the dinosaur lives in water, or it is zero (z=0) if the dinosaur lives on (at) land. Please implement the following member functions (methods):

  • double getPositionx() : returns x position
  • double getPositiony() : returns y position
  • double getPositionz() : returns z position
  • void setPositionx() : sets x position
  • void setPositiony() : sets y position
  • void setPositionz() : sets z position
  • Position() : default constructor initialising all member variables to zero
  • Position(double x, double y, double double z) : parameterized constructor for setting the dinosaur position when generating an object instance.

(d) After the introduction of Location, Plant, and Position, we turn to the base class Dinosaur. It provides the following constructor: Dinosaur(double lngth, double hght, double wght, double age, Location lctn, string nm = "")

The following checks are to performed to validate the inputs before assigning them to the class member variables.

  • If the length (= length_) (in meters) is less than or equal to 0.0, then set it to 1.0, else keep as is.
  • If the height (= height_) (in meters) is less than or equal to 0.0, then set it to 2.0, else keep as is.
  • If the weight (= weight_) (in tons) is less than or equal to 0.0, then set it to 14.0, else keep as is.
  • If the age (= age_) (in years) is less than or equal to 0.0, then set it to 10.0 * 108, else keep as is.
  • If the name of the species (= name_) is passed as an empty string, set it to "unknown", else keep as is.
  • If the value passed for location_ is greater than kAntarctica (5) or less than kAsia (0), set location_ to kAsia, else keep as is.

Next, the following get functions are to be implemented:

  • Location getLocation() : returns the current location (continent where the dinosaur lives)
  • double getLength() : returns the length of the dinosaur
  • double getHeight() : returns the height of the dinosaur
  • double getWeight() : returns the weight of the dinosaur
  • double getAge() : returns the age of the dinosaur
  • string getName() : returns the name of the dinosaur species

In addition, the following set functions are to be provided to change the values of the member variables. Additional input validation inside these member functions is to be performed. If the input arguments do not satisfy the conditions below, the existing values are to be kept.

  • void setLocation(Location location): change location_ to location, if kAsia (=0) <= location <= kAntarctica (=5).
  • void setLength(double length): change length_ to length, if length > 0.0.
  • void setHeight(double height): change height_ to heightt, if height > 0.0.
  • void setWeight(double weight): change weight_ to weight, if weight > 0.0.
  • void setAge(double age) : change age_ to age, if age > 0.0.
  • void setName(string name): change the dinosaur species, name_, if name is a non-empty string.

The following member functions are also to be added as part of the base class:

  • void grow(double factor): multiplies dinosaur's height_ and length_ with factor, if 1.0 < factor < 2.0. Otherwise, the existing values are kept.
  • friend bool operator<(const Dinosaur &left, const Dinosaur &right): this function overloads the < operator. If the height_ of the dinosaur to the left of < is less than the height_ of the dinosaur to the right, this function returns true, otherwise false.
  • void move( double delta_x, double delta_y, double delta_z): this function receives the distances moved in the three directions. As part of the base class, this function only needs to be declared. There is no need to dene (implement) it yet, i.e., you can keep the body of the function empty. It is to be overridden in the derived classes later.
  • Position moved(): this function returns the position the dinosaur has arrived at after move(). As part of the base class this member function always returns the zero position characterized by (0, 0, 0).

Declare the member variables needed as private and all member functions as public.

(e) The class Brachiosaurus inherits from the base class Dinosaur (public inheritance). The constructor is defined as follows: Brachiosaurus(double l, double h, double w, double a, Location lctn, string n = "Brachiosaurus")

When calling the associated base-class constructor, you need to pass the appropriate input arguments from the derived-class constructor to the base-class constructor of class Dinosaur. Additional input validation steps are required as part of the derived-class constructor to make sure that the member variables are set consistently:

  • If the dinosaur's length was specied to be greater than 27.0, set this value to 27.0.
  • If the dinosaur's height was specied to be greater than 13.0, set this value to 13.0.
  • If the dinosaur's weight was specied to be greater than 44.0, set this value to 44.0.
  • If the dinosaur's age was specied to be less than 152.1 * 106, set this value to 152.1 * 106.

Input arguments passed to the constructor, meeting the conditions above, are accepted as is.

The related set functions of this derived class have to be adjusted as follows:

  • void setLength(double length): if an input argument greater than 27.0 was passed, use the value 27.0. Afterwards pass this value to the setLength function of the base-class Dinosaur.
  • void setHeight(double height): if an input argument greater than 13.0 was passed, use the value 13.0. Afterwards pass this value to the setHeight function of the base-class Dinosaur.
  • void setWeight(double weight): if an input argument greater than 44.0 was passed, use the value 44.0. Afterwards pass this value to the setWeight function of the base-class Dinosaur.
  • void setAge(double age): if an input argument less than 152.1 * 106 was passed, use the value 152.1 * 106. Afterwards pass this value to the setAge function of the base-class Dinosaur.

Now we want to add some behavior typical for an object of type Brachiosaurus:

  • void eatSomePlant(): every time this function is called, an object of type Brachiosaurus simply gains 1.0 tons of weight. Pass the resulting weight of the dinosaur to the member function setWeight() to make sure that the animal's weight limit is kept. If the dinosaur has reached its maximum weight, it can eat as many plants as desired without gaining more weight.
  • int eatPlant(Plant eat): this is a more sophisticated function. First, you need to check if the height of the dinosaur is equal or larger than the height of the plant to be eaten. If this is the case, the plant gets eaten and the dinosaur's weight is increased by the plant's weight. Once more, pass the resulting weight of the dinosaur to the member function setWeight() to make sure that the animal's weight limit is kept.
  • void grow(double factor): this function multiplies the dinosaur's height and length with factor, but only if 1.0 < factor < 3.0. Otherwise, no multiplication is carried out. Use the member functions setLength() and setHeight() to ensure that the maximum values set above are kept.

Finally, four functions need to be implemented to help the dinosaur move from one position to the next by walking. We assume motion in the x-y-plane (z=0). To this end, please add two member variables of type vector<double> to the class Brachiosaurus. The first one is to be called distances_list_x_. This vector stores (successive) distances in x-direction. The second one is to be called distances_list_y_. This vector stores (successive) distances in y-direction. Now, you need to write the four following functions:

  • void walk(double delta_x, double delta_y): in this function, distances delta_x are to be included into the vector distances_list_x_ (push-back). Similarly, distances delta_y are to be included into the vector distances_list_y_ (push-back).
  • void move(double delta_x, double delta_y, double delta_z): this function now implements its base-class counterpart. It wraps around (and contains) walk(). It passes its input arguments delta_x and delta_y to walk(). Since an object of type Brachiosaurus is assumed to move in the x-y-plane, we can assume delta_z = 0.0.
  • Position walked(): this function is to calculate and return the current position by adding successive distances starting at the origin (0.0, 0.0, 0.0). The current x-position is found by adding up all x-distances stored in distances_list_x_. The current y-position is found by adding up all the y-distances stored in distances_list_y_.
  • Position moved(): this function wraps around (and contains) walked(). It simply passes on the result of type Position returned to it by walked().

(f) The class Quetzalcoatlus inherits from the base class Dinosaur (public inheritance). The constructor is defined as follows: Quetzalcoatlus(double l, double h, double w, double a, Location l, string name = "Quetzalcoatlus")

When calling the associated base-class constructor, you need to pass the appropriate input arguments from the derived-class constructor to the base-class constructor of class Dinosaur. Note that the class Quetzalcoatlus has two additional member variables: bool alive_, which tells us if the dinosaur is still alive. Its default value is true. Furthermore, there is Position p_ with the origin, i.e., (0.0, 0.0, 0.0) as its default value.

Additional input validation steps are required as part of the derived-class constructor to make sure that the member variables are set consistently:

  • If the dinosaur's length was specied to be greater than 11.0, set this value to 11.0.
  • If the dinosaur's height was specied to be greater than 8.5, set this value to 8.5.
  • If the dinosaur's weight was specied to be greater than 0.25, set this value to 0.25.
  • If the dinosaur's age was specied to be less than 72.0 * 106, set this value to 72.0 * 106.

Input arguments passed to the constructor, meeting the conditions above, are accepted as is.

The related set functions of this derived class have to be adjusted as follows:

  • void setLength(double length): if an input argument greater than 11.0 was passed, use the value 11.0. Afterwards pass this value to the setLength function of the base-class Dinosaur.
  • void setHeight(double height): if an input argument greater than 8.5 was passed, use the value 8.5. Afterwards pass this value to the setHeight function of the base class Dinosaur.
  • void setWeight(double weight): if an input argument greater than 0.25 was passed, use the value 0.25. Afterwards pass this value to the setWeight function of the base-class Dinosaur.
  • void setAge(double age): if an input argument less than 72.0 * 106 was passed, use the value 72.0 * 106. Afterwards pass this value to the setAge function of the base-class Dinosaur.

Now we want to add some behavior typical for an object of type Quetzalcoatlus. They are as follows:

  • void grow(double factor): this function multiplies the dinosaur's height and length with factor, but only if 1.0 < factor < 1.5. Otherwise, no multiplication is carried out. Use the member functions setLength() and setHeight() to ensure that the maximum values set above are kept.
  • bool isAlive(): this function returns true, if the dinosaur is alive, otherwise false.
  • void died(): this function sets the variable alive_ to false.

Finally, four functions need to be implemented to help the dinosaur move from one position to the next by flying. We assume that the dinosaur is airborne when ying, i.e., z >= 0.

  • void y(double delta_x, double delta_y, double delta_z): Starting from the initial position at the origin, as set in the constructor, each time this function is called, the current position is updated as follows: (1) calculate the new x-coordinate of p_ by adding delta_x to the current x-coordinate of p_, (2) calculate the new y-coordinate of p_ by adding delta_y to the current y-coordinate of p_, (3) calculate the new z-coordinate of p_ by adding delta_z to the current z-coordinate of p_. Care has to be taken if the dinosaur ies towards the ground (delta_z < 0). As this dinosaur cannot move below ground, you have to monitor the z-coordinate during position updates. Should there be a negative z-coordinate as the result of adding delta_z with delta_z < 0 to a current position's z-coordinate, then the position_z_ member variable of p_ has to be set to zero.
  • void move(double delta_x, double delta_y, double delta_z): this function wraps around (contains) y () and passes its input arguments delta_x, delta_y and delta_z on to y ().
  • Position flown(): this function simply returns the current postion stored in the member variable p_.
  • Position moved(): this function wraps around (and contains) own(). It simply passes on the result of type Position returned to it by flown().

(g) The class Plesiosauria inherits from the base class Dinosaur (public inheritance). The constructor is de fined as follows: Plesiosauria (double l, double h, double w, double a, Location l, string name = "Plesiosauria")

This class stores successive positions using the private member variable position_list_ of type vector<Position>. Make it a part of the class.

When calling the associated base-class constructor, you need to pass the appropriate input arguments from the derived-class constructor to the base-class constructor of class Dinosaur. Additional input validation steps are required as part of the derived-class constructor to make sure that the member variables are set consistently:

  • If the dinosaur's length was specied to be greater than 20.0, set this value to 20.0.
  • If the dinosaur's height was specied to be greater than 9.0, set this value to 9.0.
  • If the dinosaur's weight was specied to be greater than 150.0, set this value to 150.0.
  • If the dinosaur's age was specied to be less than 203.0 * 106, set this value to 203.0 * 106.

Input arguments passed to the constructor, meeting the conditions above, are accepted as is.

The related set functions of this derived class have to be adjusted as follows:

  • void setLength(double length): if an input argument greater than 20.0 was passed, use the value 20.0. Afterwards pass this value to the setLength function of the base-class Dinosaur.
  • void setHeight(double height): if an input argument greater than 9.0 was passed, use the value 9.0. Afterwards pass this value to the setHeight function of the base-class Dinosaur.
  • void setWeight(double weight): if an input argument greater than 150.0 was passed, use the value 150.0. Afterwards pass this value to the setWeight function of the base-class Dinosaur.
  • void setAge(double age): if an input argument less than 203.0 * 106 was passed, use the value 203.0 * 106. Afterwards pass this value to the setAge function of the base-class Dinosaur.

Now we want to add some behavior typical for an object of type Plesiosauria.

  • void grow(double factor): this function multiplies the dinosaur's height and length with factor, but only if 1.0 < factor < 4.0. Otherwise, no multiplication is carried out. Use the member functions setLength() and setHeight() to ensure that the maximum values set above are kept.
  • int eatDinosaur(Quetzalcoatlus& toeat): this function rst checks if the dinosaur passed as an input argument is still alive. If this is the case, the function checks if the Plesiosauria objects's height exceeds the height of the Quetzalcoatlus object which is to be eaten. If this the case, the Plesiosauria object eats the Quetzalcoatlus object. Then the Quetzalcoatlus object's function died needs to be called. The weight of the Plesiosauria object is to be increased by the weight of the Quetzalcoatlus object. Use the function setWeight() to ensure that the weight limits are kept. On the other hand, if the Quetzalcoatlus object to be eaten is already dead, then it gets eaten right away. Again the function setWeight() is to be used to ensure that the weight limits are kept.

Finally, four functions need to be implemented to help the dinosaur move from one position to the next by swimming. We assume that the dinosaur is under water when swimming, i.e., z <= 0. Note that this class stores successive positions using the member variable position_list_ of type vector<Position>. The basic idea is to start at the origin, calculate new positions, and add (push-back) each new position into the position_list_ such that the last entry in the list always refers to the current position. The following functions are to be implemented:

  • void swim(double delta_x, double delta_y, double delta_z): starting at the origin, this function calculates successive positions and includes them into the position_list_. The first entry in the position_list_ should be the origin, i.e., (0.0, 0.0, 0.0). Please include the origin into position_list_ as its rst entry, for example, when you call swim() for the first time. To calculate a new position, you rst have to get the last entry from the position_list_. It is of type Position. You may want to call this object storing the current position curr_position. To get an updated position, maybe called updated_position, you need to do three things: (1) take position_x_ of curr_position, add delta_x to it, and assign the result to position_x_ of updated_position, (2) take position_y_ of curr_position, add delta_y to it, and assign the result to position_y_ of updated_position, (3) take position_z_ of curr_position, add delta_z to it, and assign the result to position_z_ of updated_position. The object updated_position then needs to be put at the end of position_list_ (push- back). There is, however, a little catch. As the animal is supposed to move under water (z<=0), you need to monitor the z-coordiate of the intermediate Position results. If a result yields a z-coordinate > 0, this z-coordinate is to be set to 0.
  • void move(double delta_x, double delta_y, double delta_z): this function wraps around (contains) swim() and passes its input arguments delta_x, delta_y and delta_z on to swim().
  • Position swam(): this function simply returns the current postion stored as the last element in position_list_
  • Position moved(): this function wraps around (and contains) swam(). It simply passes on the result of type Position returned to it by swam().

(h) For each class, provide a header le and a source code le. The les names have to correspond to the class names spelled in lower-case. For example, use plant.h and plant.cpp for the class Plant. Also write your main function into another source code le (main.cpp). For submission, it is essential that your program takes its input from the le input.txt and writes its output to the le output.txt. To this end, please add the following source code after the includes and before the main function.

1 std :: ofstream cout("output.txt");

2 std :: istream cin("input.txt");

Make sure that you include all the necessary header les. Due to these changes, the variable cin turns into an istream object, and the variable cout represents an ostream object. If you do not want to read from a le or write to a le, e.g., when working on your program, you can simply comment out these lines. If you use the command using namespace std, this has to be commented out when reading from or writing to le using cin and cout, respectively. Otherwise the compiler cannot resolve whether these objects are le stream objects or standard stream objects (ambiguous symbols).

We will provide the two les. When testing, you can use input.txt for reading and out-put.txt for comparing the output of your program to what should be produced.

(i) Here is source code which you can use for your main function to test your classes.

(j) Finally, please find an UML class diagram below offering an overview. We will provide the UML diagram as a separate pdf file as well.

Attachment:- Assignment File.rar

Reference no: EM132322852

Questions Cloud

Addressed in the field of information technology : In your own opinion, what are some important ethical and societal issues that need to be addressed in the field of Information Technology?
Determine whether these keys contain duplicates or not : We have n keys in an arbitrary range. We would like to determine whether these keys contain duplicates or not. Thus if there are no duplicate keys
Briefly state and name countries identify as target victims : From this research revelation in our chapter 11, briefly state and name the countries and organizations identified as the targeted victims?
Describe the prevailing view that experts hold : Describe the prevailing view that experts hold about the likely future of the concept in question. Include the views of at least three (3) experts to support.
Provide a source code file for the main function : For each class, you have to provide a header file and a source code file. You also need to provide a source code file for the main function
Developing a raspberry pi controlled scada : The aim of this project involves designing and implementing a distributed real time data acquisition system, to be integrated through a SCADA system.
Explain the methods of raising company funds : Explain the methods of raising company funds, that is, using share capital or debt, and how to account for each - Demonstrate the ability to prepare consolidate
Investigate the crime or the scene of the incident : What would I have to do for each of the following to accomplish my mission?
Cyber forensic investigation process : What are the steps of a cyber forensic investigation process?

Reviews

len2322852

6/15/2019 2:11:06 AM

You have to complete this assignment on your own. Each of your C++ files submitted has to compile in Visual Studio as available on the school's lab computers in room 1.1.53. Your executable must run on these Windows computers as well. We will provide detailed upload hints and naming instructions for your zip file before the deadline. If you pass the skills' assessment depends on whether your executable produces the correct output for a given input. To check, we will use the Windows command line program fc (file compare). A sample call would be "fc youroutput.txt correct.txt". If the contents of the two les are identical, fc prints a result similar to "no differences encountered".

Write a Review

Other Engineering Questions & Answers

  Determining the condensed per kilogram of fuel

Methanol, CH3OH, is burned with 200% theoretical air in an engine and the products are brought to 100 kPa, 30oC. How much water is condensed per kilogram of fuel?

  Evaluating the locations of charging stations

Tesla Motors recently announced their new model 3, which is a less expensive version of their model S. The company received over a quarter of a million pre-orders. Since the launch, potential buyers have been evaluating the locations of charging s..

  Provide procedure for undertaking the core cutter method

Compute the volume of cutting, given that the width at formation level is 8 m and the side slopes 1 1/2 to 1 - Provide the detailed procedure for undertaking the Core Cutter Method.

  Construct the circuit with multisim

Complete the chart by adjusting the values of frequency and measuring Ic and Vc using the Agilent Multi-meter and then from these values calculating the value of Xc in the last column.

  Design and simulate an audio amplifier

In general, you will have one other classmate in your team. Each of you will design and simulate an audio amplifier with different specifications, each making your choice from the above parameters.

  How many multiplications and additions can be performed

How many multiplications and additions per second can be performed on a chip in 2005 and 2010? Discuss some possible uses for chips with this level.

  Design simulate and test an audio amplifier

Design, simulate, and test an Audio Amplifier which delivers one of the above power outputs to an 8? speaker load.

  Result using the solution of part

Derive a formula for p(g/cm3) as a function of P(N/m2). (See Example 2.6-1) Check your result using the solution of part (b).

  Determine the transfer function of the system

Determine the transfer function of the system and determine and plot the amplitude response of the system - Sketch the poles and zeros of the transfer function in the complex plane. Is the system BIBO stable?

  Determine the strength ratio r at the bottom surface

Consider a laminate [±45] of the following material:- Determine the strength ratio R at the bottom surface of the laminate, using the given strength criteria:

  Calculate the d-spacing for the wet smectite

Calculate the d-spacing for the wet smectite. What happened to the smectite crystal structure, when it was exposed to water?

  Small cellular structures

Small cellular structures (ribosomes, mitochondria, & others) that perform specific metabolic functions for the cell as a whole What is the function of the heart, how does it pump blood?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd