Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Phones {
- private:
- string brand;
- double price;
- double screen_size;
- public:
- Phones(string brand, double price, double screen_size) {
- this->brand = brand;
- this->price = price;
- this->screen_size = screen_size;
- }
- ~Phones() {}
- double getPrice() {
- return price;
- }
- void print() {
- cout << "Brand: " << brand << endl;
- cout << "Price: " << price << endl;
- cout << "Screen size: " << screen_size << endl;
- }
- };
- void findMostExpensive(Phones arr[], int size) {
- double maxPrice = 0;
- int index = -1;
- for (int i = 0; i < size; i++) {
- if (arr[i].getPrice() > maxPrice) {
- maxPrice = arr[i].getPrice();
- index = i;
- }
- }
- if (index != -1) {
- cout << "The most expensive phone: " << endl;
- arr[index].print();
- }
- }
- void PrintAllPhones(Phones arr[], int size) {
- for (int i = 0; i < size; i++) {
- arr[i].print();
- cout << endl;
- }
- }
- int main() {
- const int size = 3;
- Phones phones[size] = { Phones("Samsung", 500, 6.2),
- Phones("Apple", 800, 6.1),
- Phones("Huawei", 400, 6.5) };
- PrintAllPhones(phones, size);
- cout << endl;
- findMostExpensive(phones, size);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement