Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //call.h
- #pragma once
- #include <string>
- using namespace std;
- typedef struct Call
- {
- int number;
- bool type; // T outgoing F incoming
- string name;
- }Call;
- //callphone.h
- #pragma once
- #include "Stack.h"
- #include "LinePhone.h"
- class CellPhone : public LinePhone
- {
- public:
- CellPhone(int x = 0);
- ~CellPhone();
- void acceptCall_b(int,string);
- void dialNumber_b(int,string);
- void showIncomming_b();
- void showOutgoing_b();
- void save_contact(int, string);
- void delete_contact(int, string);
- void save_pic(int);
- void delete_pic(int);
- private:
- Stack s2; // will be using for saving contacts
- };
- // callphoneNocam.h
- #pragma once
- class CellPhoneNoCam
- {
- };
- // linephone.h
- #pragma once
- #include "Stack.h"
- class LinePhone
- {
- public:
- LinePhone(int x=0);
- ~LinePhone();
- void acceptCall(int);
- void dialNumber(int);
- void showIncomming();
- void showOutgoing();
- protected:
- Stack s1;
- };
- //stack.h
- #pragma once
- #define MAX 10
- #include "Call.h"
- class Stack
- {
- friend void print();
- public:
- Stack() { top = -1; } // cons
- ~Stack();
- bool push(int x,bool type);
- bool push(int x, bool type, string name);
- int pop();
- int peek();
- int peek_index_incoming(int index);
- int peek_index_incoming(int index,string&);
- int peek_index_outgoing(int index);
- bool isEmpty();
- int Getop()const;
- private:
- struct Call a[MAX]; // Maximum size of Stack
- int top;
- };
- //cellphone.cpp
- #include "CellPhone.h"
- #include <iostream>
- using namespace std;
- CellPhone::CellPhone(int x)
- {
- }
- CellPhone::~CellPhone()
- {
- }
- void CellPhone::acceptCall_b(int incoming_call,string name)
- {
- s1.push(incoming_call, false, name);
- }
- void CellPhone::dialNumber_b(int outgoing_call,string name)
- {
- s1.push(outgoing_call, true, name);
- }
- void CellPhone::showIncomming_b()
- {
- for (int i = 0; i <= s1.Getop(); i++)
- {
- string name;
- int res = s1.peek_index_incoming(i, name);
- if (res != 0)
- {
- cout << res <<" "<< name << endl;
- }
- }
- }
- void CellPhone::showOutgoing_b()
- {
- }
- void CellPhone::save_contact(int number,string name)
- {
- }
- void CellPhone::delete_contact(int number,string name)
- {
- }
- void CellPhone::save_pic(int pic)
- {
- }
- void CellPhone::delete_pic(int pic)
- {
- }
- //cellphonenocam.cpp
- #include "CellPhoneNoCam.h"
- //linephone.cpp
- #include "LinePhone.h"
- #include "Stack.h"
- #include <iostream>
- using namespace std;
- LinePhone::LinePhone(int x)
- {
- }
- LinePhone::~LinePhone()
- {
- }
- void LinePhone::acceptCall(int number_in_coming)
- {
- s1.push(number_in_coming,false);
- }
- void LinePhone::dialNumber(int number_out_going)
- {
- s1.push(number_out_going, true);
- }
- void LinePhone::showIncomming()
- {
- for (int i = 0; i <=s1.Getop(); i++)
- {
- int res = s1.peek_index_incoming(i);
- if (res!= 0)
- {
- cout << res << endl;
- }
- }
- }
- void LinePhone::showOutgoing()
- {
- for (int i = 0; i <= s1.Getop(); i++)
- {
- int res_2 = s1.peek_index_outgoing(i);
- if (res_2 != 0)
- {
- cout << res_2 << endl;
- }
- }
- }
- //main.cpp
- #include <iostream>
- #include <iomanip>
- #include "Stack.h"
- #include "LinePhone.h"
- #include "CellPhone.h"
- #include "CellPhoneNoCam.h"
- using namespace std;
- void main()
- {
- LinePhone t1;
- t1.acceptCall(544481276);
- t1.dialNumber(544212121);
- t1.showIncomming();
- t1.showOutgoing();
- CellPhone s1;
- s1.acceptCall_b(5444, "boy");
- s1.dialNumber_b(541231, "girl");
- s1.showIncomming_b();
- }
- //stack.cpp
- #include "Stack.h"
- #include <iostream>
- using namespace std;
- Stack::~Stack()
- {
- }
- bool Stack::push(int x,bool type)
- {
- if (top >= (MAX - 1)) { // because starts with 0
- cout << "Stack Overflow" << endl;
- return false;
- }
- else {
- a[++top].number = x;
- a[top].type = type;
- cout << x << " pushed into stack" << endl;
- return true;
- }
- }
- bool Stack::push(int x, bool type, string name)
- {
- if (top >= (MAX - 1)) { //because starts with 0
- cout << "Stack Overflow" << endl;
- return false;
- }
- else {
- a[++top].number = x;
- a[top].type = type;
- a[top].name = name;
- cout << x << " pushed into stack" << endl;
- return true;
- }
- }
- int Stack::pop()
- {
- if (top < 0) {
- cout << "Stack Underflow" << endl; // starts with 0
- return 0;
- }
- else {
- int x = a[top--].number;
- return x;
- }
- }
- int Stack::peek()
- {
- if (top < 0) {
- cout << "Stack is Empty" << endl;
- return 0;
- }
- else {
- int x = a[top].number;
- return x;
- }
- }
- bool Stack::isEmpty()
- {
- return (top < 0);
- }
- int Stack::Getop()const
- {
- return this->top;
- }
- int Stack::peek_index_incoming(int index)
- {
- if (index < 0)
- {
- cout << "Stack Underflow" << endl;
- return 0;
- }
- else
- {
- if (a[index].type==false)
- {
- return a[index].number;
- }
- return 0;
- }
- }
- int Stack::peek_index_incoming(int index, string &name)
- {
- if (index < 0)
- {
- cout << "Stack Underflow" << endl;
- return 0;
- }
- else
- {
- if (a[index].type == false)
- {
- name = a[index].name;
- return a[index].number;
- }
- return 0;
- }
- }
- int Stack::peek_index_outgoing(int index)
- {
- if (index < 0)
- {
- cout << "Stack Underflow" << endl;
- return 0;
- }
- else
- {
- if (a[index].type == true)
- {
- return a[index].number;
- }
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement