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

Update Solution Exercise 3 - Article.cpp

parent fcc5d9a3
No related branches found
No related tags found
No related merge requests found
#include<iostream>
#include <iostream>
using namespace std;
class Article {
private:
string Name;
float Price;
class Article
{
private:
string Name;
float Price;
public:
//getter
string get_Name()
{
return Name;
}
float get_Price()
{
return Price;
}
//setter
void set_Name()
{
cout << "Please enter the name of the article: ";
cin >> Name;
}
void set_Price()
{
cout << "Please enter the price of the article: ";
cin >> Price;
}
//Member functions
void Show_data() //Declaration and definition of the member function Show_data
{
cout << "The article " << get_Name() << " costs " << get_Price() << " Euro." << endl;
}
void Enter_data() //Declaration and definition of the member function Enter_data
{
set_Name();
set_Price();
}
void Calculate_TotalPrice(int quant)//Declaration and definition of the member function Calculate_TotalPrice
{
cout << "Total price: " << quant*get_Price() << endl;
}
public:
// getter
string get_Name() { return Name; }
float get_Price() { return Price; }
// setter
void set_Name() {
cout << "Please enter the name of the article: ";
cin >> Name;
}
void set_Price() {
cout << "Please enter the price of the article: ";
cin >> Price;
}
// Member functions
void Show_data() // Declaration and definition of the member function Show_data
{
cout << "The article " << get_Name() << " costs " << get_Price() << " Euro." << endl;
}
void Enter_data() // Declaration and definition of the member function Enter_data
{
set_Name();
set_Price();
}
void Calculate_TotalPrice(int quant) // Declaration and definition of the member function Calculate_TotalPrice
{
cout << "Total price: " << quant * get_Price() << endl;
}
};
int main()
{
Article art;
int quantity;
art.Enter_data();
art.Show_data();
cout << "Please enter a quantity: ";
cin >> quantity;
art.Calculate_TotalPrice(quantity);
cout << endl << endl;
return 0;
}
int main() {
Article art;
int quantity;
art.Enter_data();
art.Show_data();
cout << "Please enter a quantity: ";
cin >> quantity;
art.Calculate_TotalPrice(quantity);
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