nie-ii-year

lab stuff from undergrad second year.
git clone http://git.hanabi.in/repos/nie-ii-year.git
Log | Files | Refs | LICENSE

commit b3d9cc1e76058f6ab5b5ca512c883611f4766fd1
parent 46c548c3163a985f59af84cf0ba3c96abd1112fd
Author: Agastya Chandrakant <acagastya@outlook.com>
Date:   Fri,  3 Nov 2017 09:36:15 +0530

create
Diffstat:
As3/oops/tq.cpp | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+), 0 deletions(-)

diff --git a/s3/oops/tq.cpp b/s3/oops/tq.cpp @@ -0,0 +1,74 @@ +#include <iostream> +#define MAX 5 + +int read = -1; +int write = -1; + +template <class T> +class queue{ + T data[MAX]; +public: + void inQueue(){ + T incoming; + if(write == MAX - 1){ + std::cout << "Queue overflow\n"; + return; + } + if(read == -1) + ++read; + std::cout << "Enter element to be entered: "; + std::cin >> incoming; + write = (write + 1); + data[write] = incoming; + }; + void deQueue(){ + if(read == -1 || read > write) + std::cout << "Queue underflow.\n"; + else{ + std::cout << data[read] << " has been removed.\n"; + read++; + } + }; + void displayQueue(){ + if(write == -1 || read > write) + std::cout <<"Queue is empty.\n"; + else{ + for(int i = read; i <= write; i++) + std::cout << data[i] << " "; + std::cout << "\n"; + } + }; +}; + +int main() { + int choice; + queue <int> q; + do{ + std::cout << "Enter choice: "; + std::cin >> choice; + switch (choice) { + case 1: q.inQueue(); + q.displayQueue(); + break; + case 2: q.deQueue(); + q.displayQueue(); + break; + default: choice = 0; + } + }while(choice); + queue <float> Q; + do{ + std::cout << "Enter choice: "; + std::cin >> choice; + switch (choice) { + case 1: Q.inQueue(); + Q.displayQueue(); + break; + case 2: Q.deQueue(); + Q.displayQueue(); + break; + default: choice = 0; + } + }while(choice); + return 0; +}