Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <map>
- #include <set>
- #include <vector>
- #include <string>
- #include <stdio.h>
- using namespace std;
- class Electrical_facility //электрическая установка
- {
- protected:
- string type;
- double r;
- public:
- Electrical_facility(string newtype, double newr)
- {
- type = newtype;
- r = newr;
- }
- string get_type()
- {
- return type;
- }
- //void set_type(string newtype)
- //{
- // this->type = newtype;
- //}
- double get_r()
- {
- return r;
- }
- void set_r(double newr)
- {
- this->r = newr;
- }
- virtual void print()
- {
- cout << this->get_type() << ": " << this->get_r() << " Om" << endl;
- }
- };
- class Lamp : public Electrical_facility
- {
- protected:
- bool light;
- public:
- Lamp(double newr) : Electrical_facility("LMP", newr)
- {
- light = false;
- }
- bool get_light()
- {
- return light;
- }
- void set_light(bool newlight)
- {
- this->light = newlight;
- }
- void print()
- {
- cout << this->get_type() << ": " << this->get_r() << " Om ";
- if(this->get_light())
- cout << "light: on\n";
- else
- cout << "light: off\n";
- }
- };
- class Resistor : public Electrical_facility
- {
- public:
- Resistor(double newr) : Electrical_facility("RES", newr) {}
- void print()
- {
- cout << this->get_type() << ": " << this->get_r() << " Om" << endl;
- }
- };
- class Appliance : public Electrical_facility
- {
- protected:
- double req_u, req_i, du, di;
- bool is_working;
- public:
- Appliance(double newr, double newrequ, double newreqi,
- double newdu, double newdi) : Electrical_facility("APP", newr)
- {
- req_u = newrequ;
- du = newdu;
- req_i = newreqi;
- di = newdi;
- is_working = false;
- }
- double get_req_u()
- {
- return req_u;
- }
- void set_req_u(double newreq_u)
- {
- this->req_u = newreq_u;
- }
- double get_req_i()
- {
- return req_i;
- }
- void set_req_i(double newreq_i)
- {
- this->req_i = newreq_i;
- }
- double get_du()
- {
- return du;
- }
- void set_du(double newdu)
- {
- this->du = newdu;
- }
- double get_di()
- {
- return di;
- }
- void set_di(double newdi)
- {
- this->di = newdi;
- }
- void set_is_working(bool state)
- {
- this->is_working = state;
- }
- bool get_is_working()
- {
- return is_working;
- }
- void print()
- {
- cout << this->get_type() << ": " << this->get_r() << " Om ";
- if(this->get_is_working())
- cout << "work: on\n";
- else
- cout << "work: off\n";
- cout << " required: " << this->get_req_u() << "V " << this->get_req_i() << "A \n";
- cout << " variation: " << this->get_du() << "V " << this->get_di() << "A \n";
- }
- };
- class CCS : public Electrical_facility
- {
- protected:
- double e;
- public:
- CCS(double newr, double newe) : Electrical_facility("CCS", newr)
- {
- e = newe;
- }
- double get_e()
- {
- return e;
- }
- void set_e(double newe)
- {
- this->e = newe;
- }
- void print()
- {
- cout << this->get_type() << ": " << this->get_r() << " Om " << this->get_e() << " V" << endl;
- }
- };
- class Key : public Electrical_facility
- {
- protected:
- bool state;
- public:
- Key(bool newstate) : Electrical_facility("KEY", 0)
- {
- state = newstate;
- }
- bool get_state()
- {
- return state;
- }
- void set_state(bool newstate)
- {
- this->state = newstate;
- }
- void print()
- {
- cout << this->get_type() << ": ";
- if(this->get_state())
- cout << "locked \n";
- else
- cout << "unlocked \n";
- }
- };
- class Branch
- {
- protected:
- vector<Electrical_facility*> branch;
- public:
- Branch() {}
- void set_el_f(int chain_number, bool flag)
- {
- if(flag)
- {
- cout << "If you want to set a new lamp, please type 1" << endl;
- cout << "If you want to set a new resistor, please type 2" << endl;
- cout << "If you want to set a new appliance, please type 3" << endl;
- cout << "If you want to set a new CCS, please type 4" << endl;
- cout << "If you want to set a new key, please type 5" << endl;
- cout << "Be careful: you can set only CCS in main subchain" << endl;
- }
- int type, place; cin >> type;
- if(flag)
- cout << "Now please type the number of position, where you want to put it: ";
- cin >> place;
- Electrical_facility* new_obj = new Electrical_facility("error", -100500);
- double r, ru, ri, du, di, e;
- bool f = true;
- switch (type)
- {
- case 1:
- if(flag)
- cout << "Please enter the lamp resistance: ";
- cin >> r;
- if(chain_number)
- new_obj = new Lamp(r);
- else
- f = false;
- break;
- case 2:
- if(flag)
- cout << "Please enter the resistor resistance: ";
- cin >> r;
- if(chain_number)
- new_obj = new Resistor(r);
- else
- f = false;
- break;
- case 3:
- if(flag)
- {
- cout << "Please enter the appliance resistance, then required voltage and amperage, ";
- cout << "then variation of voltage and amperage: ";
- }
- cin >> r >> ru >> ri >> du >> di;
- if(chain_number)
- new_obj = new Appliance(r, ru, ri, du, di);
- else
- f = false;
- break;
- case 4:
- if(flag)
- cout << "Please enter the CCS resistance and electromotive force: ";
- cin >> r >> e;
- if(chain_number != 0)
- {
- if(flag)
- cout << "You can't place CCS here\n";
- f = false;
- }
- else
- new_obj = new CCS(r, e);
- break;
- case 5:
- if(flag)
- cout << "Please enter the key state: ";
- bool st;
- cin >> st;
- if(chain_number)
- new_obj = new Key(st);
- else
- f = false;
- break;
- default:
- f = false;
- if(flag)
- cout << "Something went wrong, please try again\n";
- break;
- }
- place--;
- if(f)
- if(place < 0 || place > branch.size())
- {
- if(flag)
- cout << "Something went wrong, please try again\n";
- }
- else
- {
- branch.insert(branch.begin() + place, new_obj);
- }
- }
- //bool is_empty(){
- // return branch.empty();
- //}
- void remove_el_f()
- {
- cout << "Please enter the number of the facility you want to remove: ";
- int n; cin >> n; n--;
- if(n >= branch.size() || n < 0)
- cout << "Something went wrong, please try again\n";
- else
- branch.erase(branch.begin() + n);
- }
- bool is_locked()
- {
- bool res = true;
- for(int i = 0; i < branch.size(); i++)
- {
- if(branch[i]->get_type() == "KEY")
- {
- Key key = *(dynamic_cast<Key*>(branch[i]));
- if(!key.get_state())
- {
- res = false;
- break;
- }
- }
- }
- return res;
- }
- double get_r_from_to(int from, int to)
- {
- double res = 0;
- from--, to--;
- if(to >= 0 && to < branch.size() && from >=0 && from < branch.size()
- && to >= from && this->is_locked())
- for(int i = from; i <= to; i++)
- res += branch[i]->get_r();
- return res;
- }
- void change_parameters(bool flag)
- {
- if(flag)
- {
- cout << "There are " << branch.size() << " elements in this branch\n";
- cout << "Enter the number of element which parameters you want to change: ";
- }
- int i; cin >> i; i--;
- if(i >= branch.size() || i < 0)
- {
- if(flag)
- cout << "Incorrect number of element, please try again\n";
- }
- else
- {
- string type = branch[i]->get_type();
- if(flag)
- cout << "Availiable changes: \n";
- if(type == "LMP")
- {
- Lamp* lmp = (dynamic_cast<Lamp*>(branch[i]));
- if(flag)
- {
- cout << "Internal resistance: now" << lmp->get_r() << " Om\n";
- cout << "Type 1 for changing the internal resistance, \n";
- cout << " 0 for exit: ";
- }
- int answer; cin >> answer;
- switch (answer)
- {
- case 1:
- if(flag)
- cout << "Enter new value of internal resistance: ";
- double r; cin >> r;
- lmp->set_r(r);
- break;
- case 0:
- break;
- default:
- if(flag)
- cout << "Incorrect command\n";
- break;
- }
- }
- else if(type == "RES")
- {
- Resistor* res = (dynamic_cast<Resistor*>(branch[i]));
- if(flag)
- {
- cout << "Resistance: now" << res->get_r() << " Om\n";
- cout << "Type 1 for changing the resistance, \n";
- cout << " 0 for exit: ";
- }
- int answer; cin >> answer;
- switch (answer)
- {
- case 1:
- if(flag)
- cout << "Enter new value of resistance: ";
- double r; cin >> r;
- res->set_r(r);
- break;
- case 0:
- break;
- default:
- if(flag)
- cout << "Incorrect command\n";
- break;
- }
- }
- else if(type == "APP")
- {
- Appliance* app = (dynamic_cast<Appliance*>(branch[i]));
- if(flag)
- {
- cout << "Internal resistance: now" << app->get_r() << " Om\n";
- cout << "Required voltage: now " << app->get_req_u() << " V\n";
- cout << "Required amperage: now " << app->get_req_i() << " A\n";
- cout << "Variation of voltage: now " << app->get_du() << " V\n";
- cout << "Variation of amperage: now " << app->get_di() << " A\n";
- cout << "Type 1 for changing the internal resistance, \n";
- cout << " 2 for changing the required voltage, \n";
- cout << " 3 for changing the required amperage, \n";
- cout << " 4 for changing the variation of voltage, \n";
- cout << " 5 for changing the variation of amperage, \n";
- cout << " 0 for exit: ";
- }
- int answer; cin >> answer;
- double u, i, r;
- switch (answer)
- {
- case 1:
- if(flag)
- cout << "Enter new value of internal resistance: ";
- cin >> r;
- app->set_r(r);
- break;
- case 2:
- if(flag)
- cout << "Enter new value of required voltage: ";
- cin >> u;
- app->set_req_u(u);
- break;
- case 3:
- if(flag)
- cout << "Enter new value of required amperage: ";
- cin >> i;
- app->set_req_i(i);
- break;
- case 4:
- if(flag)
- cout << "Enter new value of variation of voltage: ";
- cin >> u;
- app->set_du(u);
- break;
- case 5:
- if(flag)
- cout << "Enter new value of variation of amperage: ";
- cin >> i;
- app->set_di(i);
- break;
- case 0:
- break;
- default:
- if(flag)
- cout << "Incorrect command\n";
- break;
- }
- }
- else if(type == "CCS")
- {
- CCS* ccs = (dynamic_cast<CCS*>(branch[i]));
- if(flag)
- {
- cout << "Internal resistance: now" << ccs->get_r() << " Om\n";
- cout << "Electromotive force of the CCS: now " << ccs->get_e() << " V\n";
- cout << "Type 1 for changing the internal resistance, \n";
- cout << " 2 for changing the electromotive force, \n";
- cout << " 0 for exit: ";
- }
- int answer; cin >> answer;
- switch (answer)
- {
- case 1:
- if(flag)
- cout << "Enter new value of internal resistance: ";
- double r; cin >> r;
- ccs->set_r(r);
- break;
- case 2:
- if(flag)
- cout << "Enter new value of electromotive force: ";
- double e; cin >> e;
- ccs->set_e(e);
- break;
- case 0:
- break;
- default:
- if(flag)
- cout << "Incorrect command\n";
- break;
- }
- }
- else if(type == "KEY")
- {
- Key* key = (dynamic_cast<Key*>(branch[i]));
- if(flag)
- cout << "State of the key: now ";
- if(key->get_state())
- {
- if(flag)
- cout << "locked\n";
- }
- else
- {
- if(flag)
- cout << "unlocked\n";
- }
- if(flag)
- cout << "Type 1 for changing the key state, 0 for exit: ";
- int answer; cin >> answer;
- switch (answer)
- {
- case 1:
- if(flag)
- cout << "Type 1 (or 0) for locking (or unlocking) the key: ";
- bool newstate; cin >> newstate;
- key->set_state(newstate);
- case 0:
- break;
- default:
- if(flag)
- cout << "Incorrect command\n";
- break;
- }
- }
- else
- {
- if(flag)
- cout << "Coder, you have a great error! Fix it immideately!" << endl;
- }
- }
- }
- int size()
- {
- return branch.size();
- }
- bool is_shorted_path()
- {
- if(branch.size() == 0)
- return true;
- if(!this->is_locked())
- return false;
- for(int i = 0; i < branch.size(); i++)
- {
- if(branch[i]->get_type() != "KEY")
- return false;
- }
- return true;
- }
- void print(){
- for(int i = 0; i < branch.size(); i++)
- branch[i]->print();
- }
- double get_emf()
- {
- double res = 0;
- for(int i = 0; i < branch.size(); i++)
- {
- if(branch[i]->get_type() == "CCS")
- {
- CCS* ccs = (dynamic_cast<CCS*>(branch[i]));
- res += ccs->get_e();
- }
- }
- return res;
- }
- };
- class Subchain //please test me, i am not tested
- {
- protected:
- vector<Branch*> subchain;
- public:
- void set_branch(int subchain_number, bool flag)
- {
- if(subchain_number == 0 && subchain.size() > 0)
- {
- if(flag)
- cout << "Sorry, you can't have more than 1 branch in main subchain\n";
- }
- else
- subchain.push_back(new Branch());
- }
- void set_el(int subchain_number, bool flag)
- {
- if(flag)
- {
- cout << "There are " << subchain.size() << " branches in subchain\n";
- cout << "Please type the number of branch where you want to set the element: ";
- }
- int j; cin >> j; j--;
- if(j >= 0 && j < subchain.size())
- subchain[j]->set_el_f(subchain_number, flag);
- else
- {
- if(flag)
- cout << "Incorrect number of branch\n";
- }
- }
- void change_parameters(bool flag)
- {
- if(flag)
- {
- cout << "There are " << subchain.size() << " branches in subchain\n";
- cout << "Please type the number of branch where you want to\n";
- cout << "change parameters of the element: ";
- }
- int j; cin >> j; j--;
- if(j >= 0 && j < subchain.size())
- subchain[j]->change_parameters(flag);
- else
- if(flag)
- cout << "Incorrect number of branch\n";
- }
- void remove_el()
- {
- cout << "There are " << subchain.size() << " branches in subchain\n";
- cout << "Please type the number of branch where you want to delete the element: ";
- int j; cin >> j; j--;
- if(j >= 0 && j < subchain.size())
- subchain[j]->remove_el_f();
- else
- cout << "Incorrect number of branch\n";
- }
- bool has_shorted_paths()
- {
- for(int i = 0; i < subchain.size(); i++)
- {
- if(subchain[i]->is_shorted_path())
- return true;
- }
- return false;
- }
- double get_r_from_to(int j, int from, int to)
- {
- if(j == -1)
- {
- cout << "Please enter the number of branch where needed elements are: ";
- cin >> j; j--;
- }
- double res = 0;
- if(j >= 0 && j < subchain.size())
- {
- if(from == -1 || to == -1)
- {
- cout << "Please enter the numbers of first and last elements for calculating\n";
- cin >> from >> to;
- }
- res = subchain[j]->get_r_from_to(from, to);
- }
- else
- cout << "Incorrect number of branch\n";
- return res;
- }
- double get_r_branch(int j)
- {
- if(j == -1)
- {
- cout << "Please enter the number of branch where you want to find resistance value: ";
- cin >> j; j--;
- }
- double res = 0;
- if(j >= 0 && j < subchain.size())
- res = subchain[j]->get_r_from_to(1, subchain[j]->size());
- else
- cout << "Incorrect number of branch\n";
- return res;
- }
- double get_r_subchain()
- {
- double sum = 0.0;
- double sum_of_branch = 0.0;
- int cnt = 0;
- if(this->has_shorted_paths())
- return 0;
- for(int i = 0; i < subchain.size(); i++)
- {
- if(subchain[i]->is_locked())
- {
- double r = subchain[i]->get_r_from_to(1, subchain[i]->size());
- sum_of_branch = r;
- sum += 1 / r;
- cnt++;
- }
- }
- if(cnt == 0)
- return 0;
- else if(cnt == 1)
- return sum_of_branch;
- else
- return 1 / sum;
- }
- bool is_locked()
- {
- bool res = true;
- if(!subchain.empty())
- {
- res = subchain[0]->is_locked();
- for(int i = 1; i < subchain.size(); i++)
- {
- res = res || subchain[i]->is_locked();
- }
- }
- return res;
- }
- void remove_branch()
- {
- cout << "There are " << subchain.size() << " branches in subchain\n";
- cout << "Please enter the number of branch you want to remove: ";
- int j; cin >> j; j--;
- if(j >= 0 && j < subchain.size())
- subchain.erase(subchain.begin() + j);
- else
- cout << "Incorrect number of branch\n";
- }
- int size()
- {
- return subchain.size();
- }
- void print()
- {
- for(int i = 0; i < subchain.size(); i++)
- {
- cout << "Branch " << i + 1 << endl;
- subchain[i]->print();
- cout << endl;
- }
- }
- double get_emf()
- {
- return subchain[0]->get_emf();
- }
- };
- class Chain
- {
- protected:
- vector<Subchain*> chain;
- public:
- void set(bool flag)
- {
- if(flag)
- {
- cout << "Type 0 to exit\n";
- cout << "Type 1 to set a new subchain\n";
- cout << "Type 2 to set a new branch\n";
- cout << "Type 3 to set a new element\n";
- }
- int n; cin >> n;
- if(n == 1) chain.push_back(new Subchain());
- else
- if(n == 2 || n == 3)
- {
- if(flag)
- {
- cout << "Please enter the number of subchain where you want to set new ";
- if(n == 2) cout << "branch: ";
- if(n == 3) cout << "element: ";
- }
- int i; cin >> i; i--;
- if(i >= 0 && i < chain.size())
- {
- if(n == 2) chain[i]->set_branch(i, flag); //
- if(n == 3) chain[i]->set_el(i, flag);
- }
- else
- {
- if(flag)
- cout << "Incorrect number of subchain\n";
- }
- }
- }
- /*void set_subchain()
- {
- chain.push_back(new Subchain());
- }
- void set_branch()
- {
- cout << "Please enter the number of subchain where you want to set new branch: ";
- int i; cin >> i; i--;
- if(i >= 0 && i < chain.size())
- chain[i]->set_branch();
- else
- cout << "Incorrect number of subchain\n";
- }
- void set_el()
- {
- cout << "Please enter the number of subchain where you want to set new element: ";
- int i; cin >> i; i--;
- if(i >= 0 && i < chain.size())
- chain[i]->set_el(i);
- else
- cout << "Incorrect number of subchain\n";
- }*/
- //void remove_el()
- //{
- // cout << "Please enter the number of chain where you want to remove the element: ";
- // int i; cin >> i; i--;
- // if(i >= 0 && i < chain.size())
- // chain[i]->remove_el();
- // else
- // cout << "Incorrect number of chain\n";
- //}
- //void remove_branch()
- //{
- // cout << "Please enter the number of chain where you want to remove the branch: ";
- // int i; cin >> i; i--;
- // if(i >= 0 && i < chain.size())
- // chain[i]->remove_branch();
- // else
- // cout << "Incorrect number of chain\n";
- //}
- //void remove_chain()
- //{
- // cout << "Please enter the number of chain you want to remove: ";
- // int i; cin >> i; i--;
- // if(i >= 0 && i < chain.size())
- // chain.erase(chain.begin() + i);
- // else
- // cout << "Incorrect number of chain\n";
- //}
- void remove()
- {
- map<int, pair<string, string>> m;
- m[0] = make_pair("exit", "error");
- m[1] = make_pair("element",
- "Please enter the number of subchain where you want to remove the element: ");
- m[2] = make_pair("branch",
- "Please enter the number of subchain where you want to remove the branch: ");
- m[3] = make_pair("subchain",
- "Please enter the number of subchain you want to remove: ");
- for(int i = 0; i < 4; i++)
- cout << "Type " << i << " to remove the " << m[i].first << endl;
- int n; cin >> n;
- if(n > 0 && n < 4)
- {
- cout << m[n].second;
- int i; cin >> i; i--;
- if(i >= 0 && i < chain.size())
- {
- if(n == 1) chain[i]->remove_el();
- else if(n == 2) chain[i]->remove_branch();
- else if(n == 3) chain.erase(chain.begin() + i);
- }
- else
- cout << "Incorrect number of subchain\n";
- }
- }
- void change_parameters(bool flag)
- {
- if(flag)
- {
- cout << "Please enter the number of subchain where you want to\n";
- cout << "change paramaters of the element: ";
- }
- int i; cin >> i; i--;
- if(i >= 0 && i < chain.size())
- chain[i]->change_parameters(flag);
- else
- {
- if(flag)
- cout << "Incorrect number of subchain\n";
- }
- }
- bool is_locked()
- {
- bool res = true;
- for(int i = 0; i < chain.size(); i++)
- {
- res = res && chain[i]->is_locked();
- }
- return res;
- }
- double get_r_chain()
- {
- double r = 0.0;
- for(int i = 0; i < chain.size(); i++)
- r += chain[i]->get_r_subchain();
- return r;
- }
- double get_r_subchain(int i)
- {
- if(i == -1)
- {
- cout << "Please enter the number of subchain which resistance you need: ";
- cin >> i; i--;
- }
- double r = 0;
- if(i >= 0 && i < chain.size())
- r = chain[i]->get_r_subchain();
- else
- cout << "Incorrect number of subchain\n";
- return r;
- }
- double get_r_branch(int i, int j)
- {
- if(i == -1)
- {
- cout << "Please enter the number of subchain where needed branch is: ";
- cin >> i; i--;
- }
- double r = 0;
- if(i >= 0 && i < chain.size())
- r = chain[i]->get_r_branch(j);
- else
- cout << "Incorrect number of subchain\n";
- return r;
- }
- double get_r_from_to(int i, int j, int from, int to)
- {
- if(i == -1)
- {
- cout << "Please enter the number of subchain where needed elements are: ";
- cin >> i; i--;
- }
- double r = 0;
- if(i >= 0 && i < chain.size())
- r = chain[i]->get_r_from_to(j, from, to);
- else
- cout << "Incorrect number of subchain\n";
- return r;
- }
- void print()
- {
- for(int i = 0; i < chain.size(); i++)
- {
- cout << "Subchain " << i + 1 << endl;
- chain[i]->print();
- }
- }
- double get_i(int subch, int br, bool flag)
- {
- if(subch == -1 && br == -1)
- {
- cout << "Type the coordinates: number of subchain and number of branch: ";
- cin >> subch >> br;
- subch--; br--;
- }
- double res = 0;
- string s = "";
- if(subch >= 0 && subch < chain.size())
- {
- if(br >= 0 && br < chain[subch]->size())
- {
- if(this->is_locked())
- {
- //double r_all = this->get_r_chain();
- //double u_all = chain[0]->get_emf();
- double i_all = this->get_i_all(flag);
- //if(r_all == 0)
- //{
- // s = "Chain is shorted\n";
- //}
- //else
- //{
- //i_all = u_all / r_all;
- double r_subch = this->get_r_subchain(subch);
- double r_branch = this->get_r_branch(subch, br);
- //cout << u_all << " " << i_all << " " << r_all << endl;
- //cout << r_subch << " " << r_branch << endl;
- if(r_subch == 0)
- s = "Subchain is shorted\n";
- else if(r_branch == 0)
- s = "Branch is shorted\n";
- else
- res = i_all * r_subch / r_branch;
- //}
- }
- else
- s = "Chain is unlocked\n";
- }
- else
- s = "Incorrect number of branch\n";
- }
- else
- s = "Incorrect number of subchain\n";
- if(flag)
- cout << s;
- return res;
- }
- double get_i_all(bool flag)
- {
- double i_all = 0;
- string s;
- if(this->is_locked())
- {
- if(chain.size())
- {
- double r_all = this->get_r_chain();
- double u_all = chain[0]->get_emf();
- if(r_all == 0)
- {
- s = "Chain is shorted\n";
- }
- else
- {
- i_all = u_all / r_all;
- }
- }
- else
- s = "Chain has no CCS in it\n";
- }
- else
- s = "Chain is unlocked\n";
- if(flag)
- cout << s;
- return i_all;
- }
- void check_state()
- {
- for(int i = 0; i < chain.size(); i++)
- {
- chain[i]->check_state();
- }
- }
- double get_u_chain(bool flag)
- {
- double res = 0;
- if(this->is_locked())
- {
- if(chain.size())
- res = chain[0]->get_emf();
- else
- {
- if(flag)
- cout << "Chain has no CCS in it\n";
- }
- }
- else
- {
- if(flag)
- cout << "Chain is unlocked\n";
- }
- return res;
- }
- double get_u_subchain(bool flag)
- {
- double res = 0;
- if(flag)
- cout << "Enter the number of subchain which voltage you want to calculate: ";
- int subch; cin >> subch; subch--;
- if(subch >=0 && subch < chain.size())
- {
- if(this->is_locked())
- {
- double r = this->get_r_subchain(subch);
- if(r == 0)
- {
- if(flag)
- cout << "Subchain is shorted\n";
- }
- else
- {
- double i_all = this->get_i_all(flag);
- res = r * i_all;
- }
- }
- else
- {
- if(flag)
- cout << "Chain is unlocked\n";
- }
- }
- else
- {
- if(flag)
- cout << "Incorrect subchain number\n";
- }
- return res;
- }
- double get_u_branch(bool flag)
- {
- if(flag)
- cout << "Type the coordinates: number of subchain and number of branch: ";
- int subch, br;
- cin >> subch >> br;
- subch--; br--;
- double i = this->get_i(subch, br, flag);
- double r = this->get_r_branch(subch, br);
- return i * r;
- }
- double get_u_from_to(bool flag)
- {
- if(flag)
- {
- cout << "Type the coordinates: number of subchain and number of branch, ";
- cout << "number of start and finish objects for calculating: ";
- }
- int subch, br, from, to;
- cin >> subch >> br >> from >> to;
- subch--; br--;
- double i = this->get_i(subch, br, flag);
- double r = this->get_r_from_to(subch, br, from, to);
- return i * r;
- }
- };
- int main()
- {
- //#ifdef _DEBUG
- // freopen("in.txt", "r", stdin);
- // freopen("out.txt", "w", stdout);
- //#endif
- Chain* chain = new Chain();
- int n = 1;
- while(n != 26)
- {
- cout << "1 - set\n";
- cout << "2 - is_locked\n";
- cout << "3 - remove\n";
- cout << "4 - change_parameters\n";
- cout << "5 - print\n";
- cout << "6 - get_r_chain\n";
- cout << "7 - get_r_subchain\n";
- cout << "8 - get_r_branch\n";
- cout << "9 - get_r_from_to1\n";
- cout << "10 - get_i_all\n";
- cout << "11 - get_u_chain\n";
- cout << "12 - get_u_subchain\n";
- cout << "13 - get_u_branch\n";
- cout << "14 - get_u_from_to1\n";
- cout << "15 - get_i\n";
- cin >> n;
- switch (n)
- {
- case 1:
- chain->set(true);
- break;
- case 2:
- cout << chain->is_locked() << endl;
- break;
- case 3:
- chain->remove();
- break;
- case 4:
- chain->change_parameters(true);
- break;
- case 5:
- chain->print();
- break;
- case 6:
- cout << chain->get_r_chain() << endl;
- break;
- case 7:
- cout << chain->get_r_subchain(-1) << endl;
- break;
- case 8:
- cout << chain->get_r_branch(-1, -1) << endl;
- break;
- case 9:
- cout << chain->get_r_from_to(-1, -1, -1, -1) << endl;
- break;
- case 10:
- cout << chain->get_i_all(true) << endl;
- break;
- case 11:
- cout << chain->get_u_chain(true) << endl;
- break;
- case 12:
- cout << chain->get_u_subchain(true) << endl;
- break;
- case 13:
- cout << chain->get_u_branch(true) << endl;
- break;
- case 14:
- cout << chain->get_u_from_to(true) << endl;
- break;
- case 15:
- cout << chain->get_i(-1, -1, true) << endl;
- break;
- default:
- break;
- }
- }
- cout << "compilation completed\n";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement