Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class StockRecord {
- private:
- char id[12];
- char ime[50];
- float kupenaCena;
- float momentalnaCena;
- int brAkcii;
- public:
- StockRecord(const char *id="", const char *ime="", float momentalnaCena=0, int brAkcii=0){
- strcpy(this->id, id);
- strcpy(this->ime, ime);
- this->momentalnaCena = momentalnaCena;
- this->brAkcii = brAkcii;
- }
- void setNewPrice(double c){
- this->kupenaCena = c;
- }
- double value(){
- return brAkcii*kupenaCena;
- }
- double profit(){
- return brAkcii*(momentalnaCena - kupenaCena);
- }
- friend ostream &operator<< (ostream &o, const StockRecord &rhs){
- o << rhs.ime << " " << rhs.brAkcii << " " << rhs.momentalnaCena << " " << rhs.kupenaCena << " " <<
- rhs.brAkcii*(rhs.momentalnaCena - rhs.kupenaCena)*-1 << endl; return o;
- }
- };
- class Client{
- private:
- char imePrezime[60];
- int id;
- StockRecord *sr;
- int brAkcii;
- public:
- Client(const char *imePrezime="", int id=0){
- strcpy(this->imePrezime, imePrezime);
- brAkcii = 0;
- this->id = id;
- }
- ~Client(){ delete [] sr; }
- double totalValue(){
- double sum=0;
- for(int i=0; i<brAkcii; i++){
- sum+=sr[i].value();
- }
- return sum;
- }
- Client& operator+=(const StockRecord &c) {
- StockRecord *temp = new StockRecord[brAkcii+1];
- for(int i=0; i<brAkcii; i++)
- temp[i]=sr[i];
- temp[brAkcii]=c;
- sr = temp;
- brAkcii++;
- return *this;
- }
- friend ostream &operator<< (ostream &o, Client &rhs){
- o << rhs.id << " " << rhs.totalValue() << endl;
- for(int i=0; i<rhs.brAkcii; i++){
- o << rhs.sr[i];
- }
- return o;
- }
- };
- // ne menuvaj vo main-ot
- int main(){
- int test;
- cin >> test;
- if(test == 1){
- double price;
- cout << "=====TEST NA KLASATA StockRecord=====" << endl;
- StockRecord sr("1", "Microsoft", 60.0, 100);
- cout << "Konstruktor OK" << endl;
- cin >> price;
- sr.setNewPrice(price);
- cout << "SET metoda OK" << endl;
- }
- else if(test == 2){
- cout << "=====TEST NA METODITE I OPERATOR << OD KLASATA StockRecord=====" << endl;
- char id[12], company[50];
- double price, newPrice;
- int n, shares;
- cin >> n;
- for(int i = 0; i < n; ++i){
- cin >> id;
- cin >> company;
- cin >> price;
- cin >> newPrice;
- cin >> shares;
- StockRecord sr(id, company, price, shares);
- sr.setNewPrice(newPrice);
- cout << sr.value() << endl;
- cout << sr;
- }
- }
- else if(test == 3){
- cout << "=====TEST NA KLASATA Client=====" << endl;
- char companyID[12], companyName[50], clientName[50];
- int clientID, n, shares;
- double oldPrice, newPrice;
- bool flag = true;
- cin >> clientName;
- cin >> clientID;
- cin >> n;
- Client c(clientName, clientID);
- cout << "Konstruktor OK" << endl;
- for(int i = 0; i < n; ++i){
- cin >> companyID;
- cin >> companyName;
- cin >> oldPrice;
- cin >> newPrice;
- cin >> shares;
- StockRecord sr(companyID, companyName, oldPrice, shares);
- sr.setNewPrice(newPrice);
- c += sr;
- if(flag){
- cout << "Operator += OK" << endl;
- flag = false;
- }
- }
- cout << c;
- cout << "Operator << OK" << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement