Advertisement
edensheiko

c++ phone class ver - 0.5

Mar 14th, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.21 KB | None | 0 0
  1. //call.h
  2. #pragma once
  3. #include <string>
  4. using namespace std;
  5. typedef struct Call
  6. {
  7.     int number;
  8.     bool type; // T outgoing F incoming
  9.     string name;
  10. }Call;
  11. //callphone.h
  12. #pragma once
  13. #include "Stack.h"
  14. #include "LinePhone.h"
  15. class CellPhone : public LinePhone
  16. {
  17. public:
  18.     CellPhone(int x = 0);
  19.     ~CellPhone();
  20.     void acceptCall_b(int,string);
  21.     void dialNumber_b(int,string);
  22.     void showIncomming_b();
  23.     void showOutgoing_b();
  24.     void save_contact(int, string);
  25.     void delete_contact(int, string);
  26.     void save_pic(int);
  27.     void delete_pic(int);
  28.    
  29. private:
  30.     Stack s2; // will be using for saving contacts
  31. };
  32. // callphoneNocam.h
  33. #pragma once
  34. class CellPhoneNoCam
  35. {
  36. };
  37. // linephone.h
  38. #pragma once
  39. #include "Stack.h"
  40. class LinePhone
  41. {
  42. public:
  43.     LinePhone(int x=0);
  44.     ~LinePhone();
  45.     void acceptCall(int);
  46.     void dialNumber(int);
  47.     void showIncomming();
  48.     void showOutgoing();
  49.  
  50. protected:
  51.     Stack s1;
  52. };
  53. //stack.h
  54. #pragma once
  55. #define MAX 10
  56. #include "Call.h"
  57. class Stack
  58. {
  59.     friend void print();
  60. public:
  61.     Stack() { top = -1; } // cons
  62.     ~Stack();
  63.     bool push(int x,bool type);
  64.     bool push(int x, bool type, string name);
  65.     int pop();
  66.     int peek();
  67.     int peek_index_incoming(int index);
  68.     int peek_index_incoming(int index,string&);
  69.     int peek_index_outgoing(int index);
  70.     bool isEmpty();
  71.     int Getop()const;
  72. private:
  73.     struct Call a[MAX]; // Maximum size of Stack
  74.     int top;
  75. };
  76. //cellphone.cpp
  77. #include "CellPhone.h"
  78. #include <iostream>
  79. using namespace std;
  80.  
  81. CellPhone::CellPhone(int x)
  82. {
  83.  
  84. }
  85.  
  86. CellPhone::~CellPhone()
  87. {
  88.  
  89. }
  90. void CellPhone::acceptCall_b(int incoming_call,string name)
  91. {
  92.     s1.push(incoming_call, false, name);
  93. }
  94.  
  95. void CellPhone::dialNumber_b(int outgoing_call,string name)
  96. {
  97.     s1.push(outgoing_call, true, name);
  98. }
  99.  
  100. void CellPhone::showIncomming_b()
  101. {
  102.     for (int i = 0; i <= s1.Getop(); i++)
  103.     {
  104.         string  name;
  105.         int res = s1.peek_index_incoming(i, name);
  106.         if (res != 0)
  107.         {
  108.             cout << res <<" "<< name << endl;
  109.            
  110.         }
  111.  
  112.     }
  113.  
  114. }
  115.  
  116. void CellPhone::showOutgoing_b()
  117. {
  118.  
  119. }
  120.  
  121. void CellPhone::save_contact(int number,string name)
  122. {
  123.  
  124. }
  125.  
  126. void CellPhone::delete_contact(int number,string name)
  127. {
  128.  
  129. }
  130.  
  131. void CellPhone::save_pic(int pic)
  132. {
  133.  
  134. }
  135.  
  136. void CellPhone::delete_pic(int pic)
  137. {
  138.  
  139. }
  140. //cellphonenocam.cpp
  141. #include "CellPhoneNoCam.h"
  142.  
  143. //linephone.cpp
  144. #include "LinePhone.h"
  145. #include "Stack.h"
  146. #include <iostream>
  147.  
  148. using namespace std;
  149.  
  150. LinePhone::LinePhone(int x)
  151. {
  152.  
  153. }
  154.  
  155. LinePhone::~LinePhone()
  156. {
  157.  
  158. }
  159.  
  160. void LinePhone::acceptCall(int number_in_coming)
  161. {
  162.     s1.push(number_in_coming,false);
  163. }
  164.  
  165. void LinePhone::dialNumber(int number_out_going)
  166. {
  167.     s1.push(number_out_going, true);
  168. }
  169.  
  170. void LinePhone::showIncomming()
  171. {
  172.     for (int i = 0; i <=s1.Getop(); i++)
  173.     {
  174.         int res = s1.peek_index_incoming(i);
  175.         if (res!= 0)
  176.         {
  177.             cout << res << endl;
  178.         }
  179.        
  180.     }
  181. }
  182.  
  183. void LinePhone::showOutgoing()
  184. {
  185.     for (int i = 0; i <= s1.Getop(); i++)
  186.     {
  187.         int res_2 = s1.peek_index_outgoing(i);
  188.         if (res_2 != 0)
  189.         {
  190.             cout << res_2 << endl;
  191.         }
  192.     }
  193. }
  194.  
  195. //main.cpp
  196. #include <iostream>
  197. #include <iomanip>
  198. #include "Stack.h"
  199. #include "LinePhone.h"
  200. #include "CellPhone.h"
  201. #include "CellPhoneNoCam.h"
  202.  
  203. using namespace std;
  204.  
  205. void main()
  206. {
  207.     LinePhone t1;
  208.     t1.acceptCall(544481276);
  209.     t1.dialNumber(544212121);
  210.     t1.showIncomming();
  211.     t1.showOutgoing();
  212.     CellPhone s1;
  213.     s1.acceptCall_b(5444, "boy");
  214.     s1.dialNumber_b(541231, "girl");
  215.     s1.showIncomming_b();
  216.  
  217. }
  218. //stack.cpp
  219. #include "Stack.h"
  220. #include <iostream>
  221.  
  222.  
  223. using namespace std;
  224.  
  225.  
  226. Stack::~Stack()
  227. {
  228.  
  229. }
  230.  
  231. bool Stack::push(int x,bool type)
  232. {
  233.     if (top >= (MAX - 1)) { // because starts with 0
  234.         cout << "Stack Overflow" << endl;
  235.         return false;
  236.     }
  237.     else {
  238.         a[++top].number = x;
  239.         a[top].type = type;
  240.         cout << x << " pushed into stack" << endl;
  241.         return true;
  242.     }
  243. }
  244.  
  245. bool Stack::push(int x, bool type, string name)
  246. {
  247.     if (top >= (MAX - 1)) { //because starts with 0
  248.         cout << "Stack Overflow" << endl;
  249.         return false;
  250.     }
  251.     else {
  252.         a[++top].number = x;
  253.         a[top].type = type;
  254.         a[top].name = name;
  255.         cout << x << " pushed into stack" << endl;
  256.         return true;
  257.     }
  258. }
  259.  
  260.  
  261. int Stack::pop()
  262. {
  263.     if (top < 0) {
  264.         cout << "Stack Underflow" << endl; // starts with 0
  265.         return 0;
  266.     }
  267.     else {
  268.         int x = a[top--].number;
  269.         return x;
  270.     }
  271. }
  272.  
  273. int Stack::peek()
  274. {
  275.     if (top < 0) {
  276.         cout << "Stack is Empty" << endl;
  277.         return 0;
  278.     }
  279.     else {
  280.         int x = a[top].number;
  281.         return x;
  282.     }
  283. }
  284.  
  285. bool Stack::isEmpty()
  286. {
  287.     return (top < 0);
  288. }
  289.  
  290. int Stack::Getop()const
  291. {
  292.     return this->top;
  293. }
  294.  
  295. int Stack::peek_index_incoming(int index)
  296. {
  297.     if (index < 0)
  298.     {
  299.         cout << "Stack Underflow" << endl;
  300.         return 0;
  301.     }
  302.     else
  303.     {
  304.         if (a[index].type==false)
  305.         {
  306.             return a[index].number;
  307.         }
  308.    
  309.         return 0;
  310.     }
  311.    
  312. }
  313.  
  314. int Stack::peek_index_incoming(int index, string &name)
  315. {
  316.     if (index < 0)
  317.     {
  318.         cout << "Stack Underflow" << endl;
  319.         return 0;
  320.     }
  321.     else
  322.     {
  323.         if (a[index].type == false)
  324.         {
  325.             name = a[index].name;
  326.             return a[index].number;
  327.         }
  328.         return 0;
  329.     }
  330. }
  331.  
  332. int Stack::peek_index_outgoing(int index)
  333. {
  334.     if (index < 0)
  335.     {
  336.         cout << "Stack Underflow" << endl;
  337.         return 0;
  338.     }
  339.     else
  340.     {
  341.         if (a[index].type == true)
  342.         {
  343.             return a[index].number;
  344.         }
  345.         return 0;
  346.     }
  347. }
  348.  
  349.  
  350.  
  351.  
  352.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement