Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Note: Make sure that you put the header comments in this main.cpp and all other cpp files file. Note: Make sure that you put the

Note: Make sure that you put the header comments in this main.cpp and all other cpp files file. Note: Make sure that you put the header comments in this main.cpp and all other cpp files file.The following data will be used for this project
Write a program that will include the following:
A class that will store mountain details which will included the following:
List item
Member for the name, (make it private)
Member for the country, (make it private)
Member for the elevation, (make it private)
Setters and getters for all the data members. (Make them public)
A member function call toMeters that will take the elevation and convert the value from feet to meters and return the converted
value. The relationship for feet to meters is 1 meter per 3.2808 feet
In the main function of the main source file, create 7 instances of Mountain objects and put the mountain data from the table
above.
Put the mountain objects in an appropriate data structure for the language that you are writing this for.
Write a method called minElevation that will return the minimum elevation.
Iterate over the data structure that contains the Mountain objects and print out the Mountain details similar to the table above,
with the addition of the elevation in feet and in meters.
Programmatically print out the elevation and name of the shortest mountain (do not hard code this).
The output for this program should be the following#include
#include
#include
#include
class Mountain {
private:
std::string name;
std::string country;
int elevation; // Elevation in feet
public:
// Constructor
Mountain(const std::string& name, const std::string& country, int elevation)
: name(name), country(country), elevation(elevation){}
// Setters
void setName(const std::string& name){
this->name = name;
}
void setCountry(const std::string& country){
this->country = country;
}
void setElevation(int elevation){
this->elevation = elevation;
}
// Getters
std::string getName() const {
return name;
}
std::string getCountry() const {
return country;
}
int getElevation() const {
return elevation;
}
// Function to convert elevation to meters
double toMeters() const {
return elevation /3.2808;
}
};
// Function to find the mountain with the minimum elevation
Mountain minElevation(const std::vector& mountains){
Mountain min_mountain = mountains[0];
for (const auto& mountain : mountains){
if (mountain.getElevation() min_mountain.getElevation()){
min_mountain = mountain;
}
}
return min_mountain;
}
int main(){
// Create instances of Mountain objects
std::vector mountains ={
Mountain("Chimborazo", "Ecuador", 20549),
Mountain("Matterhorn", "Switzerland", 14692),
Mountain("Olympus", "Greece (Macedonia)",9573),
Mountain("Everest", "Nepal", 29029),
Mountain("Mount Marcy - Adirondacks", "United States", 5344),
Mountain("Mount Mitchell - Blue Ridge", "United States", 6684),
Mountain("Zugspitze", "Switzerland", 9719)
};
// Print the header with column names
std::cout std::left std::setw(30) "Mountain Name"
std::setw(25) "Country"
std::setw(20) "Elevation (ft)"
std::setw(20) "Elevation (m)"
"
";
// Print mountain details
for (const auto& mountain : mountains){
std::cout std::left std::setw(30) mountain.getName()
std::setw(25) mountain.getCountry()
std::setw(20) mountain.getElevation()" ft"
std::setw(20) static_cast(mountain.toMeters())" m"
"
";
}
// Find and print the shortest mountain
Mountain shortest_mountain = minElevation(mountains);
std::cout "
The mountain with the smallest elevation is: "
shortest_mountain.getName()"," shortest_mountain.getCountry()
", with an elevation (ft) of: " shortest_mountain.getElevation()" ft
";
return 0; // Indicate that the program ended successfully
}can u please fix my code so it can make up to this
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What is adverse impact? How can it be proved?

Answered: 1 week ago