Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1vata zadacha d i
- #include <iostream>
- using namespace std;
- class Room {
- public:
- Room() { }
- virtual void displayRoomInfo() = 0;
- virtual void displayRoomPrice() = 0;
- virtual ~Room() { }
- };
- class StandardRoom : public Room {
- bool hasBathroom;
- public:
- StandardRoom() {
- this->hasBathroom = false;
- }
- StandardRoom(bool hasBathroom) {
- this->hasBathroom = hasBathroom;
- }
- void displayRoomInfo() {
- cout << "This is a standard room with a queen-sized bed";
- if(hasBathroom) cout << " and a bathroom";
- cout << ".\n";
- }
- void displayRoomPrice() {
- cout << "The price for a standard room is $";
- if(hasBathroom) cout << "100";
- else cout << "80";
- cout << " per night.\n";
- }
- ~StandardRoom() { }
- };
- class DeluxeRoom : public Room {
- bool hasBalcony;
- public:
- DeluxeRoom() { this->hasBalcony = false; }
- DeluxeRoom(bool hasBalcony) { this->hasBalcony = hasBalcony; }
- void displayRoomInfo() {
- cout << "This is a deluxe room with a king-sized bed, a bathroom, a mini-fridge";
- if(hasBalcony) cout << " and a balcony";
- cout << ".\n";
- }
- void displayRoomPrice() {
- cout << "The price for a deluxe room is $";
- if(hasBalcony) cout << "200";
- else cout << "160";
- cout << " per night.\n";
- }
- ~DeluxeRoom() { }
- };
- int main() {
- Room* rooms[5];
- int testCase;
- cin >> testCase;
- if (testCase == 1) {
- cout << "TEST CASE 1: TESTING STANDARD ROOM CLASS" << endl;
- for (int i = 0; i < 5; i++) {
- rooms[i] = new StandardRoom();
- rooms[i]->displayRoomInfo();
- rooms[i]->displayRoomPrice();
- }
- } else if (testCase == 2) {
- cout << "TEST CASE 2: TESTING DELUXE ROOM CLASS" << endl;
- for (int i = 0; i < 5; i++) {
- rooms[i] = new DeluxeRoom();
- rooms[i]->displayRoomInfo();
- rooms[i]->displayRoomPrice();
- }
- } else {
- cout << "TEST CASE 3: TESTING BOTH CLASSES" << endl;
- for (int i = 0; i < 5; i++) {
- if (i % 2) {
- bool hasBalcony;
- cin >> hasBalcony;
- rooms[i] = new DeluxeRoom(hasBalcony);
- }
- else {
- bool hasBathroom;
- cin >> hasBathroom;
- rooms[i] = new StandardRoom(hasBathroom);
- }
- rooms[i]->displayRoomInfo();
- rooms[i]->displayRoomPrice();
- }
- }
- return 0;
- ---------------------------------------------------------------------------------------------------------------------------------------
- //2ra
- #include <iostream>
- #include <cstring>
- using namespace std;
- class FoodItem {
- protected:
- char* tip;
- int n;
- public:
- FoodItem() {
- this->tip = new char[8];
- strcpy(this->tip, "empty");
- this->n = 0;
- }
- FoodItem(char* type, int n) {
- this->tip = new char[strlen(type) + 1];
- strcpy(this->tip, type);
- this->n = n;
- }
- char* getType() { return tip; }
- virtual int getPrice() = 0;
- virtual int getTime() = 0;
- virtual ~FoodItem() {
- delete [] tip;
- }
- };
- class Pizza : public FoodItem {
- char* dough;
- public:
- Pizza() : FoodItem() {
- this->dough = new char[12];
- strcpy(this->dough, "wholeWheat");
- }
- Pizza(char* tip, int n, char* dough) : FoodItem(tip, n) {
- this->dough = new char[strlen(dough) + 1];
- strcpy(this->dough, dough);
- }
- int getPrice() {
- if(strcmp(this->dough, "wholeWheat") == 0) {
- return 250 * n;
- }
- else if(strcmp(this->dough, "glutenFree") == 0) {
- return 350 * n;
- } else {
- return 0;
- }
- }
- int getTime() { return 25; }
- ~Pizza() {
- delete [] dough;
- }
- };
- class Steak : public FoodItem {
- bool cooked;
- public:
- Steak() : FoodItem() {
- this->cooked = false;
- }
- Steak(char* tip, int n, bool cooked) : FoodItem(tip, n) {
- this->cooked = cooked;
- }
- int getPrice() { return 1300 * n; }
- int getTime() {
- if(cooked) return 20;
- else if(!cooked) return 15;
- else return 0;
- }
- ~Steak() { }
- };
- FoodItem* getMaxFoodItem(FoodItem* pItem[], int n) {
- FoodItem* item = pItem[0];
- int max_food_price = pItem[0]->getPrice();
- for(int i = 0; i < n; i++) {
- if(max_food_price < pItem[i]->getPrice()) {
- max_food_price = pItem[i]->getPrice();
- item = pItem[i];
- }
- }
- return item;
- }
- int main() {
- FoodItem *p;
- int n;
- cin>>n;
- char type[30];
- char dough[30];
- bool cooked;
- int size;
- FoodItem *items[n];
- for (int i = 0; i <n; ++i) {
- cin>>type;
- cin>>size;
- if(strcmp(type, "pizza")==0 ) {
- cin>>dough;
- items[i] = new Pizza(type, size, dough);
- }else{
- cin>>cooked;
- items[i] = new Steak(type, size, cooked);
- }
- }
- FoodItem *it = getMaxFoodItem(items, n);
- cout<<"Type: "<<it->getType()<<endl;
- cout<<"The max price is: "<<it->getPrice()<<endl;
- cout<<"Time to cook: "<<it->getTime();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement