Question

Hi I need some help on how to write this in a H file for c++...

Hi I need some help on how to write this in a H file for c++ please

You will need to create two structures. One is called Cost. Cost will have the following members:

  • The number of hours it takes to take care of a specific Dinosaur.
  • The cost (per hour) of taking care of this Dinosaur.
  • The cost of food to feed this Dinosaur for one week.
  • The cost of materials/supplies (grooming, medical) for this Dinosaur for one week

The second structure is called Dinosaurs. Dinosaurs will have the following members:

  • The name of the Dinosaur
  • The description of the Dinosaur
  • The average length of the Dinosaur (in feet)
  • The average height of the Dinosaur (in feet)
  • The location of the Dinosaur (example: its origin or where they are commonly found)
  • If the Dinosaur is dangerous (Boolean variable)
  • A variable to hold the Cost structure members
0 0
Add a comment Improve this question Transcribed image text
Answer #1

source code of the above question

/*
* File: dinosaur.h
* Author: student
*
* Created on 22 November, 2019, 2:24 PM
*/

#ifndef DINOSAUR_H
#define DINOSAUR_H
using namespace std;
//member declaration of Cost structure
struct Cost
{
int no_of_hours;
int cost_per_hour;
float cost_of_food;
float cost_of_materials;
};
//member declaration of Dinosaur structure
struct Dinosaurs
{
string name;
string description;
float length_dino;
float height_dino;
string origin_loc_dino;
bool nature;
struct Cost C;
};

#endif /* DINOSAUR_H */

implemented this header file in c++ program is given below

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/*
* File: testprogram.cpp
* Author: student
*
* Created on 22 November, 2019, 2:41 PM
*/

#include <iostream>
#include "dinosaur.h"
using namespace std;

int main()
{
Dinosaurs D;
D.name="black dinosaur";
D.description="black,wild dinosaur found in amazon jungle";
D.length_dino=12;
D.height_dino=15.5;
D.origin_loc_dino="AMAZON";
D.nature=1;
D.C.no_of_hours=2;
D.C.cost_per_hour=500;
D.C.cost_of_food=1000;
D.C.cost_of_materials=1000;
float total_cost=D.C.no_of_hours*(D.C.cost_per_hour+D.C.cost_of_food+D.C.cost_of_materials);
cout<<"the information about a dinosaur and total cost per week spent to a dinosaur given below"<<endl;
cout<<D.name<<endl;
cout<<D.description<<endl;
cout<<D.length_dino<<"feet"<<endl;
cout<<D.height_dino<<"feet"<<endl;
cout<<"origin of dinosaur in "<<D.origin_loc_dino<<endl;
if(D.nature==1)
cout<<"dangerous dinosaur"<<endl;
else
cout<<"non dangerous dinosaur"<<endl;
cout<<"total cost spent per dinosaur in a week="<<total_cost;
return 0;
}

screen of the above program given below

result after executing the above program

Add a comment
Know the answer?
Add Answer to:
Hi I need some help on how to write this in a H file for c++...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT