Skip to content
Snippets Groups Projects
Commit 21213ad9 authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 1 - Farm.cpp

parent e91858fa
No related branches found
No related tags found
No related merge requests found
#include<iostream>
#include <iostream>
using namespace std;
class Animal
{
private:
float Revenue;
float Weight;
float DailyPrice;
public:
void Request_data() //Declaration and definition of the member function Request_data
{
cout << "How is the daily price?"<< endl;
cin >> DailyPrice;
cout << "What is the weight of the animal? " << endl;
cin >> Weight;
}
public:
//Constructor
Animal()
{
Request_data();
};
Animal(float w, float p):Weight(w), DailyPrice(p) { }
//Function
void Calculate_revenue() //Declaration and definition of the member function Calculate_revenue
{
Revenue = Weight* DailyPrice;
cout << "Revenue: " << Revenue <<endl;
}
class Animal {
private:
float Revenue;
float Weight;
float DailyPrice;
public:
void Request_data() // Declaration and definition of the member function Request_data
{
cout << "How is the daily price?" << endl;
cin >> DailyPrice;
cout << "What is the weight of the animal? " << endl;
cin >> Weight;
}
public:
// Constructor
Animal() { Request_data(); };
Animal(float w, float p) : Weight(w), DailyPrice(p) {}
// Function
void Calculate_revenue() // Declaration and definition of the member function Calculate_revenue
{
Revenue = Weight * DailyPrice;
cout << "Revenue: " << Revenue << endl;
}
};
int main()
{
Animal pig(19,2.5);
cout << "Pig ";
pig.Calculate_revenue();
Animal cow;
cout << "Cow ";
cow. Calculate_revenue();
cout << endl << endl;
return 0;
}
int main() {
Animal pig(19, 2.5);
cout << "Pig ";
pig.Calculate_revenue();
Animal cow;
cout << "Cow ";
cow.Calculate_revenue();
cout << endl << endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment