You are on page 1of 19

402106779 BWALYA TERISSA POPOPO

FACULTY OF INFORMATION TECHNOLOGY


PROGRAMMING 622

Name & Surname: BWALYA TERISSA POPOPO ICAS/ITS No: 402106779

Qualification: BSCIT Semester: 2nd Module Name: PROG 622

Date Submitted: 30 Sept 2022

ASSESSMENT CRITERIA MARK EXAMINER MODERATOR


ALLOCATION MARKS MARKS
MARKS FOR CONTENT

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:

Signature of Examiner: Signature of Moderator:

1|P ag e
402106779 BWALYA TERISSA POPOPO

TABLE OF CONTENTS

QUESTION ONE...............................................................3
Code................................................................................3
Output ............................................................................8

QUESTION TWO ............................................................10


Code..............................................................................10
Output ..........................................................................13

QUESTION THREE .........................................................14


Code..............................................................................14
Output ..........................................................................18
REFERENCES .................................................................19

2|P ag e
402106779 BWALYA TERISSA POPOPO

QUESTION ONE

Code
#include<string>
#include<iostream>

#include<ostream>

using namespace std;

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;

friend ostream& operator<<(ostream& os , const List & list);


const string front(){return head->customerName;}
const string back(){return tail->customerName;}

3|P ag e
402106779 BWALYA TERISSA POPOPO

};
bool List::isEmpty() const{

return head == NULL ? true:false;


}
void List::push(string customerNme){
Bwalya * newCust = new Bwalya;
newCust->customerName = customerNme;

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{

auto tmp = head;


head = head->next;
delete tmp;
return true;
}
}

4|P ag e
402106779 BWALYA TERISSA POPOPO

const int List::size() const{


if(isEmpty()){
return 0;

}
int count{};
for(Bwalya * it = head ; it != NULL ; it = it -> next){
count++;
}

return count;
}

ostream& operator<<(ostream& os , const List & list){


for(Bwalya * it = list.head;it != NULL ; it = it->next){

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(){

cout<<"\n\n\n############### Welcome to Virtual line system


################\n\n";

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;

if (userChoice >= 3){


cout<<"Thank you!!!\n";
break;
}
if(userChoice == 1){

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>

using namespace std;

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

void Stack::push(string item){


items.push_front(item);
cout<<"<"<<item<<">added to stack\n";
}

string Stack::pop(){
auto top{items.front()};
items.pop_front();
return top;
}

const string& Stack::peek() const{


return items.front();
}

bool Stack::isEmpty() const{


return items.empty();
}

int Stack::size() const{


return (int)items.size();

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;

cout<<"PLACE YOUR PLATES IN THE CARBINET\n"


<<"ENTER 'done' WHEN FINISHED\n";
while (true){
getline(cin,plate);
//check if user is not finished
if(plate == "done"){
cout<<"-----------------------------------------------------------------------------------
------------------------\n"
<<"\nYOU FILLED THE CABINET WITH DESIRED NUMBER OF PLATES\n"
<<"----------------------------------------------------------------------------------------
-------------------\n";
break;
}
//add plate to stack
cabinet.push(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();
}

cout<<"CABINET IS NOW EMPTY\n";


}

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>

using namespace std;

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();

};

Queue::Queue(int lim){limit = lim;}

14 | P a g e
402106779 BWALYA TERISSA POPOPO

bool Queue::isFull(){
if(size() == limit){
return true;

}
else{
return false;
}
}

bool Queue::enqueue(string item){


if(isFull()){
cout<<"Queue is currently full \n"
<<"Come back Later !!!!!\n";

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

cout<<"<"<<items.front()<<"> item removed from the Queue\n";


items.pop();
return true;

}
}

bool Queue::isEmpty(){

return items.empty();
}

int Queue::size() const{

return (int)items.size();
}

const string& Queue::front(){

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

cout<<"RECORD THE CARS \n";


cout<<"----------------------------------------------------------------------\n";

for(int i{1} ; i <= size ; i++){


cout<<"ENTER CAR ("<<i<<") `s DETAILS/NAME :";
getline(cin,tmp_car);
if(tmp_car == ""){
i--;

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

You might also like