Skip to content
This repository was archived by the owner on Jul 30, 2023. It is now read-only.

Commit c926ca9

Browse files
author
danyathecoder
committed
lab8
1 parent dac0c9f commit c926ca9

14 files changed

+1455
-0
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Lab2_source/main.cpp Lab2/main.cpp

File renamed without changes.

Lab8/Drug.cpp

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// Created by danilapoddubny on 15/12/2020.
3+
//
4+
5+
#include "Drug.h"
6+
#include<iostream>
7+
8+
Drug::Drug(const std::string &name, const std::string &country, int date, int rating, int sold) : name(name),
9+
country(country),
10+
date(date),
11+
rating(rating),
12+
sold(sold) {}
13+
14+
Drug::Drug() : name("name"),
15+
country("country"),
16+
date(100),
17+
rating(10),
18+
sold(100) {}
19+
20+
const std::string &Drug::getName() const {
21+
return name;
22+
}
23+
24+
void Drug::setName(const std::string &name) {
25+
Drug::name = name;
26+
}
27+
28+
const std::string &Drug::getCountry() const {
29+
return country;
30+
}
31+
32+
void Drug::setCountry(const std::string &country) {
33+
Drug::country = country;
34+
}
35+
36+
int Drug::getDate() const {
37+
return date;
38+
}
39+
40+
void Drug::setDate(int date) {
41+
Drug::date = date;
42+
}
43+
44+
int Drug::getRating() const {
45+
return rating;
46+
}
47+
48+
void Drug::setRating(int rating) {
49+
Drug::rating = rating;
50+
}
51+
52+
int Drug::getSold() const {
53+
return sold;
54+
}
55+
56+
void Drug::setSold(int sold) {
57+
Drug::sold = sold;
58+
}
59+
60+
bool operator==(const Drug &lhs, const Drug &rhs) {
61+
return lhs.name == rhs.name &&
62+
lhs.country == rhs.country &&
63+
lhs.date == rhs.date &&
64+
lhs.rating == rhs.rating &&
65+
lhs.sold == rhs.sold;
66+
}
67+
68+
bool operator<(const Drug &lhs, const Drug &rhs) {
69+
if (lhs.name < rhs.name)
70+
return true;
71+
if (rhs.name < lhs.name)
72+
return false;
73+
if (lhs.country < rhs.country)
74+
return true;
75+
if (rhs.country < lhs.country)
76+
return false;
77+
if (lhs.date < rhs.date)
78+
return true;
79+
if (rhs.date < lhs.date)
80+
return false;
81+
if (lhs.rating < rhs.rating)
82+
return true;
83+
if (rhs.rating < lhs.rating)
84+
return false;
85+
return lhs.sold < rhs.sold;
86+
}
87+
88+
bool operator>(const Drug &lhs, const Drug &rhs) {
89+
return rhs < lhs;
90+
}
91+
92+
bool operator<=(const Drug &lhs, const Drug &rhs) {
93+
return !(rhs < lhs);
94+
}
95+
96+
bool operator>=(const Drug &lhs, const Drug &rhs) {
97+
return !(lhs < rhs);
98+
}
99+
100+
std::ostream &operator<<(std::ostream &os, const Drug &drug) {
101+
os << "name: " << drug.name << " country: " << drug.country << " date: " << drug.date << " rating: " << drug.rating
102+
<< " sold: " << drug.sold;
103+
return os;
104+
}
105+
106+
std::istream& operator>>(std::istream& in, Drug& drug)
107+
{
108+
in >> drug.name;
109+
in >> drug.country;
110+
in >> drug.date;
111+
in >> drug.rating;
112+
in >> drug.sold;
113+
return in;
114+
}

Lab8/Drug.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// Created by danilapoddubny on 15/12/2020.
3+
//
4+
5+
#ifndef LAB8_DRUG_H
6+
#define LAB8_DRUG_H
7+
8+
#include <string>
9+
#include <ostream>
10+
11+
class Drug {
12+
public:
13+
Drug(const std::string &name, const std::string &country, int date, int rating, int sold);
14+
Drug();
15+
16+
const std::string &getName() const;
17+
18+
void setName(const std::string &name);
19+
20+
const std::string &getCountry() const;
21+
22+
void setCountry(const std::string &country);
23+
24+
int getDate() const;
25+
26+
void setDate(int date);
27+
28+
int getRating() const;
29+
30+
void setRating(int rating);
31+
32+
int getSold() const;
33+
34+
void setSold(int sold);
35+
36+
bool operator!=(const Drug &rhs) const;
37+
38+
friend bool operator==(const Drug &lhs, const Drug &rhs);
39+
40+
friend bool operator<(const Drug &lhs, const Drug &rhs);
41+
42+
friend bool operator>(const Drug &lhs, const Drug &rhs);
43+
44+
friend bool operator<=(const Drug &lhs, const Drug &rhs);
45+
46+
friend bool operator>=(const Drug &lhs, const Drug &rhs);
47+
48+
friend std::ostream &operator<<(std::ostream &os, const Drug &drug);
49+
50+
friend std::istream &operator>>(std::istream& in, Drug& drug);
51+
52+
private:
53+
std::string name;
54+
std::string country;
55+
int date;
56+
int rating;
57+
int sold;
58+
};
59+
60+
61+
#endif //LAB8_DRUG_H

Lab8/Exception.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//
2+
// Created by danilapoddubny on 16/12/2020.
3+
//
4+
5+
#include "Exception.h"
6+
7+
const std::string &Exception::getMessage() const {
8+
return message;
9+
}
10+
11+
Exception::Exception(const std::string &message) : message(message) {}

Lab8/Exception.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Created by danilapoddubny on 16/12/2020.
3+
//
4+
5+
#ifndef LAB8_EXCEPTION_H
6+
#define LAB8_EXCEPTION_H
7+
8+
#include <string>
9+
10+
class Exception {
11+
public:
12+
Exception(const std::string &message);
13+
14+
const std::string &getMessage() const;
15+
16+
private:
17+
std::string message;
18+
19+
};
20+
21+
22+
#endif //LAB8_EXCEPTION_H

0 commit comments

Comments
 (0)