Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- #include <fstream>
- #define DG 0.0
- #define GG 1.0
- using namespace std;
- // 1. zadatak
- template <typename Type>
- double Percentage(Type arr[], int n, int a, int b) {
- int count = 0;
- for (int i = 0; i < n; i++) {
- if (arr[i] > a && arr[i] < b) {
- count++;
- }
- }
- return (double)count / (double)n * 100;
- }
- // 2. zadatak
- class Money {
- friend bool operator<(const Money&, const int);
- friend bool operator>(const Money&, const int);
- private:
- int mAmount;
- public:
- Money() : mAmount(0) {}
- Money(int amount) : mAmount(amount) {}
- };
- bool operator<(const Money& lhs, const int rhs) {
- return lhs.mAmount < rhs;
- }
- bool operator>(const Money& lhs, const int rhs) {
- return lhs.mAmount > rhs;
- }
- int main() {
- Money* monies = new Money[3];
- monies[0] = Money(5);
- monies[1] = Money(7);
- monies[2] = Money(3);
- cout << Percentage(monies, 3, 4, 10) << "%" << endl;
- return 0;
- }
- // 3. zadatak
- class Enemy {
- friend class IllegalEnemyException;
- protected:
- std::string mName;
- int mHealth;
- int mAttackDamage;
- public:
- Enemy();
- Enemy(std::string, int);
- int getAttackDamage() const { return mAttackDamage; }
- int getHealth() const { return mHealth; }
- virtual void heal(int amount);
- virtual void takeDamage(int amount) = 0;
- };
- Enemy::Enemy() : mName(""), mHealth(0), mAttackDamage(0) {}
- Enemy::Enemy(std::string name, int attackdamage) : mName(name), mHealth(100), mAttackDamage(attackdamage) {}
- void Enemy::heal(int amount) {
- if (mHealth == 0) { return; }
- mHealth += amount;
- }
- // 4. zadatak
- class ArmoredEnemy : protected Enemy{
- private:
- double mHitRatio;
- int mArmor;
- public:
- ArmoredEnemy();
- ArmoredEnemy(double, int, std::string, int);
- virtual void takeDamage(int amount);
- };
- ArmoredEnemy::ArmoredEnemy() : mHitRatio(0), mArmor(0), Enemy() {}
- ArmoredEnemy::ArmoredEnemy(double hitratio, int armor, std::string name, int attackdamaage) : mHitRatio(hitratio), mArmor(armor), Enemy(name, attackdamaage) {}
- // 5. zadatak
- void ArmoredEnemy::takeDamage(int amount) {
- double damage = DG + (float)rand() * (GG - DG) / (float)RAND_MAX;
- if (damage < mHitRatio) {
- return;
- }
- for (int i = 0; i < amount; i++) {
- if (mArmor != 0) {
- mArmor -= 1;
- }
- else if (mHealth != 0) {
- mHealth -= 1;
- }
- else {
- return;
- }
- }
- }
- // 6. zadatak
- class IllegalEnemyException : public std::runtime_error {
- public:
- IllegalEnemyException(std::string);
- };
- IllegalEnemyException::IllegalEnemyException(std::string message) : std::runtime_error(message) {}
- // 7. zadatak
- // ...
- // 8. zadatak
- // ...
- // 9. zadatak - C#
- interface ITaxable
- {
- int GetTaxPercentage();
- double CalculateAmount();
- double CalculateTaxAmount();
- }
- // 10. zadatak - C#
- class Flour : ITaxable
- {
- public int TaxPercentage { get; private set; }
- public int QuantityKg { get; private set; }
- public int PricePerKg { get; private set; }
- public Flour(int taxPercentage, int quantityKg, int pricePerKg)
- {
- TaxPercentage = taxPercentage;
- QuantityKg = quantityKg;
- PricePerKg = pricePerKg;
- }
- public int GetTaxPercentage()
- {
- return this.TaxPercentage;
- }
- public double CalculateAmount()
- {
- return (this.QuantityKg * this.PricePerKg) + (this.QuantityKg * this.PricePerKg * (this.TaxPercentage / 100));
- }
- public double CalculateTaxAmount()
- {
- return (this.QuantityKg * this.PricePerKg * (this.TaxPercentage / 100));
- }
- }
- // 11. zadatak - C#
- // ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement