Professional Documents
Culture Documents
Programmig 622 Assignment
Programmig 622 Assignment
QUESTION ONE 50
QUESTION TWO 20
QUESTION THREE 20
TOTAL 90
MARKS FOR TECHNICAL ASPECTS
TABLE OF CONTENTS 2
Accurate numbering according to the numbering in
text and page numbers.
LAYOUT AND SPELLING 3
Font – Calibri 12
Line Spacing – 1.0
Margin should be justified.
REFERENCES 5
According to the Harvard Method
TOTAL 10
TOTAL MARKS FOR ASSIGNMENT 100
Examiner’s Comments:
Moderator’s Comments:
1|P ag e
402106779 BWALYA TERISSA POPOPO
TABLE OF CONTENTS
QUESTION ONE...............................................................3
Code................................................................................3
Output ............................................................................8
2|P ag e
402106779 BWALYA TERISSA POPOPO
QUESTION ONE
Code
#include<string>
#include<iostream>
#include<ostream>
class Bwalya{
public:
string customerName;
Bwalya * next;
};
class List{
private:
Bwalya * head, *tail;
public:
List():head(NULL),tail(NULL){}
void push(string customerNme);
bool pop_front();
bool isEmpty() const;
const int size()const;
3|P ag e
402106779 BWALYA TERISSA POPOPO
};
bool List::isEmpty() const{
newCust->next = NULL;
if (isEmpty()){
head = newCust;
tail = newCust;
}
else{
tail->next = newCust;
tail = tail->next;
}
}
bool List::pop_front(){
if(isEmpty()){
return false;
}
else{
4|P ag e
402106779 BWALYA TERISSA POPOPO
}
int count{};
for(Bwalya * it = head ; it != NULL ; it = it -> next){
count++;
}
return count;
}
os<<it->customerName<<endl;
}
return os;
}
class VIRTUALSYSTEM{
private:
List customers;
public:
void addCust();
void callCust();
void Program();
};
void VIRTUALSYSTEM::addCust(){
5|P ag e
402106779 BWALYA TERISSA POPOPO
string cust;
cout<<"CUSTOMER NAME :";
cin>>cust;
customers.push(cust);
cout<<"Customer added to line \n";
void VIRTUALSYSTEM::callCust(){
if(customers.isEmpty()){
cout<<"\nLIne EMpty\n";
}
else{
customers.pop_front();
if(customers.isEmpty()){
cout<<"lINE Empty \n";
}
}
}
void VIRTUALSYSTEM::Program(){
int userChoice;
while(true){
cout<<"\t\t1. Call a customer\n"
<<"\t\t2. Add a customer\n"
6|P ag e
402106779 BWALYA TERISSA POPOPO
<<"\t\t3.Quit\n"
<<"Your choice :";
cin>>userChoice;
callCust();
if(userChoice == 2){
addCust();
}
}
int main(){
VIRTUALSYSTEM system;
system.Program();
}
7|P ag e
402106779 BWALYA TERISSA POPOPO
OUTPUT
8|P ag e
402106779 BWALYA TERISSA POPOPO
9|P ag e
402106779 BWALYA TERISSA POPOPO
QUESTION TWO
CODE
#include<iostream>
#include<iterator>
#include<list>
#include<string>
class Stack{
private:
//contains items in the stack
list<string> items;
public:
//adds an item on top of the stack
void push(string item);
//removes an item from the top of the stack returns the popped item
string pop();
//returns a reference to the top item from the stack
const string& peek() const;
//returns bool checks if stack is empty
bool isEmpty() const;
//returns the total elements in the stack
int size() const;
};
//defination of Stack methods
10 | P a g e
402106779 BWALYA TERISSA POPOPO
string Stack::pop(){
auto top{items.front()};
items.pop_front();
return top;
}
11 | P a g e
402106779 BWALYA TERISSA POPOPO
}
//function to simulate the plates in the cabinet program
void Cabinet(){
//stores plates in a cabinet in a stack form
Stack cabinet;
string plate;
}
//Now wash the plates using LIFO
cout<<"\nNOW EMPTYING THE PLATES IN THE CABINET\n";
12 | P a g e
402106779 BWALYA TERISSA POPOPO
while(cabinet.size() != 0){
cout<<"CURRENT PLATE : "<<cabinet.peek()<<"\n";
cabinet.pop();
}
int main(){
Cabinet();
}
OUTPUT
13 | P a g e
402106779 BWALYA TERISSA POPOPO
QUESTION THREE
CODE
#include<queue>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<string>
class Queue{
private:
int limit;
queue<string> items;
public:
Queue(int lim = 5);
bool enqueue(string item);
bool dequeue();
bool isEmpty();
bool isFull();
int size() const;
const string& front();
};
14 | P a g e
402106779 BWALYA TERISSA POPOPO
bool Queue::isFull(){
if(size() == limit){
return true;
}
else{
return false;
}
}
return false;
}
else{
items.push(item);
cout<<"<"<<item<<"> has been added to the Queue\n";
return true;
}
}
bool Queue::dequeue(){
if(isEmpty()){
cout<<"Queue Currently empty!!!";
return false;
}
else{
15 | P a g e
402106779 BWALYA TERISSA POPOPO
}
}
bool Queue::isEmpty(){
return items.empty();
}
return (int)items.size();
}
return items.front();
}
void CarWash(){
int size ;
string tmp_car;
cout<<"ENTER THE MAXIMUM ALLOWED CARS IN THE CAR WASH : ";
cin>>size;
Queue cars(size);
16 | P a g e
402106779 BWALYA TERISSA POPOPO
continue;
}
else{
cars.enqueue(tmp_car);
}
}
cout<<"----------------------------------------------------------------------\n";
cout<<"NOW WASHING THE CARS IN ORDER OF ARRIVAL\n";
cout<<"----------------------------------------------------------------------\n";
while(!cars.isEmpty()){
cout<<"CURRENTLY WASHING CAR : <"<<cars.front() << ">\n";
cars.dequeue();
}
cout<<"----------------------------------------------------------------------\n";
int main(){
CarWash();
}
17 | P a g e
402106779 BWALYA TERISSA POPOPO
OUTPUT
18 | P a g e
402106779 BWALYA TERISSA POPOPO
REFERENCES
https://www.educba.com/c-plus-plus-linked-list/
https://www.w3schools.com/cpp/cpp_pointers.asp
https://abhiarrathore.medium.com/the-magic-of-c-stl-standard-template-library-
e910f43379ea
https://www.w3schools.com/
19 | P a g e