Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 3

#include <iostream>

#include <stdlib.h>
#include<string>
using namespace std;

class Furniture {
private:
string name;
float price;
public:
Furniture() : name(""), price() {}
Furniture(string c_name, float c_price) :
name(c_name),
price(c_price) {}

void setData()
{
string c_name;
float c_price;
cin.ignore();
cout << "Furniture name: "; getline(cin, c_name);
this->SetName(c_name);
cout << "Enter price: "; cin >> c_price;
this->SetPrice(c_price);

}
void displayData()
{
cout << "Furniture name: " << this->GetName() << endl;
cout << "Price: " << this->GetPrice() << endl;
}

void SetName(string c_name)


{
this->name = c_name;
}

void SetPrice(float c_price)


{
this->price = c_price;
}

string GetName()
{
return this->name;
}
float GetPrice()
{
return this->price;
}
};

class Chair : public Furniture {


private:
string colour;
public:
Chair() :Furniture(), colour("") {}

Chair(string c_name, float c_price, string c_colour) :Furniture(c_name, c_price),


colour(c_colour) {}

void setData()
{
string c_colour;
cin.ignore();
cout << "Colour: "; getline(cin, c_colour);
this->SetColour(c_colour);
}

void displayData()
{
cout << "Colour: " << this->GetColour() << endl;
}

void SetColour(string c_colour)


{
this->colour = c_colour;
}
string GetColour()
{
return this->colour;
}

};

class Table : public Furniture {


private:
int count_on_table;
public:
Table() :Furniture(), count_on_table() {}

Table(string c_name, float c_price, int c_count_on_table) :Furniture(c_name,


c_price), count_on_table(c_count_on_table) {}

void setData()
{
int c_count_on_table;
cout << "Table count: "; cin >> c_count_on_table;
this->SetCountTable(c_count_on_table);
}

void displayData()
{
cout << "Table count: " << this->GetCountTable() << endl;
}

void SetCountTable(int c_count_on_table)


{
this->count_on_table = c_count_on_table;
}
int GetCountTable()
{
return this->count_on_table;
}

int main()
{
char operation;
Table tables[10];
Chair chairs[10];
int cout = 0;
do {
std::cout << "\n MENU\n";
std::cout << "1-Get Data: \n";
std::cout << "2-Display data\n";
std::cout << "\n Chose or cancel by pressing 0\n";
cin >> operation;
switch (operation)
{
case'0':break;
case'1':tables[cout++].setData(); chairs[cout].setData(); break;
case'2':std::cout << "Display data\n";
for (int i = 0; i < cout; i++)
{
chairs[i].displayData();
tables[i].displayData();
}
break;
default:
break;
}
} while (operation != '0');
return 0;
}
};

You might also like