Startpunkten

This commit is contained in:
2026-03-05 13:44:23 +01:00
commit adf9f82c8b
26 changed files with 3313 additions and 0 deletions

6
The_Store/boolean.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef __BOOLEAN_H_
#define __BOOLEAN_H_
typedef int boolean;

202
The_Store/huvud.cpp Normal file
View File

@@ -0,0 +1,202 @@
//#####################################################
// LAB 3 I PUMA
// CRILLE & ROBIN 980107
// AFFÄREN
//=====================================================
#include "lista.cpp"
#include "twindow.hpp"
const int BUFFERSIZE = 100; //för säkerinmatning
const int MAXSIZE = 5; //maximalt antal element
const int SIST = 0; //inmatning i listan
const int FORST=!SIST; //inmatning i listan
const int FALSE=0; //boolsk varabel
const int TRUE=!FALSE; //boolsk varabel
const int antalKassor = 2;
const int BREDD = 7; //fönstrets bredd
const int HOJD = 2; //fönstrets höjd
//#####################################################
// SÄKER INMATNING
// SER TILL ATT BARA HELTAL MATAS IN
//=====================================================
int mataIn()
{
char buffer[BUFFERSIZE];
int f;
do
{
cin >> buffer;
if (strcmp(buffer,"0") == 0)
return 0;
else
{
f = atoi(buffer);
if (f!=0)
return f;
else
cout <<" Inget tal, forsok igen: ";
}
}while (!f);
}
//#####################################################
// SÄTTER IN ELEMENT I LISTAN
//=====================================================
void _listInsert(listClass <TWindow> &minLista)
{
if(minLista.listLength() < MAXSIZE)
{
TWindow *newItem;
newItem = new TWindow(Lleft, Ltop,(BREDD+Lleft),(HOJD+Ltop),BLUE,WHITE);
cout << " Vem kommer in i affaren?";
cout << *newItem;
newItem->editText();
if(minLista.newDuplicate(*newItem))
{
cout <<"\n Personen ar redan har.";
getch();
}
else
minLista.listInsert(minLista.listLength()+1, *newItem);
}
else
{
cout <<" Affaren ar full !!!";
getch();
}
}
//#####################################################
// VISAR ALLA ELEMENT I LISTAN
//=====================================================
void _listDisplay(listClass <TWindow> minLista)
{
TWindow *a;
a = new TWindow(1, 20,(BREDD+1),(HOJD+20),GREEN,WHITE);
if(!minLista.listIsEmpty())
for(int i=0 ; i<minLista.listLength() ; i++)
{
*a=minLista.retrive(i);
a->move(LmoveX,LmoveY);
cout << *a;
}
}
//#####################################################
// VISAR ALLA ELEMENT I KASSORNA
//=====================================================
void _queueDisplay(queueClass <TWindow> minQueue[])
{
TWindow *b,*c;
b = new TWindow(Qleft[0],Qtop,(BREDD+Qleft[0]),(HOJD+Qtop),RED,WHITE);
c = new TWindow(Qleft[1],Qtop,(BREDD+Qleft[1]),(HOJD+Qtop),RED,WHITE);
if(!minQueue[0].isEmpty())
{
for(int i=0 ; i<minQueue[0].length() ; i++)
{
*b=minQueue[0].retrive(i);
cout << *b;
b->move(QmoveX,QmoveY);
}
}
if(!minQueue[1].isEmpty())
{
for(int i=0 ; i<minQueue[1].length() ; i++)
{
*c=minQueue[1].retrive(i);
cout << *c;
c->move(QmoveX,QmoveY);
}
}
}
//#####################################################
// FLYTTAR EN PERSON TILL EN KASSA
//=====================================================
void _toQueue(queueClass<TWindow> minQueue[],listClass<TWindow> &minLista)
{
int kassa,position;
TWindow *flyttGubbe;
flyttGubbe = new TWindow(Lleft, Ltop,(BREDD+Lleft),(HOJD+Ltop),BLUE,WHITE);
cout <<" Vem vill du flytta till kon?";
cout << *flyttGubbe;
flyttGubbe->editText();
if(minLista.newDuplicate(*flyttGubbe))
{
cout <<"\n Till vilken kassa [1/2] ?";
cin >> kassa;
position=minLista.getPos(*flyttGubbe);
minQueue[kassa-1].ins(minLista.retrive(position));
minLista.listDel(position+1);
}
else
{
cout <<"\n Personen fanns inte i affaren!";
getch();
}
}
//#####################################################
// BETJÄNAR EN PERSON UR EN KASSA (TAR BORT)
//=====================================================
void _getOut(queueClass <TWindow> minQueue[])
{
int kassa;
cout <<"\n Fran vilken kassa [1/2] ?";
kassa=mataIn();
if(kassa>antalKassor)
cout <<" Vi har inte sa manga kassor!";
else if(minQueue[kassa-1].length()==0)
cout <<" Det finns ingen att betjana.";
else
{
minQueue[kassa-1].del(FORST);
return;
}
getch();
}
//#####################################################
// MAIN-MENU-ITEMS
//=====================================================
void menuItems()
{
clrscr();
TWindow *separera;
separera = new TWindow(63,0,64,15,YELLOW,YELLOW);
cout << *separera;
separera->move(LmoveX,LmoveY);
cout <<" Bengans begagnade barnklader. \n"
<<" ----------------------------- \n\n"
<<" 1. Lagg till person i affaeren. \n"
<<" 2. Flytta person till en ko. \n"
<<" 3. Betjana person ur en ko.\n"
<<" 0. Avsluta programmet. \n\n";
gotoxy(52,1);
cout <<"Kassa 1";
gotoxy(72,wherey());
cout <<"Kassa 2";
gotoxy(2,20);
cout <<"Dessa personer ar inne i affaren...";
gotoxy(2,9);
}
//#####################################################
// MAINFUNCTION
//=====================================================
void main()
{
queueClass<TWindow> minQueue[antalKassor];
listClass<TWindow> minLista;
char val = TRUE;
do
{
menuItems();
_listDisplay(minLista);
_queueDisplay(minQueue);
cin >> val;
switch (val)
{
case '1' : _listInsert(minLista);break;
case '2' : _toQueue(minQueue,minLista);break;
case '3' : _getOut(minQueue);break;
case '0' : cout <<" Programmet avslutat";break;
default: cout <<" Fel val"<< endl;
}
}while (val != '0');

12
The_Store/keycode.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef __KEYCODE_H
#define __KEYCODE_H
const int LeftTop = 201;
const int RightTop = 187;
const int RightBottom = 188;
const int LeftBottom = 200;

179
The_Store/lista.cpp Normal file
View File

@@ -0,0 +1,179 @@
//#####################################################
// LISTA.CPP
//=====================================================
#include <stddef.h> //för NULL
#include <assert.h> //för assert()
#include <iostream.h> //för in-ut matning
#include <conio.h> //för getch();
#include <string.h> //för säker inmatning
#include <stdlib.h> //för atoi()
#include "queue.cpp"
const int Lleft = 1; //fönstrets X-position
const int Ltop = 13; //fönstrets Y-position
const int LmoveX = 9; //fönsterflyttning X-led
const int LmoveY = 0; //fönsterflyttning Y-led
template <class T>
class listClass
{
public:
listClass();
~listClass();
T retrive(int position);
int listIsEmpty();
int listLength();
int newDuplicate(T newItem);
int getPos(T newItem);
void listInsert(int position, T newItem);
void listDel(int position);
private:
struct listNode
{
T listContent;
listNode* next;
};
typedef struct listNode listNode;
typedef struct listNode* ptrType;
ptrType head;
int size;
};
//#####################################################
// CONSTRUCTOR
// SÄTTER LISTSTORLEKEN TILL NOLL & HEAD TILL NULL
// pre: TRUE
// post: en lista har skapats
//=====================================================
template <class T>
listClass<T>::listClass():size(0), head(NULL)
{
}
//#####################################################
// DESTRUCTOR
// FÖRSTÖR LISTAN, ANROPAS AUTOMATISKT VID AVSLUT
// pre: TRUE
// post: listan har raderats
//=====================================================
template <class T>
listClass<T>::~listClass()
{
}
//#####################################################
// KOLLAR OM LISTAN ÄR TOM
// pre: TRUE
// post: TRUE om listan är tom
// post: FALSE om listan inte är tom
//=====================================================
template <class T>
int listClass<T>::listIsEmpty()
{
return int (size == 0);
}
//#####################################################
// RETURNERAR ANTALET ELEMENT I LISTAN
// pre: TRUE
// post: antalet element i listan är returnerade
//=====================================================
template <class T>
int listClass<T>::listLength()
{
return size;
}
//#####################################################
// LÄGGER TILL ETT NYTT ELEMENT I LISTAN
// pre: att maximalt antal element inte finns
// pre: att listelementet inte finns
// post: listan har ett nytt element
//=====================================================
template <class T>
void listClass<T>::listInsert(int position, T newItem)
{
size++;
ptrType newPtr= new listNode;
newPtr->listContent=newItem;
if (position==1)
{
newPtr->next=head;
head=newPtr;
}
else
{
ptrType prev=head;
for (int i=1;i<position-1;i++)
prev=prev->next;
newPtr->next=prev->next;
prev->next=newPtr;
}
}
//#####################################################
// TAR BORT ELEMENT I LISTAN
// pre: att det finns en lista
// post: ett elementet har tagits bort
//=====================================================
template <class T>
void listClass<T>::listDel(int position)
{
ptrType prev,cur;
size--;
if(position == 1)
{
cur=head;
head=head->next;
}
else
{
prev=head;
for (int i=1;i<position-1;i++)
prev=prev->next;
cur=prev->next;
prev->next=cur->next;
}
delete cur;
cur=NULL;
}
//#####################################################
// KOLLAR OM ETT ELEMENT FINNS
// pre: att det finns en lista
// post: TRUE om elementet redan finns
// post: FALSE om elementet inte redan finns
//=====================================================
template <class T>
int listClass<T>::newDuplicate(T newItem)
{
ptrType cur;
for(cur=head ; cur!=NULL ; cur=cur->next)
if(cur->listContent == newItem)
return TRUE;
return FALSE;
}
//#####################################################
// HÄMTAR ÖVERSTA ELEMENTET
// pre: att det finns en lista
// post: det översta elementet har returnerats
//=====================================================
template <class T>
T listClass<T>::retrive(int position)
{
ptrType cur=head;
for(int i=0 ; i<position ; i++)
cur=cur->next;
return (cur->listContent);
}
//#####################################################
// HÄMTAR POSITIONEN ETT SÖKT ELEMENT FINNS PÅ
// pre: att det finns en lista
// post: om TRUE returneras positionen
// post: FALSE om elementet inte fanns
//=====================================================
template <class T>
int listClass<T>::getPos(T newItem)
{
ptrType cur=head;
for(int position=1 ; position<size ; position++)
{
cur=cur->next;
if(cur->listContent == newItem)
return position;
}
return FALSE;

110
The_Store/queue.cpp Normal file
View File

@@ -0,0 +1,110 @@
//#####################################################
// QUEUE.CPP
//=====================================================
const int Qleft[2] = {50,70};
const int Qtop = 1;
const int QmoveX = 0;
const int QmoveY = 4;
template <class T>
class queueClass
{
public:
queueClass();
~queueClass();
T retrive(int position);
int isEmpty();
int length();
int duplicate(T newItem);
void ins(T newItem);
void del(int position);
private:
listClass<TWindow>minLista;
typedef struct queueNode* ptrType;
ptrType head;
int size;
};
//#####################################################
// CONSTRUCTOR
// SÄTTER KÖSTORLEKEN TILL NOLL & HEAD TILL NULL
// pre: TRUE
// post: en kö har skapats
//=====================================================
template <class T>
queueClass<T>::queueClass():size(0), head(NULL)
{
}
//#####################################################
// DESTRUCTOR
// FÖRSTÖR KÖN, ANROPAS AUTOMATISKT VID AVSLUT
// pre: att det finns en kö
// post: kön har raderats
//=====================================================
template <class T>
queueClass<T>::~queueClass()
{
}
//#####################################################
// RETURNERAR ANTALET ELEMENT I KÖN
// pre: TRUE
// post: antalet element i kön är returnerade
//=====================================================
template <class T>
int queueClass<T>::length()
{
return (minLista.listLength());
}
//#####################################################
// KOLLAR OM ETT ELEMENT FINNS
// pre: att det finns en kö
// post: TRUE om elementet redan finns
// post: FALSE om elementet inte redan finns
//=====================================================
template <class T>
int queueClass<T>::duplicate(T newItem)
{
return (minLista.newDuplicate(newItem));
}
//#####################################################
// LÄGGER TILL ETT NYTT ELEMENT I KÖN
// pre: att maximalt antal element inte finns
// pre: att elementet inte finns
// post:ett nytt element
//=====================================================
template <class T>
void queueClass<T>::ins(T newItem)
{
size++;
minLista.listInsert(size, newItem);
}
//#####################################################
// TAR BORT ELEMENT I LISTAN
// pre: att det finns en kö
// post: översta elementet har tagits bort
//=====================================================
template <class T>
void queueClass<T>::del(int position)
{
size--;
minLista.listDel(position);
}
//#####################################################
// KOLLAR OM KÖN ÄR TOM
// pre: TRUE
// post: TRUE om kön är tom
// post: FALSE om kön inte är tom
//=====================================================
template <class T>
int queueClass<T>::isEmpty()
{
return (minLista.listIsEmpty());
}
//#####################################################
// HÄMTAR ELEMENTET
// pre: att det finns en lista
// post: det översta elementet har returnerats
//=====================================================
template <class T>
T queueClass<T>::retrive(int position)
{

203
The_Store/twindow.cpp Normal file
View File

@@ -0,0 +1,203 @@
#include <dos.h>
#include <conio.h>
#include <bios.h>
#include <string.h>
#include <ctype.h>
#include "twindow.hpp"
const int MAXX=80;
const int MAXY=25;
const int MINX=0;
const int MINY=0;
class Display
{
public:
typedef unsigned far* ScreenPtr;
static void drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg);
};
void Display::drawChar(unsigned x,unsigned y, char c, unsigned fg, unsigned bg)
{
ScreenPtr display = (ScreenPtr)MK_FP(0xB800,0x0);
display[y*80+x] = (((bg<<4)|fg)<<8)|(c & 255);
}
//=============================================================================
// default constructor: skapar fönstret med vissa koordinater och färger
//-----------------------------------------------------------------------------
TWindow::TWindow()
{
Left=1;Right=8;Bottom=24;Top=20;background=BLUE;foreground=WHITE;
text=NULL;
}
//=============================================================================
// constructor: skapar fönstret med vissa koordinater och färger
//-----------------------------------------------------------------------------
TWindow::TWindow(unsigned left,unsigned top,unsigned right ,unsigned bottom, DColor bg, DColor fg):
Left(left),Right(right),Bottom(bottom),Top(top),background(bg), foreground(fg)
{
theState = 0;//FALSE;
text=NULL;
}
//=============================================================================
// destructor: förstör fönstret
//-----------------------------------------------------------------------------
TWindow::~TWindow()
{
if(isVisible())
hide();
}
//=============================================================================
// hide: gömmer fönstret
//-----------------------------------------------------------------------------
void TWindow::hide()
{
erase();
}
//=============================================================================
// show: visar fönstret
//-----------------------------------------------------------------------------
void TWindow::display()
{
draw();
if(text)
showText();
}
//=============================================================================
// draw: ritar upp fönstret
//-----------------------------------------------------------------------------
void TWindow::draw()
{
theState = 1;//;TRUE;
for(int j= Top; j< Bottom; j++ )
for(int i=Left; i< Right ; i++ )
{
Display::drawChar(i,j,' ',foreground,background);
}
drawBorder();
}
//=============================================================================
// erase: ritar över fönstret med svart
//-----------------------------------------------------------------------------
void TWindow::erase()
{
for(int j= Top; j<= Bottom; j++ )
for(int i=Left; i<= Right ; i++ )
Display::drawChar(i,j,' ',BLACK,BLACK);
theState = 0;//FALSE;
}
//=============================================================================
// drewBorder: ritar ramen runt fönstret
//-----------------------------------------------------------------------------
void TWindow::drawBorder()
{
for(int i=Left+1; i< Right; i++)Display::drawChar(i ,Top , HLine , foreground, background);
for( i=Left+1; i< Right; i++)Display::drawChar(i ,Bottom , HLine , foreground, background);
for( i=Top+1; i< Bottom; i++)Display::drawChar(Left ,i , VLine , foreground, background);
for( i=Top+1; i< Bottom; i++)Display::drawChar(Right ,i , VLine , foreground, background);
Display::drawChar(Left ,Top , LeftTop , foreground, background);
Display::drawChar(Right ,Top ,RightTop , foreground, background);
Display::drawChar(Right ,Bottom ,RightBottom, foreground, background);
Display::drawChar(Left ,Bottom , LeftBottom, foreground, background);
}
void TWindow::move(unsigned relX, unsigned relY)
{
Left=Left+relX;
Right=Right+relX;
Top=Top+relY;
Bottom=Bottom+relY;
}
void TWindow::moveAbs(unsigned x, unsigned y)
{
unsigned width=Right-Left;
unsigned height=Bottom-Top;
Left=x;
Right=x+width;
Top=y;
Bottom=y+height;
}
void TWindow::setText(char* txt)
{
text=new char[strlen(txt)];
strcpy(text, txt);
}
void TWindow::showText()
{
int x=Left+1,y=Top+1;
for(int i=0;i<strlen(text);i++)
{
Display::drawChar(x, y, text[i], foreground, background);
if(++x>=Right)
{
x=Left+1;
y++;
}
}
}
void TWindow::editText()
{
int i=0;
delete text;
int size=(Right-Left-1)*(Bottom-Top-1);
text=new char[size];
text[0]='\0';
char* buffer=new char[size];
while(((buffer[i]=bioskey(0))!=ENTER)&&(i<size))
{
if(buffer[i]==BACK)
{
text[i-1]='\0';
if(--i<0)i=0;
draw();
showText();
}
else if(buffer[i]==ESC)
{
delete text;
text=NULL;
draw();
return;
}
else if(isalnum(buffer[i])||buffer[i]==' ')
{
text[i]=buffer[i];
text[i+1]='\0';
showText();
i++;
}
}
}
TWindow& TWindow::operator=(TWindow& t)
{
delete text;
text=new char[strlen(t.text)];
strcpy(text, t.text);
return *this;
}
boolean TWindow::operator==(TWindow& t)
{
return strcmp(t.text, text)==0;
}
boolean TWindow::operator<(TWindow& t)
{
return strcmp(text, t.text)<0;
}
boolean TWindow::operator>(TWindow& t)
{
return strcmp(text, t.text)>0;
}
ostream& operator<<(ostream& o, TWindow& t)
{
t.display();
return o;
}
istream& operator>>(istream&i, TWindow& t)
{
t.editText();
return i;
}

39
The_Store/twindow.hpp Normal file
View File

@@ -0,0 +1,39 @@
#ifndef __TWINDOW__H
#define __TWINDOW__H
#include "keycode.h"
#include "boolean.h"
#include <iostream.h>
typedef unsigned char DColor;
class TWindow
{
public:
TWindow();
TWindow(unsigned left,unsigned top,unsigned right ,unsigned bottom, DColor bg, DColor fg);
~TWindow();
boolean isVisible() {return theState;}
void hide();
void display();
void move(unsigned nX, unsigned nY);
void TWindow::moveAbs(unsigned x, unsigned y);
void setText(char* txt);
void editText();
char* getText(){return text;};
void setColor(unsigned char col){background=col;};
TWindow& operator=(TWindow& t);
boolean operator==(TWindow& t);
boolean operator<(TWindow& t);
boolean operator>(TWindow& t);
private:
char* text;
DColor background, foreground;
boolean theState;
unsigned Left,Top, Right,Bottom;
void draw();
void erase();
void drawBorder();
void showText();
};
ostream& operator<<(ostream& o, TWindow& t);
istream& operator>>(istream&i, TWindow& t);
#endif